:root {
  --red: #e53935;
  --red-deep: #b71c1c;
  --green: #18a957;
  --green-deep: #08743a;
  --orange: #ff9f1a;
  --orange-deep: #c96d00;
  --gray: #8d96a3;
  --ink: #1e2430;
  --paper: rgba(255, 255, 255, 0.94);
  --line: rgba(30, 36, 48, 0.13);
  --shadow: 0 18px 40px rgba(45, 28, 23, 0.22);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", "Noto Sans", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 5%, rgba(255, 255, 255, 0.8), transparent 32%),
    linear-gradient(160deg, #ffe5ec 0%, #fff7e6 36%, #dff6ff 70%, #d2ffe5 100%);
  overflow: hidden;
}

button, select, input {
  font: inherit;
}

button {
  cursor: pointer;
}

.phone-shell {
  position: relative;
  width: min(100vw, 480px);
  height: 100dvh;
  min-height: 640px;
  margin: 0 auto;
  overflow: hidden;
  background: #fff8ef;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08), 0 0 35px rgba(0, 0, 0, 0.18);
}

.bg-soft {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(rgba(255, 247, 236, 0.86), rgba(255, 247, 236, 0.78)),
    url("assets/background.png") center / cover no-repeat;
  opacity: 0.52;
  pointer-events: none;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 1;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hidden {
  display: none !important;
}

.start-screen,
.info-screen,
.words-screen,
.result-screen {
  justify-content: center;
  overflow: auto;
  padding-bottom: calc(18px + var(--safe-bottom));
}

.brand-card,
.menu-card,
.info-card,
.words-card,
.result-card,
.game-top,
.play-card,
.bottom-nav {
  background: var(--paper);
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.brand-card {
  padding: 16px 18px;
  text-align: center;
}

.logo {
  width: min(48vw, 178px);
  aspect-ratio: 1 / 1;
  object-fit: contain;
  display: block;
  margin: -4px auto -18px;
  filter: drop-shadow(0 8px 10px rgba(68, 39, 18, 0.25));
}

.brand-card h1 {
  margin: 0;
  font-size: clamp(32px, 10vw, 46px);
  line-height: 0.95;
  color: #d82525;
  letter-spacing: -0.04em;
  text-shadow: 0 3px 0 rgba(255, 255, 255, 0.9);
}

.brand-card p {
  margin: 10px auto 0;
  max-width: 31ch;
  font-weight: 700;
  line-height: 1.35;
}

.menu-card,
.info-card,
.words-card,
.result-card {
  padding: 18px;
}

.menu-card h2,
.info-card h2,
.words-card h2,
.result-card h2 {
  margin: 0 0 12px;
  font-size: 26px;
  color: #7b3100;
}

.menu-btn,
.level-btn,
.bottom-nav button {
  border: 0;
  border-radius: 16px;
  font-weight: 900;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.12), 0 12px 20px rgba(0, 0, 0, 0.12);
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}

.menu-btn:active,
.level-btn:active,
.bottom-nav button:active,
.choice-card:active {
  transform: translateY(2px) scale(0.99);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12), 0 8px 14px rgba(0, 0, 0, 0.12);
}

.menu-btn {
  width: 100%;
  min-height: 48px;
  margin: 8px 0;
  background: #fff;
  color: #793602;
  border: 2px solid rgba(121, 54, 2, 0.18);
}

.menu-btn.primary {
  background: linear-gradient(180deg, #ff3e3e, #d91919);
  color: #fff;
  border-color: transparent;
}

.level-box {
  margin-top: 14px;
  padding: 12px;
  border-radius: 18px;
  background: rgba(255, 214, 163, 0.42);
  border: 1px solid rgba(126, 56, 4, 0.12);
}

.level-box p {
  margin: 0 0 8px;
  font-weight: 900;
  color: #7b3100;
}

.level-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.level-btn {
  min-height: 62px;
  padding: 8px 4px;
  background: #fffaf2;
  color: #7b3100;
  border: 2px solid rgba(123, 49, 0, 0.12);
}

.level-btn small {
  font-weight: 800;
  opacity: 0.75;
}

.level-btn.active {
  background: linear-gradient(180deg, #25c76b, #0f994a);
  color: #fff;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}

.toggle-row {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.76);
  font-weight: 850;
}

.game-screen {
  padding: 8px;
  gap: 8px;
}

.game-top {
  flex: 0 0 auto;
  padding: 8px;
}

.top-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-title img {
  width: 45px;
  height: 45px;
  object-fit: contain;
}

.top-title strong {
  display: block;
  font-size: 19px;
  line-height: 1;
  color: #d82525;
}

.top-title span {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  font-weight: 800;
  color: #7b3100;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 6px;
}

.score-grid div {
  padding: 5px 7px;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff, #fff4df);
  text-align: center;
  border: 1px solid rgba(118, 68, 0, 0.11);
}

.score-grid span {
  display: block;
  color: #81510d;
  font-size: 11px;
  font-weight: 850;
}

.score-grid strong {
  display: block;
  color: #1b2430;
  font-size: 18px;
  line-height: 1.1;
}

.play-card {
  flex: 1 1 auto;
  min-height: 0;
  padding: 8px;
  display: flex;
  flex-direction: column;
}

.play-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 36px;
  padding: 4px 4px 8px;
  font-weight: 850;
}

#roundInfo {
  font-size: 13px;
  color: #7b3100;
  white-space: nowrap;
}

.message {
  flex: 1;
  text-align: right;
  font-size: 13px;
  color: #2d5b35;
  font-weight: 900;
  min-width: 0;
}

.message.bad {
  color: #c22626;
}

.play-row {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(132px, 42%);
  gap: 8px;
}

.fall-zone {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border-radius: 22px;
  background:
    linear-gradient(rgba(14, 39, 66, 0.72), rgba(32, 73, 102, 0.56)),
    radial-gradient(circle at 50% 12%, rgba(255, 255, 255, 0.22), transparent 32%);
  border: 2px solid rgba(255, 255, 255, 0.75);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.05);
}

