/* Layout: TLJ と おなじ いろ・もじ。ホームは コースの ならび、あそぶ ときは まんなかに 黒板を 1まい */
:root {
  --paper: #EEF4FA;
  --card: #FFFFFF;
  --ink: #1D2846;
  --ink-2: #56627F;
  --line: #D5DFEC;
  --sun: #FFC53D;
  --sun-2: #E9A400;
  --sun-soft: #FFF4D1;
  --tomato: #EC5B45;
  --tomato-soft: #FDE7E3;
  --leaf: #1F9E74;
  --leaf-2: #167A59;
  --leaf-soft: #DDF4EA;
  --sky: #2F76CC;
  --sky-soft: #E1EDFB;
  --grape: #7A5BD0;
  --grape-soft: #EEE8FB;
  --board: #1A2240;
  --board-2: #232D52;
  --board-ink: #E7ECF7;
  --board-dim: #7D88AE;
  --display: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Meiryo", sans-serif;
  --body: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Meiryo", sans-serif;
  --code: "Source Code Pro", Consolas, Menlo, "MS Gothic", monospace;
  color-scheme: light;
}
html, body { min-height: 100%; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  box-sizing: border-box;
  max-width: 1100px;
  margin: 0 auto;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }
code, kbd { font-family: var(--code); }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding-block: 10px; flex-wrap: wrap; }
.brand {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--display); font-weight: 800; font-size: 19px;
  background: none; border: 0; cursor: pointer; padding: 0; color: var(--ink);
}
.crumb { font-family: var(--display); font-weight: 500; color: var(--ink-2); font-size: 15px; min-width: 0; }
.spacer { flex: 1; }
.toggle {
  background: var(--card); border: 2px solid var(--line); border-radius: 999px;
  padding: 3px 14px; font-weight: 700; cursor: pointer; font-size: 14px;
}
.toggle[aria-pressed="false"] { color: var(--ink-2); }
main { flex: 1; display: flex; flex-direction: column; padding-block: 0 24px; }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--display); font-weight: 800; font-size: 16px; line-height: 1.3;
  border: 2px solid var(--line); border-radius: 14px; padding: 10px 20px; cursor: pointer;
  color: var(--ink); background: var(--card); box-shadow: 0 3px 0 var(--line);
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.btn.primary { background: var(--sun); border-color: var(--sun-2); box-shadow: 0 4px 0 var(--sun-2); }

kbd {
  display: inline-block; min-width: 1.4em; text-align: center;
  background: var(--card); color: var(--ink); border: 2px solid var(--line); border-bottom-width: 4px;
  border-radius: 8px; padding: 0 8px; font-size: .9em; font-weight: 700; line-height: 1.5;
}

/* ---------- home ---------- */
.hero { display: flex; align-items: center; gap: 18px; margin: 6px 0 18px; }
.hero h1 { font-family: var(--display); font-weight: 800; font-size: 28px; margin: 0; line-height: 1.3; }
.hero p { margin: 4px 0 0; color: var(--ink-2); }
.bob { animation: bob 2.4s ease-in-out infinite; flex: none; }
@keyframes bob { 50% { transform: translateY(-6px); } }

.genre { margin-bottom: 20px; }
.genre h2 { display: flex; align-items: baseline; gap: 12px; margin: 0 0 10px; flex-wrap: wrap; }
.g-name {
  font-family: var(--display); font-weight: 800; font-size: 20px;
  padding: 2px 14px; border-radius: 10px; color: #fff;
}
.g-name.html { background: var(--tomato); }
.g-name.css { background: var(--sky); }
.g-name.mix { background: var(--grape); }
.g-note { font-size: 15px; color: var(--ink-2); font-weight: 700; }

