:root {
  --ink: #15242f;
  --muted: #5a6a73;
  --paper: #fffdf7;
  --panel: #ffffff;
  --line: #d9e3e8;
  --blue: #2f7fd2;
  --red: #e74f5b;
  --green: #2d9b68;
  --yellow: #f7c948;
  --violet: #7857c8;
  --shadow: 0 18px 42px rgba(21, 36, 47, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  background: linear-gradient(90deg, rgba(47, 127, 210, 0.08) 1px, transparent 1px), linear-gradient(0deg, rgba(45, 155, 104, 0.08) 1px, transparent 1px), #f4fbf8;
  background-size: 34px 34px;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

button:focus-visible {
  outline: 4px solid rgba(47, 127, 210, 0.35);
  outline-offset: 3px;
}

.app {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 20px 0 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  fill: var(--yellow);
  stroke: var(--ink);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3.4vw, 2.6rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.brand p {
  margin: 5px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(2, minmax(92px, 1fr));
  gap: 10px;
}

.scoreboard div {
  display: grid;
  gap: 2px;
  min-height: 62px;
  padding: 8px 14px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 5px 5px 0 rgba(21, 36, 47, 0.12);
}

.scoreboard span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.scoreboard strong {
  font-size: 1.8rem;
  line-height: 1;
}

.controls {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.mode-tabs,
.row-picker {
  display: flex;
  gap: 8px;
  min-width: 0;
}

.row-picker {
  overflow-x: auto;
  padding-bottom: 3px;
}

.mode-tab,
.row-button,
.tool-button,
.mini-button,
.sound-button {
  min-height: 44px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 4px 4px 0 rgba(21, 36, 47, 0.12);
  font-weight: 900;
}

.mode-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 88px;
  padding: 9px 12px;
}

.mode-tab.active,
.row-button.active {
  color: #ffffff;
  background: var(--blue);
}

.row-button {
  flex: 0 0 auto;
  width: 58px;
  padding: 8px 6px;
  font-size: 1.2rem;
}

.play-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 320px);
  gap: 16px;
  align-items: start;
}

.stage,
.kana-map {
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.stage {
  position: relative;
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: 18px;
  min-height: 575px;
  padding: 18px;
  overflow: hidden;
}

.mascot-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 118px;
}

.mascot {
  width: min(100%, 128px);
  height: auto;
  filter: drop-shadow(0 10px 0 rgba(21, 36, 47, 0.09));
}

.ship {
  fill: #63c6b7;
  stroke: var(--ink);
  stroke-width: 6;
  stroke-linejoin: round;
}

.ship-window {
  fill: #f7c948;
  stroke: var(--ink);
  stroke-width: 6;
  stroke-linejoin: round;
}

.wing {
  fill: #e74f5b;
  stroke: var(--ink);
  stroke-width: 6;
  stroke-linejoin: round;
}

.face {
  fill: #fffdf7;
  stroke: var(--ink);
  stroke-width: 6;
}

.smile,
.spark {
  fill: none;
  stroke: var(--ink);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.spark {
  fill: #f7c948;
}

.s2 {
  fill: #93d66f;
}

.prompt-zone {
  display: grid;
  grid-template-columns: minmax(74px, 96px) minmax(0, 1fr) 58px;
  gap: 14px;
  align-items: center;
  min-width: 0;
}

.picture {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 5px 5px 0 rgba(21, 36, 47, 0.1);
  font-size: clamp(2.35rem, 6vw, 4rem);
  line-height: 1;
}

.prompt-copy {
  min-width: 0;
}

.small-label {
  display: inline-block;
  margin: 0 0 8px;
  padding: 4px 10px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #f7c948;
  font-size: 0.88rem;
  font-weight: 900;
}

.prompt-copy h2 {
  margin: 0;
  font-size: clamp(1.42rem, 4.7vw, 3.15rem);
  line-height: 1.05;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.prompt-copy p:last-child {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  font-weight: 800;
}

.sound-button {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  background: #ffffff;
  color: var(--blue);
  font-size: 1.15rem;
}

.quiz-panel,
.trace-panel {
  grid-column: 1 / -1;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.choice-card {
  display: grid;
  place-items: center;
  min-height: 150px;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 6px 6px 0 rgba(21, 36, 47, 0.1);
  font-size: clamp(3.5rem, 9vw, 6.8rem);
  font-weight: 900;
  line-height: 1;
}

.choice-card:nth-child(1) {
  border-color: var(--blue);
}

.choice-card:nth-child(2) {
  border-color: var(--red);
}

.choice-card:nth-child(3) {
  border-color: var(--green);
}

.choice-card:nth-child(4) {
  border-color: var(--violet);
}

.choice-card.correct {
  color: #146b46;
  background: #dff8e9;
  transform: translate(2px, 2px);
  box-shadow: 3px 3px 0 rgba(21, 36, 47, 0.12);
}

.choice-card.miss {
  animation: shake 180ms ease-in-out 2;
}

.trace-panel {
  display: grid;
  gap: 12px;
  margin-top: 10px;
}

.trace-panel.hidden,
.quiz-panel.hidden {
  display: none;
}

.trace-board {
  position: relative;
  width: min(100%, 560px);
  aspect-ratio: 1.25;
  margin: 0 auto;
  overflow: hidden;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: linear-gradient(90deg, transparent calc(50% - 1px), rgba(21, 36, 47, 0.18) calc(50% - 1px), rgba(21, 36, 47, 0.18) calc(50% + 1px), transparent calc(50% + 1px)), linear-gradient(0deg, transparent calc(50% - 1px), rgba(21, 36, 47, 0.18) calc(50% - 1px), rgba(21, 36, 47, 0.18) calc(50% + 1px), transparent calc(50% + 1px)), #ffffff;
  box-shadow: inset 0 0 0 10px rgba(247, 201, 72, 0.16);
  touch-action: none;
}

.trace-board.try-again {
  animation: shake 180ms ease-in-out 2;
  box-shadow:
    inset 0 0 0 10px rgba(231, 79, 91, 0.15),
    0 0 0 4px rgba(231, 79, 91, 0.16);
}

.trace-letter {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(47, 127, 210, 0.17);
  font-size: clamp(9rem, 30vw, 18rem);
  font-weight: 900;
  line-height: 1;
  user-select: none;
}

.stroke-guide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.guide-stroke {
  fill: none;
  stroke: rgba(21, 36, 47, 0.36);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 4 4;
}

.guide-start {
  fill: #f7c948;
  stroke: var(--ink);
  stroke-width: 0.8;
}

.guide-number {
  fill: var(--ink);
  font-family: system-ui, sans-serif;
  font-size: 4.2px;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: central;
}

#traceCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.trace-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 124px;
  padding: 9px 16px;
  background: #ffffff;
}

.tool-button.primary {
  color: #ffffff;
  background: var(--green);
}

.feedback {
  grid-column: 1 / -1;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  font-size: clamp(1.15rem, 3vw, 1.7rem);
  font-weight: 900;
  text-align: center;
}

.kana-map {
  padding: 14px;
}

.map-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.map-heading h2 {
  margin: 0;
  font-size: 1.15rem;
}

.mini-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  background: #ffffff;
  font-size: 1.2rem;
}

.kana-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.kana-tile {
  display: grid;
  gap: 2px;
  place-items: center;
  min-height: 68px;
  padding: 6px 4px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.kana-tile.active {
  border-color: var(--blue);
  background: #eaf4ff;
}

.kana-char {
  font-size: 1.55rem;
  font-weight: 900;
  line-height: 1;
}

.kana-stars {
  min-height: 16px;
  color: #d79b00;
  font-size: 0.78rem;
  line-height: 1;
}

.confetti {
  position: fixed;
  z-index: 20;
  width: 12px;
  height: 16px;
  border-radius: 3px;
  pointer-events: none;
  animation: confetti 900ms ease-out forwards;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(8px);
  }
}

@keyframes confetti {
  0% {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--dx), var(--dy), 0) rotate(260deg);
  }
}

@media (max-width: 900px) {
  .play-area,
  .stage {
    grid-template-columns: 1fr;
  }

  .mascot-wrap {
    min-height: 82px;
  }

  .mascot {
    width: 98px;
  }
}

@media (max-width: 720px) {
  .app {
    width: min(100% - 18px, 1180px);
    padding-top: 10px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .scoreboard {
    grid-template-columns: repeat(2, 1fr);
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .mode-tabs {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .prompt-zone {
    grid-template-columns: 78px minmax(0, 1fr) 52px;
    gap: 9px;
  }

  .picture {
    font-size: 2.1rem;
  }

  .sound-button {
    width: 52px;
    height: 52px;
  }

  .choice-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .choice-card {
    min-height: 112px;
  }
}

@media (max-width: 440px) {
  .brand-mark {
    width: 48px;
    height: 48px;
  }

  .stage,
  .kana-map {
    border-width: 3px;
  }

  .stage {
    padding: 12px;
    min-height: 0;
  }

  .prompt-zone {
    grid-template-columns: 1fr 52px;
  }

  .picture {
    grid-column: 1 / -1;
    width: min(92px, 100%);
    justify-self: center;
  }

  .kana-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
