:root {
  --ink: #392922;
  --muted: #75645c;
  --wine: #8b3f2f;
  --wine-dark: #5d291f;
  --gold: #f0b85a;
  --gold-soft: #fff0cc;
  --cream: #fff9ef;
  --green: #237555;
  --green-soft: #e7f6ee;
  --red: #a33d36;
  --red-soft: #fff0ed;
  --line: #ead8c7;
  --shadow: 0 20px 55px rgba(73, 38, 26, .2);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100%;
  margin: 0;
  padding: 16px;
  background:
    radial-gradient(circle at 5% 5%, rgba(240, 184, 90, .24), transparent 24rem),
    radial-gradient(circle at 95% 0%, rgba(139, 63, 47, .2), transparent 28rem),
    linear-gradient(180deg, #fff8eb, #f5e9dc);
  color: var(--ink);
  font-family: "Trebuchet MS", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button:focus-visible,
a:focus-visible,
textarea:focus-visible {
  outline: 4px solid rgba(139, 63, 47, .26);
  outline-offset: 3px;
}

.app-shell {
  width: min(1420px, 100%);
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .85);
  border-radius: 28px;
  background: rgba(255, 255, 255, .78);
  box-shadow: var(--shadow);
}

.topbar {
  min-height: 68px;
  padding: 10px 15px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(100deg, var(--wine-dark), var(--wine));
  color: white;
}

.icon-link,
.icon-button {
  width: 43px;
  height: 43px;
  flex: 0 0 43px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .15);
  color: white;
  text-decoration: none;
  font-size: 22px;
  cursor: pointer;
}