.courses { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; max-width: 760px; }
.course {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  background: var(--card); border: 2px solid var(--line); border-radius: 16px; padding: 12px 14px 12px;
  cursor: pointer; box-shadow: 0 3px 0 var(--line); transition: transform .08s, box-shadow .08s, border-color .12s;
  min-width: 0;
}
.course:hover { border-color: var(--sun-2); }
.course:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.c-level {
  font-family: var(--display); font-weight: 800; font-size: 13px;
  padding: 0 10px; border-radius: 999px; background: var(--leaf-soft); color: var(--leaf-2);
}
.course.chu .c-level { background: var(--sun-soft); color: #8A6100; }
.c-br { font-family: var(--display); font-weight: 800; font-size: 18px; margin-top: 4px; }
.c-sample {
  display: block; width: 100%; box-sizing: border-box; margin: 6px 0;
  background: var(--board); color: var(--board-ink); border-radius: 10px; padding: 6px 10px;
  font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.c-meta { font-size: 13px; color: var(--ink-2); font-weight: 700; }
.c-best { font-size: 13px; color: var(--ink-2); }
.c-best b { color: var(--tomato); font-size: 15px; }
.foot { color: var(--ink-2); font-size: 14px; margin: 4px 0 0; }

/* ---------- play ---------- */
.stage { width: 100%; max-width: 860px; margin: 8px auto 0; display: flex; flex-direction: column; gap: 12px; }
.stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stats span {
  background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 4px 14px;
  font-weight: 700; display: flex; align-items: baseline; gap: 6px;
}
.stats small { color: var(--ink-2); font-size: 13px; }
.stats b { font-family: var(--display); font-size: 22px; font-variant-numeric: tabular-nums; }
.bar { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--leaf); border-radius: 999px; transition: width .2s; }

.board {
  background: var(--board); color: var(--board-ink); border-radius: 22px;
  padding: 26px 24px 18px; min-height: 240px; box-sizing: border-box;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  box-shadow: 0 6px 0 #0E1430;
}
.board.pop { animation: pop .22s ease-out; }
@keyframes pop { 0% { transform: scale(.97); } 60% { transform: scale(1.01); } 100% { transform: none; } }
.board.shake { animation: shake .24s; }
@keyframes shake { 20% { transform: translateX(-7px); } 45% { transform: translateX(6px); } 70% { transform: translateX(-4px); } 100% { transform: none; } }

.yomi { font-family: var(--display); font-weight: 800; font-size: 17px; color: var(--sun); margin: 0; }
.read { font-family: var(--display); font-weight: 800; font-size: 26px; color: var(--board-ink); margin: 0 0 6px; line-height: 1.4; }
.n-read { font-size: 14px; }
.code {
  font-family: var(--code); font-weight: 700; margin: 0; line-height: 1.35;
  word-break: break-all; max-width: 100%;
}
.code.s { font-size: 64px; }
.code.m { font-size: 48px; }
.code.l { font-size: 36px; }
.code.xl { font-size: 28px; }
.ch.done { color: var(--leaf); color: #5FD3A4; }
.ch.todo { color: var(--board-ink); }
.ch.cur { color: var(--ink); background: var(--sun); border-radius: 6px; box-shadow: 0 0 0 2px var(--sun); }
.hint { font-weight: 700; color: #FFB4A6; margin: 14px 0 0; min-height: 1.7em; font-size: 17px; }
.next { margin: 0; text-align: center; color: var(--ink-2); font-weight: 700; }
.next .esc { margin-left: 18px; font-size: 14px; font-weight: 500; }
.next code { background: var(--card); border: 2px solid var(--line); border-radius: 8px; padding: 1px 10px; color: var(--ink); }
.warn {
  margin: 0; background: var(--tomato-soft); color: #A8321F; border: 2px solid var(--tomato);
  border-radius: 12px; padding: 8px 14px; font-weight: 700; text-align: center;
}
.keys { margin: 0; text-align: center; color: var(--ink-2); font-size: 14px; }

.ready .r-title { font-family: var(--display); font-weight: 800; font-size: 26px; margin: 0; }
.ready .r-sub { margin: 4px 0 14px; color: var(--board-dim); }
.ready .r-sub code { color: var(--board-ink); }
.ready .r-go { font-family: var(--display); font-weight: 800; font-size: 22px; margin: 0 0 14px; }
.count { font-family: var(--display); font-weight: 800; font-size: 120px; line-height: 1; margin: 0; color: var(--sun); animation: pop .3s; }

/* ---------- ゆび ガイド ---------- */
.stage.compact { gap: 10px; }
.stage.compact .board { min-height: 170px; padding-block: 18px 10px; }
.guide { display: flex; flex-direction: column; align-items: center; gap: 4px; }
/* ひかる いろは ゆびごと（キーと ゆびで おなじ いろ） */
.f-lp, .f-rp { --strong: #F07A86; }
.f-lr, .f-rr { --strong: #F2B630; }
.f-lm, .f-rm { --strong: #3DBE84; }
.f-li, .f-ri { --strong: #3B9BE0; }
.f-th { --strong: #8E6FDB; }

.kb { container-type: inline-size; width: 100%; max-width: 640px; }
.kb-row { display: flex; }
.key, .gap { --u: calc(100cqw / 15); flex: none; width: calc(var(--w) * var(--u) - 4px); height: calc(var(--u) * .86); margin: 2px; }
.key {
  position: relative; box-sizing: border-box;
  background: var(--card); border: 1.5px solid #C3CEDD; border-bottom-width: 3px;
  border-radius: calc(var(--u) * .16);
  font-family: var(--code); font-weight: 700; font-size: calc(var(--u) * .36); line-height: 1; color: var(--ink-2);
}
.key .k-m { position: absolute; left: 0; right: 0; bottom: 18%; text-align: center; }
.key .k-t { position: absolute; left: 0; right: 0; top: 10%; text-align: center; font-size: .85em; }
.key .k-t { top: 6%; font-size: .78em; }
.key .k-t + .k-m { bottom: 6%; font-size: .78em; }
.key.label .k-m { bottom: auto; top: 50%; transform: translateY(-50%); font-family: var(--body); font-size: .68em; }
.key.on {
  background: var(--strong); border-color: var(--ink); color: #fff; z-index: 1;
  box-shadow: 0 0 0 3px var(--ink); transform: translateY(-1px);
  animation: blink 1s ease-in-out infinite;
}
@keyframes blink { 50% { box-shadow: 0 0 0 3px var(--ink), 0 0 0 7px rgba(255, 197, 61, .55); } }

.hands { display: flex; align-items: flex-end; justify-content: center; gap: 14px; width: 100%; max-width: 640px; }
.hand { width: 140px; height: auto; flex: none; overflow: visible; }
.h-line rect { fill: var(--ink); stroke: var(--ink); stroke-width: 5; }
.fg, .palm { fill: #FFE3C8; }
.fg.act { fill: var(--strong); stroke: var(--ink); stroke-width: 3; }
.halo { fill: none; stroke: var(--strong); stroke-width: 16; opacity: .45; animation: halo 1s ease-in-out infinite; }
@keyframes halo { 50% { opacity: .12; } }
.finger {
  flex: 1; margin: 0 0 18px; text-align: center; font-family: var(--display); font-weight: 800; font-size: 17px;
  color: var(--ink); line-height: 1.5; min-width: 0;
}
.finger b { background: var(--sun-soft); border-radius: 6px; padding: 0 4px; }

/* ---------- result ---------- */
.board.result { background: var(--card); color: var(--ink); border: 2px solid var(--line); box-shadow: 0 4px 0 var(--line); align-items: stretch; text-align: left; gap: 16px; }
.res-top { display: flex; align-items: center; gap: 18px; justify-content: center; }
.res-rank { margin: 0; font-weight: 700; color: var(--ink-2); }
.res-rank b { font-family: var(--display); font-size: 22px; color: var(--ink); }
.res-score { margin: 0; font-family: var(--display); font-weight: 800; font-size: 64px; line-height: 1.05; color: var(--tomato); font-variant-numeric: tabular-nums; }
.res-score small { font-size: 16px; color: var(--ink-2); margin-right: 8px; }
.res-best { margin: 4px 0 0; display: inline-block; background: var(--sun); border-radius: 999px; padding: 0 14px; font-family: var(--display); font-weight: 800; }
.res-prev { margin: 4px 0 0; color: var(--ink-2); font-weight: 700; }
.res-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 0; }
.res-grid div { background: var(--paper); border-radius: 12px; padding: 8px 12px; }
.res-grid dt { font-size: 13px; color: var(--ink-2); font-weight: 700; }
.res-grid dd { margin: 0; font-family: var(--display); font-weight: 800; font-size: 22px; font-variant-numeric: tabular-nums; }
.res-miss p { margin: 0 0 6px; font-weight: 700; color: var(--ink-2); font-size: 14px; }
.res-miss ul { display: flex; gap: 14px; flex-wrap: wrap; list-style: none; margin: 0; padding: 0; font-weight: 700; }
.res-miss .none { color: var(--leaf-2); }
.res-btns { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; }

/* ---------- せまい がめん ---------- */
@media (max-width: 600px) {
  .hero h1 { font-size: 22px; }
  .hero .bob svg { width: 60px; height: 60px; }
  .code.s { font-size: 46px; }
  .code.m { font-size: 34px; }
  .code.l { font-size: 24px; }
  .code.xl { font-size: 19px; }
  .board { padding: 20px 14px 14px; min-height: 200px; }
  .res-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .res-top { flex-direction: column; text-align: center; }
  .res-score { font-size: 52px; }
}
@media (max-width: 600px) {
  .hand { width: 84px; }
  .finger { font-size: 14px; margin-bottom: 8px; }
}
@media (max-width: 380px) {
  .courses { grid-template-columns: minmax(0, 1fr); }
}
