:root {
  --bg: #0b0e14;
  --bg-alt: #11151f;
  --card: #161b26;
  --text: #e8e6df;
  --text-dim: #9aa1af;
  --accent: #b3492b;
  --accent-bright: #e0673e;
  --line: #262c3a;
  --danger: #8c2c2c;
  --danger-bright: #c8433a;
  --good: #3f7f5f;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  /* Set at runtime (ads-runtime.js) to the native AdMob banner's actual
     height once it loads, so it never overlaps the choice buttons. */
  --ad-banner-height: 0px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Georgia", "Iowan Old Style", "Times New Roman", serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(179,73,43,0.10), transparent),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.015) 0px, transparent 1px, transparent 2px);
}

#app {
  height: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}
.screen[hidden] {
  display: none;
}

/* ---------- MENU ---------- */
.menu-wrap {
  margin: auto;
  max-width: 480px;
  width: 100%;
  padding: 32px 28px;
  text-align: center;
}

.menu-icon {
  color: var(--accent-bright);
  margin-bottom: 8px;
}

.menu-wrap h1 {
  font-size: 2.3rem;
  letter-spacing: 0.02em;
  margin: 8px 0 0;
  color: var(--text);
  text-shadow: 0 0 24px rgba(224,103,62,0.25);
}

.subtitle {
  color: var(--accent-bright);
  font-style: italic;
  margin: 4px 0 20px;
  letter-spacing: 0.04em;
  font-size: 1rem;
}

.menu-flavor {
  color: var(--text-dim);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 28px;
}

.menu-endings {
  color: var(--accent-bright);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  margin: 0 0 20px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.menu-footer {
  color: var(--text-dim);
  font-size: 0.75rem;
  line-height: 1.4;
  opacity: 0.7;
}

.menu-footer a {
  color: var(--text-dim);
}

.menu-credit {
  margin-top: 8px;
}

.lang-switcher {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 14px 0 18px;
}

.lang-btn {
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}

.lang-btn.active {
  background: var(--accent);
  border-color: var(--accent-bright);
  color: #fff8f4;
}

.audio-switcher {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 0 0 18px;
  flex-wrap: wrap;
}

.audio-btn {
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}

.audio-btn.off {
  color: var(--text-dim);
  opacity: 0.55;
  text-decoration: line-through;
}

/* ---------- BUTTONS ---------- */
.btn {
  font-family: inherit;
  font-size: 1.05rem;
  padding: 15px 20px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
  -webkit-user-select: none;
  user-select: none;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(180deg, var(--accent-bright), var(--accent));
  border-color: var(--accent-bright);
  color: #fff8f4;
  font-weight: 600;
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text-dim);
}

.btn-danger {
  background: linear-gradient(180deg, var(--danger-bright), var(--danger));
  border-color: var(--danger-bright);
  color: #fff;
}

/* ---------- HOW TO PLAY ---------- */
.how-wrap {
  margin: auto;
  max-width: 480px;
  width: 100%;
  padding: 32px 28px;
}
.how-wrap h2 {
  color: var(--accent-bright);
  margin-bottom: 18px;
}
.how-wrap ul {
  padding-left: 20px;
  color: var(--text);
  line-height: 1.6;
  margin-bottom: 28px;
}
.how-wrap li { margin-bottom: 12px; }

/* ---------- GAME SCREEN ---------- */
.game-header {
  padding: calc(10px + var(--safe-top)) 16px 8px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.progress-track {
  height: 5px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
  transition: width 0.5s ease;
}

.game-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chapter-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.4rem;
  line-height: 1;
  padding: 4px 10px;
  cursor: pointer;
}

.story-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 8px;
  max-width: 620px;
  margin: 0 auto;
  width: 100%;
}

.story-text {
  font-size: 1.12rem;
  line-height: 1.7;
  white-space: pre-line;
  color: var(--text);
  animation: fadein 0.4s ease;
}

@keyframes fadein {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.ending-badge {
  margin-top: 20px;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-size: 0.85rem;
}
.ending-badge.death { background: rgba(140,44,44,0.25); color: #ff9d8a; border: 1px solid var(--danger); }
.ending-badge.best { background: rgba(63,127,95,0.25); color: #8fe3b7; border: 1px solid var(--good); }
.ending-badge.good { background: rgba(63,127,95,0.18); color: #a6d9bd; border: 1px solid var(--good); }
.ending-badge.neutral { background: rgba(179,73,43,0.18); color: #e8b39d; border: 1px solid var(--accent); }

.choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 20px calc(20px + var(--safe-bottom) + var(--ad-banner-height));
  max-width: 620px;
  margin: 0 auto;
  width: 100%;
  transition: padding-bottom 0.2s ease;
}

.choice-btn {
  font-family: inherit;
  text-align: left;
  font-size: 1rem;
  line-height: 1.4;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.choice-btn:active { transform: scale(0.98); background: #1c2230; }
.choice-btn .choice-num {
  color: var(--accent-bright);
  font-weight: 700;
  flex-shrink: 0;
}

.choices.endgame {
  padding-top: 4px;
}

/* ---------- OVERLAYS ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4,5,8,0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
}
.overlay[hidden] {
  display: none;
}

.overlay-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px 22px;
  max-width: 420px;
  width: 100%;
  text-align: center;
}
.overlay-card h3 {
  margin-top: 0;
  color: var(--text);
}
.overlay-card p {
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.5;
}
.overlay-card .btn {
  width: 100%;
  margin-top: 10px;
}

/* ---------- LANDSCAPE PHONES (short viewport) ---------- */
@media (orientation: landscape) and (max-height: 500px) {
  .menu-wrap, .how-wrap {
    margin: 0 auto;
    padding: 18px 28px;
  }
  .menu-icon { display: none; }
  .menu-wrap h1 { font-size: 1.6rem; margin-top: 0; }
  .subtitle { margin-bottom: 12px; }
  .menu-flavor { margin-bottom: 14px; }
  .menu-endings { margin-bottom: 12px; }
  .menu-buttons { margin-bottom: 12px; }
  .lang-switcher, .audio-switcher { margin: 10px 0; }
  .how-wrap ul { margin-bottom: 16px; }
  .how-wrap li { margin-bottom: 8px; }

  /* A short viewport leaves too little room for the flex-sized story
     panel (it can shrink to near-nothing since overflow:auto items have
     no minimum size). Let it size to its content and scroll the whole
     game screen instead, so the story text stays readable. */
  .story-scroll {
    flex: none;
    overflow-y: visible;
  }
}

/* ---------- TABLETS / LARGE SCREENS ---------- */
@media (min-width: 700px) {
  .menu-wrap, .how-wrap {
    max-width: 560px;
  }
  .story-scroll, .choices {
    max-width: 700px;
  }
  .story-text {
    font-size: 1.2rem;
  }
  .choice-btn {
    font-size: 1.08rem;
    padding: 16px 18px;
  }
  .overlay-card {
    max-width: 460px;
  }
}
