:root {
  --green: #2ca01c;
  --green-dark: #176910;
  --orange: #f28b1d;
  --orange-dark: #bb5a00;
  --red: #d32b27;
  --red-dark: #7d0e0d;
  --gray: #9ca0a4;
  --gray-dark: #4e5459;
  --gold: #ffd15c;
  --ink: #25170c;
  --panel: rgba(255, 248, 226, .94);
  --shadow: 0 14px 35px rgba(0, 0, 0, .27);
  --radius: 20px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 15%, rgba(255,255,255,.9), transparent 18%),
    radial-gradient(circle at 80% 12%, rgba(255,255,255,.75), transparent 13%),
    linear-gradient(180deg, rgba(64,166,248,.95) 0%, rgba(144,210,255,.9) 35%, rgba(237,248,255,.85) 52%, rgba(99,165,100,.8) 53%, rgba(47,110,65,.95) 100%);
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto auto 0 0;
  width: 47vw;
  height: 52vh;
  pointer-events: none;
  opacity: .95;
  background:
    radial-gradient(circle at 34% 12%, #fff 0 4%, transparent 4.3%),
    radial-gradient(circle at 32% 18%, #ffb8c9 0 8%, transparent 8.4%),
    linear-gradient(120deg, transparent 43%, rgba(40, 18, 8, .72) 44% 46%, transparent 47%);
  filter: drop-shadow(0 8px 10px rgba(0,0,0,.22));
  transform: rotate(-6deg);
  z-index: 0;
}
body::after {
  inset: 8vh 0 auto auto;
  width: 35vw;
  height: 35vh;
  transform: rotate(10deg) scaleX(-1);
  opacity: .65;
}

.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  padding: 14px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.18), transparent 30%),
    radial-gradient(ellipse at 75% 16%, rgba(255,255,255,.8) 0 2%, transparent 2.1% 100%);
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  max-width: 1600px;
  margin: 0 auto 12px;
}