.icon-link:hover,
.icon-button:hover { background: rgba(255, 255, 255, .25); }
.story-title { min-width: 0; flex: 1; }
.story-title small, .story-title strong { display: block; }
.story-title small { color: #f8cf9b; font-size: 10px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; }
.story-title strong { margin-top: 2px; overflow: hidden; font-size: clamp(15px, 2.2vw, 21px); text-overflow: ellipsis; white-space: nowrap; }
.scene-counter { padding: 8px 11px; border-radius: 999px; background: rgba(255, 255, 255, .14); font-size: 13px; font-weight: 1000; }
.progress-track { height: 5px; background: #e6cdb9; }
.progress-track span { display: block; width: 10%; height: 100%; border-radius: 0 99px 99px 0; background: linear-gradient(90deg, var(--gold), #ffd98e); transition: width .35s ease; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.28fr) minmax(390px, .72fr);
  gap: 0;
  min-height: 680px;
}

.scene-card { position: relative; min-width: 0; background: #28140f; }
.scene-visual { position: relative; aspect-ratio: 16 / 9; overflow: hidden; background: #321a14; }
.scene-visual::after { content: ""; position: absolute; inset: 55% 0 0; background: linear-gradient(transparent, rgba(32, 13, 8, .56)); pointer-events: none; }
.scene-visual img { width: 100%; height: 100%; display: block; object-fit: cover; transition: opacity .22s ease, transform .45s ease; }
.scene-visual img.changing { opacity: .25; transform: scale(1.015); }
.scene-badge { position: absolute; z-index: 1; top: 16px; left: 16px; padding: 7px 10px; border-radius: 999px; background: rgba(48, 21, 15, .76); color: white; font-size: 10px; font-weight: 1000; letter-spacing: .09em; }

.dialogue {
  padding: clamp(20px, 3vw, 34px);
  background: linear-gradient(135deg, #32170f, #53271d);
  color: white;
}

.speaker-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.speaker { color: #ffd494; font-size: 12px; font-weight: 1000; letter-spacing: .08em; text-transform: uppercase; }
.listen-button, .translation-button { border: 0; cursor: pointer; }
.listen-button { padding: 8px 12px; border-radius: 999px; background: rgba(255, 255, 255, .13); color: white; font-size: 12px; font-weight: 900; }
.listen-button.speaking { background: var(--gold); color: var(--wine-dark); }
.dialogue h1 { margin: 12px 0 11px; font-size: clamp(25px, 3.4vw, 43px); line-height: 1.14; letter-spacing: -.025em; }
.translation-button { padding: 0; background: transparent; color: #f7c982; font-size: 12px; font-weight: 900; text-decoration: underline; text-underline-offset: 3px; }
.translation { margin: 10px 0 0; color: rgba(255, 255, 255, .78); font-size: 14px; }

.practice-card { min-width: 0; padding: clamp(25px, 3.4vw, 43px); background: rgba(255, 255, 255, .92); }
.task-kicker { color: var(--wine); font-size: 11px; font-weight: 1000; letter-spacing: .1em; text-transform: uppercase; }
.task-heading h2 { margin: 7px 0 8px; font-size: clamp(25px, 3vw, 36px); line-height: 1.08; letter-spacing: -.025em; }
.task-heading p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.52; }

.help-buttons { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 20px; }
.help-buttons button { padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--cream); color: #6f4939; font-size: 12px; font-weight: 900; cursor: pointer; }
.help-buttons button.active { border-color: #d7a35f; background: var(--gold-soft); color: var(--wine-dark); }
.help-box { margin-top: 10px; padding: 12px 14px; border: 1px solid #ebc98f; border-radius: 13px; background: #fff9e7; color: #65483a; font-size: 14px; line-height: 1.45; }
.help-box b { color: var(--wine-dark); }

.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 22px; }
.mode-button { width: 100%; min-width: 0; min-height: 68px; padding: 11px 12px; display: flex; align-items: center; gap: 9px; border: 2px solid var(--line); border-radius: 15px; background: white; text-align: left; cursor: pointer; }
.mode-button > span:first-child { font-size: 23px; }
.mode-button > span:last-child { min-width: 0; }
.mode-button strong, .mode-button small { display: block; }
.mode-button strong { font-size: 13px; }
.mode-button small { margin-top: 3px; color: var(--muted); font-size: 10px; line-height: 1.25; }
.mode-button.active { border-color: var(--wine); background: #fff6ef; box-shadow: inset 0 0 0 1px var(--wine); }

.answer-label { display: block; margin: 18px 0 7px; color: #65483a; font-size: 12px; font-weight: 1000; }
textarea { width: 100%; min-height: 105px; resize: vertical; padding: 14px 15px; border: 2px solid #dec9b8; border-radius: 14px; background: white; color: var(--ink); font-size: 17px; line-height: 1.45; }
textarea::placeholder { color: #ad9b91; }
textarea:focus { border-color: var(--wine); }

.speech-panel { margin-top: 11px; padding: 13px; border-radius: 15px; background: #f9eee7; text-align: center; }
.speech-panel p { margin: 8px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.mic-button { min-height: 47px; padding: 10px 17px; border: 0; border-radius: 999px; background: linear-gradient(135deg, var(--wine), var(--wine-dark)); color: white; font-weight: 1000; cursor: pointer; }
.mic-button.listening { background: var(--red); animation: recording-pulse 1.15s ease-in-out infinite; }
.mic-button:disabled { opacity: .55; cursor: not-allowed; }
.mic-icon { margin-right: 5px; }
@keyframes recording-pulse { 50% { box-shadow: 0 0 0 9px rgba(163, 61, 54, .13); } }

.mode-note { margin: 11px 1px 0; color: var(--muted); font-size: 11px; line-height: 1.42; }
.feedback { margin-top: 14px; padding: 13px 14px; border-radius: 14px; font-size: 13px; line-height: 1.48; }
.feedback.good { border: 1px solid #9ed2ba; background: var(--green-soft); color: #18573e; }
.feedback.try { border: 1px solid #ebbbb5; background: var(--red-soft); color: #7e302b; }
.feedback strong { display: block; margin-bottom: 3px; }

.action-row { display: flex; gap: 9px; margin-top: 17px; }
.check-button, .next-button { min-height: 48px; flex: 1; padding: 12px 16px; border: 0; border-radius: 14px; color: white; font-weight: 1000; cursor: pointer; }
.check-button { background: linear-gradient(135deg, var(--wine), var(--wine-dark)); }
.next-button { background: linear-gradient(135deg, var(--green), #18553d); }
.check-button:hover, .next-button:hover { filter: brightness(1.06); }

.finish-card { max-width: 850px; margin: 70px auto; padding: clamp(32px, 6vw, 68px); text-align: center; }
.finish-icon { width: 76px; height: 76px; margin: 0 auto 16px; display: grid; place-items: center; border-radius: 50%; background: var(--green-soft); color: var(--green); font-size: 39px; font-weight: 1000; }
.finish-card h1 { margin: 8px 0 13px; font-size: clamp(31px, 5vw, 54px); line-height: 1.04; letter-spacing: -.04em; }
.finish-card > p:not(.task-kicker) { max-width: 660px; margin: 0 auto; color: var(--muted); line-height: 1.6; }
.finish-stats { margin: 28px 0; display: flex; justify-content: center; flex-wrap: wrap; gap: 9px; }
.finish-stats span { padding: 11px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--cream); font-size: 13px; }
.finish-stats b { color: var(--wine); }
.finish-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; }
.finish-actions button, .finish-actions a { min-height: 48px; padding: 13px 18px; display: inline-flex; align-items: center; border: 0; border-radius: 14px; background: var(--wine); color: white; font-weight: 1000; text-decoration: none; cursor: pointer; }
.finish-actions a { background: #6d625d; }

@media (max-width: 980px) {
  body { padding: 10px; }
  .app-shell { border-radius: 22px; }
  .game-layout { grid-template-columns: 1fr; }
  .scene-card { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(290px, .65fr); }
  .scene-visual { aspect-ratio: 16 / 9; }
  .dialogue { display: flex; flex-direction: column; justify-content: center; }
  .dialogue h1 { font-size: clamp(23px, 4vw, 36px); }
}

@media (max-width: 700px) {
  html, body { width: 100%; max-width: 100%; overflow-x: hidden; }
  body { padding: 0; background: white; }
  .app-shell { width: 100vw; max-width: 100vw; min-height: 100vh; border: 0; border-radius: 0; box-shadow: none; }
  .topbar { width: 100%; padding-top: max(9px, env(safe-area-inset-top)); }
  .story-title small { display: none; }
  .game-layout, .scene-card, .practice-card { width: 100%; max-width: 100vw; }
  .scene-card { display: block; }
  .scene-visual { aspect-ratio: 16 / 9; }
  .dialogue { padding: 19px 18px; }
  .dialogue h1 { margin-top: 9px; font-size: 25px; }
  .practice-card { overflow: hidden; padding: 24px 18px max(28px, env(safe-area-inset-bottom)); }
  .mode-switch { width: 100%; min-width: 0; grid-template-columns: minmax(0, 1fr); }
  .mode-button { min-height: 59px; }
  .action-row { flex-direction: column; }
}

@media (max-width: 420px) {
  .topbar { display: grid; grid-template-columns: 39px minmax(0, 1fr) 39px; gap: 8px; }
  .scene-counter { display: none; }
  .icon-link, .icon-button { width: 39px; height: 39px; flex-basis: 39px; }
  .task-heading h2 { font-size: 27px; }
  .help-buttons button { flex: 1; padding-inline: 5px; font-size: 11px; }
}

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