.lane-bg {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent 32%, rgba(255, 255, 255, 0.16) 32% 34%, transparent 34% 66%, rgba(255, 255, 255, 0.16) 66% 68%, transparent 68%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.04) 0 2px, transparent 2px 32px);
  opacity: 0.75;
}

.fall-guide {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.48);
  font-size: 36px;
  font-weight: 900;
  animation: pulseArrow 1.1s ease-in-out infinite;
}

@keyframes pulseArrow {
  0%, 100% { opacity: 0.25; transform: translateX(-50%) translateY(0); }
  50% { opacity: 0.9; transform: translateX(-50%) translateY(10px); }
}

.jp-tile {
  position: absolute;
  left: 50%;
  transform: translate(-50%, 0);
  width: min(88%, 190px);
  border-radius: 18px;
  text-align: center;
  color: #fff;
  font-weight: 950;
  border: 2px solid rgba(255, 255, 255, 0.88);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.25);
  z-index: 3;
  user-select: none;
}

.falling {
  top: 0;
  padding: 12px 6px 10px;
  background: linear-gradient(180deg, #ff5656, var(--red));
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
}

.jp-main {
  font-size: clamp(28px, 9vw, 44px);
  line-height: 1.02;
  letter-spacing: 0.04em;
}

.jp-kana {
  margin-top: 4px;
  font-size: clamp(14px, 4.2vw, 19px);
  line-height: 1.05;
  opacity: 0.95;
}

.fixed-stack {
  position: absolute;
  left: 7px;
  right: 7px;
  bottom: 7px;
  display: flex;
  flex-direction: column-reverse;
  gap: 5px;
  z-index: 2;
  pointer-events: none;
}

.fixed-tile {
  position: relative;
  width: 100%;
  transform: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 5px;
  border-radius: 13px;
  background: linear-gradient(180deg, #aeb6c2, var(--gray));
  color: #fff;
  font-weight: 950;
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.18);
}

.fixed-tile .fixed-kanji {
  font-size: 18px;
}

.fixed-tile .fixed-kana {
  font-size: 11px;
  opacity: 0.92;
}

.choices-zone {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-radius: 22px;
  padding: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(255, 247, 225, 0.8));
  border: 2px solid rgba(255, 255, 255, 0.84);
}

.choices-title {
  flex: 0 0 auto;
  text-align: center;
  font-weight: 950;
  color: #7b3100;
  font-size: 13px;
}

.choices {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  gap: 7px;
}

.choices.count-3 { grid-template-rows: repeat(3, 1fr); }
.choices.count-5 { grid-template-rows: repeat(5, 1fr); gap: 6px; }
.choices.count-7 { grid-template-rows: repeat(7, 1fr); gap: 4px; }