.logo-wrap {
  display: flex;
  justify-content: center;
  min-width: 0;
}
.game-logo {
  max-height: 155px;
  width: min(540px, 100%);
  object-fit: contain;
  filter: drop-shadow(0 13px 10px rgba(0,0,0,.35));
}
.top-info {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.score-card {
  min-width: 96px;
  padding: 8px 12px;
  border-radius: 14px;
  background: rgba(49, 25, 10, .88);
  color: white;
  border: 2px solid rgba(255,209,92,.7);
  box-shadow: var(--shadow);
  text-align: center;
}
.score-card span {
  display: block;
  font-size: 12px;
  color: #ffe5a3;
}
.score-card strong {
  display: block;
  font-size: 25px;
  line-height: 1.05;
}

.game-layout {
  max-width: 1600px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(290px, 420px) minmax(420px, 1fr) minmax(230px, 320px);
  gap: 14px;
  align-items: stretch;
}

.panel {
  border: 3px solid rgba(132, 74, 22, .9);
  box-shadow: var(--shadow);
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-title,
.state-title {
  background: linear-gradient(180deg, #563018, #1e120b);
  color: #fff1b2;
  text-align: center;
  padding: 12px 10px;
  font-weight: 900;
  letter-spacing: .04em;
  font-size: clamp(18px, 2vw, 24px);
  text-shadow: 0 2px 0 rgba(0,0,0,.45);
}

.left-panel {
  padding-bottom: 10px;
  background:
    linear-gradient(rgba(255,248,226,.95), rgba(255,248,226,.96)),
    radial-gradient(circle at 20% 20%, #ffe2e7 0 3%, transparent 3.5%);
}
.legend-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px 14px 0;
}
.mini-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 800;
  text-shadow: 0 1px 0 rgba(0,0,0,.35);
}
.mini-box.pt { background: linear-gradient(180deg, #63d43e, var(--green)); }
.mini-box.en { background: linear-gradient(180deg, #ffbd54, var(--orange)); }

.choices {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  max-height: 58vh;
  overflow: auto;
}
.choice-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) 24px minmax(0,1fr);
  gap: 8px;
  align-items: stretch;
  border: 0;
  background: rgba(255,255,255,.32);
  border-radius: 16px;
  padding: 6px;
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease, background .12s ease;
}
.choice-row:hover,
.choice-row:focus-visible {
  transform: translateY(-2px) scale(1.01);
  outline: none;
  background: rgba(255,255,255,.75);
}
.choice-row.correct-flash { animation: correctFlash .45s ease; }
.choice-row.wrong-flash { animation: wrongShake .35s ease; }
.word-box {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 8px 8px;
  border-radius: 13px;
  color: white;
  font-weight: 900;
  text-align: center;
  line-height: 1.1;
  text-shadow: 0 2px 0 rgba(0,0,0,.35);
  border: 2px solid rgba(255,255,255,.45);
  word-break: break-word;
}
.word-box.pt {
  background: linear-gradient(180deg, #78df46, var(--green) 55%, var(--green-dark));
  box-shadow: inset 0 2px 0 rgba(255,255,255,.5), 0 5px 0 #0f4f0c;
}
.word-box.en {
  background: linear-gradient(180deg, #ffc65f, var(--orange) 55%, var(--orange-dark));
  box-shadow: inset 0 2px 0 rgba(255,255,255,.5), 0 5px 0 #8d3e00;
}
.link-mark {
  align-self: center;
  text-align: center;
  color: #88430c;
  font-weight: 900;
  font-size: 22px;
}

.howto {
  margin: 0 14px;
  padding: 12px 14px;
  background: rgba(255,255,255,.72);
  border-radius: 16px;
  border: 2px dashed rgba(132,74,22,.45);
}
.howto h2 { margin: 0 0 6px; font-size: 18px; }
.howto ol { margin: 0; padding-left: 22px; font-weight: 700; }
.howto li { margin: 4px 0; }

.center-panel {
  display: flex;
  flex-direction: column;
  min-height: 700px;
  background: rgba(30, 42, 63, .93);
  border-color: rgba(255,209,92,.9);
}
.game-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: linear-gradient(180deg, rgba(29,16,11,.94), rgba(60,33,17,.9));
  color: white;
}
.mode-label {
  color: var(--gold);
  font-weight: 900;
  letter-spacing: .04em;
  font-size: 18px;
}
.message {
  min-height: 20px;
  color: #fff8e0;
  font-weight: 800;
  font-size: 14px;
}
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: flex-end;
}
select,
.btn,
.footer-btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 13px;
  font-weight: 900;
  cursor: pointer;
  font-family: inherit;
}
select {
  background: #fff8e8;
  color: #3a220f;
  border: 2px solid rgba(255,209,92,.8);
}
.btn {
  background: #f5e4b7;
  color: #321b0c;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.16);
}
.btn.primary { background: linear-gradient(180deg, #ffe588, #f2a70c); }
.btn.danger { background: linear-gradient(180deg, #ff8f80, #c32925); color: white; }
.btn.big { min-width: 160px; font-size: 18px; }

.playfield {
  position: relative;
  flex: 1;
  min-height: 520px;
  margin: 14px;
  border-radius: 22px;
  border: 3px solid rgba(255,209,92,.75);
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(6,25,55,.68), rgba(9,27,42,.88)),
    url("assets/concept.png") center / cover no-repeat;
}
.playfield::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 0, rgba(255,220,110,.20), transparent 20%),
    repeating-radial-gradient(circle at 50% 25%, rgba(255,255,255,.07) 0 2px, transparent 3px 24px),
    linear-gradient(180deg, rgba(7,16,37,.55), rgba(2,9,22,.7));
  pointer-events: none;
}
.guide-lines {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  pointer-events: none;
  z-index: 1;
}
.guide-lines span { border-right: 2px dashed rgba(255,255,255,.18); }
.guide-lines span:last-child { border-right: 0; }
.fall-arrow {
  position: absolute;
  left: 50%;
  top: 60px;
  transform: translateX(-50%);
  color: #ffe081;
  font-size: 48px;
  line-height: .55;
  text-shadow: 0 0 18px rgba(255,73,37,.8);
  opacity: .88;
  z-index: 2;
  animation: pulseArrow 1s ease-in-out infinite;
}

.jp-tile {
  position: absolute;
  left: 50%;
  width: min(300px, 72%);
  min-height: 102px;
  transform: translate(-50%, 0);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-radius: 21px;
  border: 3px solid rgba(255,255,255,.7);
  z-index: 4;
  color: white;
  text-shadow: 0 3px 0 rgba(0,0,0,.45);
  box-shadow: 0 16px 20px rgba(0,0,0,.36), inset 0 3px 0 rgba(255,255,255,.22);
  user-select: none;
}
.jp-tile.falling {
  background: linear-gradient(180deg, #ff5a54, var(--red) 55%, var(--red-dark));
}
.jp-main { font-size: clamp(38px, 5.4vw, 64px); font-weight: 950; letter-spacing: .08em; line-height: 1; }
.jp-kana { font-size: clamp(18px, 2.4vw, 30px); font-weight: 950; margin-top: 8px; }
.hidden { display: none !important; }
.fixed-stack {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 12px;
  width: min(360px, 82%);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}
.fixed-tile {
  min-height: 60px;
  border-radius: 15px;
  background: linear-gradient(180deg, #cfd3d6, var(--gray) 55%, var(--gray-dark));
  color: white;
  border: 2px solid rgba(255,255,255,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  font-weight: 950;
  text-shadow: 0 2px 0 rgba(0,0,0,.45);
  box-shadow: 0 8px 10px rgba(0,0,0,.26), inset 0 2px 0 rgba(255,255,255,.4);
  animation: landPop .2s ease;
}
.fixed-tile .jp-main-small { font-size: 30px; line-height: 1; letter-spacing: .04em; }
.fixed-tile .jp-kana-small { font-size: 16px; margin-top: 4px; }

.bottom-banner {
  margin: 0 14px 14px;
  padding: 13px 16px;
  border-radius: 16px;
  text-align: center;
  background: linear-gradient(180deg, #fff9df, #f0c97e);
  border: 3px solid rgba(132,74,22,.7);
  color: #48250e;
  font-weight: 900;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.1);
}
.bottom-banner strong:first-child { color: var(--red); }
.bottom-banner strong:last-child { color: var(--green-dark); }

.right-panel {
  display: grid;
  gap: 14px;
  grid-template-rows: 1fr 1fr;
}
.state-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: rgba(255,248,226,.95);
}
.state-card.muted { filter: saturate(.68); opacity: .86; }
.state-card.active { filter: saturate(1.25); opacity: 1; animation: stateGlow .9s ease; }
.green-title { background: linear-gradient(180deg, #2bb422, #0e4f14); color: white; }
.red-title { background: linear-gradient(180deg, #ee493f, #6e0b0a); color: white; }
.state-character {
  object-fit: contain;
  width: 100%;
  min-height: 0;
  flex: 1;
  padding: 8px;
}
.success-person { max-height: 255px; }
.gameover-person { max-height: 255px; }
.state-message {
  padding: 9px 10px 12px;
  text-align: center;
  font-weight: 900;
  color: white;
  background: rgba(49,25,10,.88);
}
.success-card.active .state-message { background: #116c17; }
.gameover-card.active .state-message { background: #970f0f; }

.footer-bar {
  max-width: 1600px;
  margin: 12px auto 0;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: rgba(35, 20, 12, .86);
  border-radius: 20px;
  border: 2px solid rgba(255,209,92,.5);
  padding: 9px 12px;
  box-shadow: var(--shadow);
}
.footer-btn {
  background: #fff3d2;
  color: #3b210e;
}
.notice {
  color: #fff0be;
  font-weight: 700;
  margin-left: auto;
  font-size: 13px;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0,0,0,.62);
  display: grid;
  place-items: center;
  padding: 18px;
}
.overlay-box {
  width: min(480px, 96vw);
  max-height: 92vh;
  overflow: auto;
  border-radius: 26px;
  border: 4px solid var(--gold);
  background: linear-gradient(180deg, #fff8dc, #f0c480);
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
  text-align: center;
  padding: 18px;
  animation: overlayIn .25s ease;
}
.overlay-title {
  font-size: 36px;
  font-weight: 950;
  color: #9b1611;
  text-shadow: 0 2px 0 white;
}
.overlay-character {
  max-width: 74%;
  max-height: 350px;
  object-fit: contain;
  margin: 8px auto;
}
.overlay-text {
  font-size: 18px;
  font-weight: 900;
  margin: 8px 0 16px;
  white-space: pre-line;
}

@keyframes pulseArrow {
  0%,100% { transform: translateX(-50%) translateY(0); opacity: .65; }
  50% { transform: translateX(-50%) translateY(8px); opacity: 1; }
}
@keyframes wrongShake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  50% { transform: translateX(7px); }
  75% { transform: translateX(-4px); }
}
@keyframes correctFlash {
  0% { filter: brightness(1); }
  45% { filter: brightness(1.55); transform: scale(1.03); }
  100% { filter: brightness(1); }
}
@keyframes landPop {
  from { transform: scale(.9); opacity: .2; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes stateGlow {
  0%,100% { transform: scale(1); box-shadow: var(--shadow); }
  50% { transform: scale(1.03); box-shadow: 0 0 38px rgba(255,235,100,.8); }
}
@keyframes overlayIn {
  from { transform: scale(.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@media (max-width: 1120px) {
  .topbar { grid-template-columns: 1fr; }
  .top-info { justify-content: center; }
  .game-layout { grid-template-columns: 1fr; }
  .center-panel { min-height: 640px; }
  .right-panel { grid-template-columns: 1fr 1fr; grid-template-rows: auto; }
  .choices { max-height: none; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .app-shell { padding: 8px; }
  .game-logo { max-height: 112px; }
  .score-card { min-width: 84px; padding: 7px 8px; }
  .score-card strong { font-size: 22px; }
  .game-layout { gap: 10px; }
  .choices { grid-template-columns: 1fr; }
  .choice-row { grid-template-columns: 1fr; }
  .link-mark { display: none; }
  .game-head { align-items: stretch; flex-direction: column; }
  .controls { justify-content: stretch; }
  .controls > * { flex: 1 1 46%; }
  .center-panel { min-height: 610px; }
  .playfield { min-height: 420px; margin: 10px; }
  .jp-tile { min-height: 90px; width: 78%; }
  .right-panel { grid-template-columns: 1fr; }
  .success-person, .gameover-person { max-height: 205px; }
  .notice { margin-left: 0; }
}
