:root {
  color-scheme: light;
  --paper: #fffdf7;
  --cream: #fff6dc;
  --ink: #29332f;
  --muted: #65716b;
  --green: #2f7d5c;
  --green-dark: #245f48;
  --green-soft: #e7f4ec;
  --orange: #ef8d3b;
  --red: #e54848;
  --line: #dce5df;
  --shadow: 0 18px 48px rgba(58, 71, 60, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 5%, rgba(244, 189, 69, 0.24), transparent 25rem),
    radial-gradient(circle at 94% 20%, rgba(93, 185, 132, 0.2), transparent 26rem),
    #f8faf5;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
}

button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 4px solid rgba(47, 125, 92, 0.3);
  outline-offset: 3px;
}

.app-shell {
  width: min(1100px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 34px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
}

.title-area {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: clamp(0.92rem, 1.8vw, 1.05rem);
  font-weight: 900;
  letter-spacing: 0.05em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 3.6rem);
  line-height: 1.05;
  letter-spacing: 0.04em;
}

h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
}

.progress-panel {
  flex: 0 0 auto;
  min-width: 122px;
  padding: 10px 16px;
  border: 2px solid #d0e4d8;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  display: grid;
  gap: 2px;
  text-align: center;
  font-weight: 900;
  box-shadow: 0 8px 22px rgba(40, 85, 62, 0.08);
}

#progressText {
  color: var(--green-dark);
  font-size: 1.12rem;
}

#scoreText {
  color: var(--muted);
  font-size: 0.88rem;
}

.level-panel,
.script-panel,
.keyboard-panel,
.game-panel {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.level-panel,
.script-panel {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.level-buttons,
.script-buttons {
  width: min(100%, 520px);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

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

.level-button {
  min-height: 48px;
  padding: 8px 10px;
  border: 2px solid #d7dfda;
  border-radius: 14px;
  color: var(--ink);
  background: #f2f4f3;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 900;
}

.level-button.selected {
  border-color: var(--green);
  color: #fff;
  background: var(--green);
}

.game-panel {
  min-height: 560px;
  padding: 22px;
  border-radius: 28px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  align-items: center;
}

.picture-card {
  position: relative;
  width: min(100%, 500px);
  min-width: 0;
  margin: 0 auto;
  overflow: hidden;
  border: 3px solid #eadfbf;
  border-radius: 24px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.96), rgba(255, 247, 220, 0.88)),
    var(--cream);
}

.picture-frame {
  position: relative;
  height: 330px;
  padding: 18px;
  overflow: hidden;
}

.picture-frame img {
  position: absolute;
  inset: 18px;
  width: calc(100% - 36px);
  height: calc(100% - 36px);
  display: block;
  object-fit: contain;
  object-position: center;
}

.answer-panel {
  width: 100%;
  min-width: 0;
  padding: 0 6px 8px;
  display: grid;
  gap: 16px;
}

.prompt {
  margin-bottom: 0;
  color: var(--green-dark);
  text-align: center;
  font-size: clamp(1.25rem, 2.7vw, 1.75rem);
  font-weight: 900;
}

.answer-slots {
  min-height: 96px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.answer-slot {
  width: clamp(58px, 7vw, 82px);
  aspect-ratio: 1;
  border: 3px solid #b8c6bd;
  border-bottom-width: 7px;
  border-radius: 16px;
  color: var(--ink);
  background: var(--paper);
  display: grid;
  place-items: center;
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 5px 0 rgba(67, 84, 73, 0.08);
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}

.answer-slot.filled {
  border-color: #76ad8c;
  background: var(--green-soft);
}

.game-panel.is-correct .answer-slot {
  border-color: var(--green);
  background: #dff3e7;
}

.game-panel.is-wrong .answer-slots {
  animation: answer-shake 380ms ease-in-out;
}

.game-panel.is-wrong .answer-slot {
  border-color: var(--orange);
  background: #fff0dc;
}

.feedback {
  min-height: 1.7em;
  margin-bottom: 0;
  color: var(--muted);
  text-align: center;
  font-size: clamp(1rem, 2vw, 1.28rem);
  font-weight: 900;
}

.game-panel.is-correct .feedback {
  color: var(--green-dark);
}

.game-panel.is-wrong .feedback {
  color: #9a531e;
}

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

.action-button {
  min-height: 54px;
  padding: 9px 14px;
  border-radius: 16px;
  cursor: pointer;
  font-weight: 900;
}

.action-button.quiet {
  border: 2px solid #d7dfda;
  color: var(--ink);
  background: #f5f6f5;
}

.action-button.next {
  grid-column: 1 / -1;
  border: 0;
  color: #fff;
  background: var(--green);
  font-size: 1.15rem;
  box-shadow: 0 6px 0 var(--green-dark);
}

.action-button.next:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 var(--green-dark);
}

.action-button:disabled {
  cursor: default;
  opacity: 0.45;
}

.keyboard-panel {
  margin-top: 16px;
  padding: 18px;
  border-radius: 28px;
}

.keyboard-heading {
  margin-bottom: 12px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.keyboard-heading h2 {
  font-size: 1.45rem;
}

.keyboard-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-weight: 800;
}

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

.kana-key {
  min-width: 0;
  min-height: 54px;
  padding: 4px;
  border: 2px solid #c7ded0;
  border-radius: 13px;
  color: var(--green-dark);
  background: #edf8f1;
  cursor: pointer;
  font-size: clamp(1.35rem, 2.8vw, 1.85rem);
  font-weight: 900;
  box-shadow: 0 3px 0 #b7d2c0;
}

.kana-key.special {
  border-color: #ebd59a;
  color: #785414;
  background: #fff7d9;
  box-shadow: 0 3px 0 #ddca94;
}

.kana-key:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #b7d2c0;
}