.choice-card {
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr 1fr;
  border: 0;
  background: transparent;
  padding: 0;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 6px 0 rgba(80, 48, 0, 0.15), 0 10px 16px rgba(0, 0, 0, 0.12);
  transition: transform 100ms ease, box-shadow 100ms ease, filter 100ms ease;
}

.choice-line {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 5px;
  color: #fff;
  font-weight: 950;
  line-height: 1.08;
  text-align: center;
  overflow-wrap: anywhere;
}

.choice-pt {
  background: linear-gradient(180deg, #28ca72, var(--green));
  border-bottom: 1px solid rgba(255, 255, 255, 0.45);
  font-size: clamp(12px, 3.35vw, 15px);
}

.choice-en {
  background: linear-gradient(180deg, #ffb13b, var(--orange));
  font-size: clamp(11px, 3.15vw, 14px);
}

.choices.count-7 .choice-line {
  font-size: 10.5px;
  padding: 2px 4px;
}

.choice-card.correct-flash {
  filter: brightness(1.25) saturate(1.2);
  transform: scale(1.04);
}

.choice-card.wrong {
  animation: shake 260ms linear;
  filter: hue-rotate(130deg) saturate(1.4);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

.bottom-nav {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 7px;
  padding-bottom: calc(7px + var(--safe-bottom));
}

.bottom-nav button {
  min-height: 42px;
  color: #6e3700;
  background: linear-gradient(180deg, #fff, #ffe7ba);
  border: 1px solid rgba(110, 55, 0, 0.12);
  font-size: 13px;
}

.info-card,
.words-card {
  max-height: min(85dvh, 700px);
  overflow: auto;
}

.info-card ol {
  margin: 0 0 14px;
  padding-left: 22px;
  line-height: 1.55;
  font-weight: 750;
}

.words-list {
  display: grid;
  gap: 8px;
  max-height: 58dvh;
  overflow: auto;
  padding-right: 4px;
}

.word-row {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 6px;
  padding: 8px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
}

.word-row .jp {
  font-weight: 950;
  color: #d82525;
}

.word-row .meaning {
  display: grid;
  gap: 3px;
}

.word-row .pt {
  color: #0b793c;
  font-weight: 850;
}

.word-row .en {
  color: #b86400;
  font-weight: 850;
}

.result-screen {
  text-align: center;
}

.result-card {
  overflow: hidden;
  position: relative;
}

.result-card.success h2 {
  color: #0f994a;
}

.result-card.gameover h2 {
  color: #c22626;
}

#resultTitle {
  font-size: clamp(34px, 11vw, 52px);
  letter-spacing: -0.04em;
}

#resultCharacter {
  display: block;
  width: min(68vw, 245px);
  max-height: 42dvh;
  object-fit: contain;
  margin: 2px auto 8px;
  filter: drop-shadow(0 12px 16px rgba(0, 0, 0, 0.25));
}

#resultMessage {
  margin: 4px auto 12px;
  font-size: 18px;
  font-weight: 900;
  line-height: 1.35;
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  margin: 0 0 14px;
}

.result-stats div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
}

.result-stats span {
  color: #7b3100;
  font-weight: 850;
}

.result-stats strong {
  font-size: 22px;
}

.paused .falling {
  filter: grayscale(0.25) brightness(0.85);
}

@media (max-height: 700px) {
  .phone-shell { min-height: 560px; }
  .brand-card { padding: 8px 14px; }
  .logo { width: 110px; margin-bottom: -14px; }
  .brand-card h1 { font-size: 34px; }
  .brand-card p { font-size: 13px; }
  .menu-card { padding: 12px; }
  .menu-btn { min-height: 42px; margin: 5px 0; }
  .level-btn { min-height: 54px; font-size: 12px; }
  .top-title img { width: 36px; height: 36px; }
  .score-grid strong { font-size: 16px; }
  .play-head { min-height: 28px; padding-bottom: 4px; }
  .bottom-nav button { min-height: 36px; font-size: 12px; }
  .fixed-tile { padding: 4px; }
}

@media (max-width: 360px) {
  .game-screen { padding: 6px; }
  .play-row { grid-template-columns: minmax(0, 1fr) minmax(118px, 43%); gap: 6px; }
  .choices-zone { padding: 6px; }
  .choice-pt { font-size: 11px; }
  .choice-en { font-size: 10.5px; }
  .bottom-nav { gap: 4px; }
  .bottom-nav button { font-size: 11px; }
}