.kana-key:disabled {
  cursor: default;
  opacity: 0.46;
}

.privacy-note {
  margin: 14px 0 0;
  color: var(--muted);
  text-align: center;
  font-size: 0.88rem;
  font-weight: 700;
}

.effect-layer {
  position: absolute;
  z-index: 3;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.correct-effect,
.wrong-effect {
  position: absolute;
  inset: 0;
  opacity: 0;
  display: grid;
  place-items: center;
}

.effect-layer.show-correct .correct-effect {
  opacity: 1;
}

.correct-ring {
  position: absolute;
  width: min(76%, 270px);
  aspect-ratio: 1;
  border: clamp(12px, 2.2vw, 20px) solid var(--red);
  border-radius: 50%;
  filter: drop-shadow(0 6px 2px rgba(130, 20, 20, 0.12));
  animation: circle-pop 620ms cubic-bezier(0.22, 1.3, 0.42, 1) both;
}

.correct-word {
  position: absolute;
  bottom: 16px;
  padding: 7px 18px;
  border-radius: 999px;
  color: #fff;
  background: var(--red);
  font-size: 1.35rem;
  font-weight: 1000;
  animation: word-rise 520ms ease-out both;
}

.effect-layer.show-wrong .wrong-effect {
  opacity: 1;
}

.boom-mark {
  position: relative;
  z-index: 2;
  font-size: clamp(5rem, 14vw, 8rem);
  filter: drop-shadow(0 7px 3px rgba(104, 65, 18, 0.18));
  animation: boom-pop 620ms cubic-bezier(0.22, 1.25, 0.36, 1) both;
}

.wrong-word {
  position: absolute;
  z-index: 3;
  bottom: 18px;
  padding: 7px 18px;
  border-radius: 999px;
  color: #7a481b;
  background: #fff4d9;
  border: 3px solid #f0b35e;
  font-size: 1.25rem;
  font-weight: 1000;
}

.puff {
  position: absolute;
  width: 58px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 242, 209, 0.92);
  border: 4px solid rgba(236, 166, 79, 0.76);
}

.puff-1 {
  transform: translate(-92px, -34px);
  animation: puff-left 650ms ease-out both;
}

.puff-2 {
  transform: translate(88px, -18px);
  animation: puff-right 650ms ease-out both;
}

.puff-3 {
  transform: translate(0, 70px);
  animation: puff-down 650ms ease-out both;
}

@keyframes circle-pop {
  0% { opacity: 0; transform: scale(1.45) rotate(-8deg); }
  62% { opacity: 1; transform: scale(0.92) rotate(2deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes word-rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes boom-pop {
  0% { opacity: 0; transform: scale(0.15) rotate(-18deg); }
  55% { opacity: 1; transform: scale(1.18) rotate(8deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes puff-left {
  from { opacity: 0; translate: 45px 20px; scale: 0.3; }
  to { opacity: 0.9; translate: -12px -8px; scale: 1; }
}

@keyframes puff-right {
  from { opacity: 0; translate: -45px 20px; scale: 0.3; }
  to { opacity: 0.9; translate: 12px -8px; scale: 1; }
}

@keyframes puff-down {
  from { opacity: 0; translate: 0 -40px; scale: 0.3; }
  to { opacity: 0.9; translate: 0 10px; scale: 1; }
}

@keyframes answer-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-7px); }
  80% { transform: translateX(7px); }
}

@media (max-width: 780px) {
  .app-shell {
    width: min(100% - 18px, 680px);
    padding-top: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  .progress-panel {
    min-width: 108px;
    padding: 8px 10px;
  }

  .level-panel,
  .script-panel {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .level-buttons,
  .script-buttons {
    width: 100%;
  }

  .game-panel {
    padding: 14px;
    gap: 12px;
  }

  .picture-frame {
    height: min(290px, 38vh);
  }

  .answer-panel {
    padding: 4px 2px;
  }

  .answer-slots {
    min-height: 76px;
    gap: 7px;
  }

  .answer-slot {
    width: clamp(50px, 14vw, 68px);
    border-radius: 13px;
  }

  .keyboard-panel {
    padding: 12px;
  }

  .keyboard-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

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

  .kana-key {
    min-height: 50px;
  }
}

@media (max-width: 460px) {
  h1 {
    font-size: 1.68rem;
    letter-spacing: 0;
  }

  .eyebrow {
    font-size: 0.78rem;
  }

  .level-button {
    min-height: 44px;
    font-size: 0.88rem;
  }

  .picture-frame {
    height: 230px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
