@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;700&family=Nunito:wght@600&display=swap');

:root {
  --bg-1: #f6f1e9;
  --bg-2: #f2e9ff;
  --ink: #1f1b16;
  --muted: #6c6259;
  --accent: #ff9c6b;
  --accent-2: #7bc6ff;
  --card-shadow: 0 12px 28px rgba(31, 27, 22, 0.12);
  --radius-xl: 28px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Baloo 2", "Nunito", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, var(--bg-2), var(--bg-1));
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 16px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(246, 241, 233, 0.82);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
  gap: 14px;
}

.loading-overlay.hidden {
  display: none;
}

.spinner {
  width: 52px;
  height: 52px;
  border: 6px solid rgba(31, 27, 22, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.loading-text {
  font-size: 16px;
  color: var(--muted);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.debug-panel {
  position: fixed;
  right: 16px;
  top: 84px;
  width: min(360px, calc(100vw - 32px));
  background: rgba(255, 255, 255, 0.96);
  border-radius: 16px;
  box-shadow: var(--card-shadow);
  padding: 12px;
  z-index: 50;
}

.debug-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
}

.debug-metrics {
  font-size: 14px;
  line-height: 1.35;
  white-space: pre-wrap;
  color: var(--ink);
}

.debug-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 56px;
  height: 56px;
  object-fit: contain;
}

.brand-title {
  font-size: 34px;
  font-weight: 700;
}

.icon-btn {
  border: none;
  background: white;
  border-radius: 999px;
  width: 44px;
  height: 44px;
  box-shadow: var(--card-shadow);
  font-size: 20px;
  cursor: pointer;
}

.icon-btn-off {
  background: #ffe3e0;
  color: #b42318;
  box-shadow: 0 0 0 2px rgba(180, 35, 24, 0.22), var(--card-shadow);
}

.headline {
  font-size: 26px;
  margin: 6px 0 18px;
  text-align: center;
}

.screen {
  display: none;
  flex: 1;
}

.screen-active {
  display: block;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
}

.card-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-choice-label {
  font-size: 17px;
  text-align: center;
  color: var(--ink);
  margin-top: 6px;
}
.card {
  position: relative;
  border-radius: var(--radius-xl);
  padding: 18px;
  background: white;
  box-shadow: var(--card-shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 140px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-image {
  padding: 0;
  overflow: hidden;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.card-square {
  aspect-ratio: 1 / 1;
  min-height: unset;
}

.card:active {
  transform: scale(0.97);
}

.card-loader {
  position: absolute;
  width: 38px;
  height: 38px;
  border: 4px solid rgba(31, 27, 22, 0.2);
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.choice-index {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: #fff;
  color: #111;
  font-size: 17px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.ending-choice-card {
  background: #fff;
  padding: 0;
}

.ending-choice-image {
  width: 78%;
  height: 78%;
  object-fit: contain;
}


.card-shape {
  position: absolute;
  inset: 14px;
  border-radius: 22px;
  opacity: 0.25;
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.play-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.hero-card {
  width: min(320px, 80vw);
  height: min(320px, 80vw);
  border-radius: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  box-shadow: var(--card-shadow);
  position: relative;
}

.progress {
  width: min(420px, 85vw);
  height: 12px;
  background: rgba(31, 27, 22, 0.1);
  border-radius: 999px;
  overflow: hidden;
}

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

.controls {
  display: flex;
  gap: 12px;
}

.story-text {
  width: min(720px, 90vw);
  max-height: 220px;
  overflow: auto;
  background: rgba(255, 255, 255, 0.8);
  padding: 14px 16px;
  border-radius: 16px;
  box-shadow: var(--card-shadow);
  font-size: 16px;
  line-height: 1.4;
  color: var(--ink);
}

.next-btn {
  margin-top: 16px;
  padding: 16px 28px;
  border-radius: 999px;
  border: none;
  background: #ffffff;
  color: #1f1b16;
  font-size: 18px;
  font-weight: 700;
  box-shadow: var(--card-shadow);
}

.next-row {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}

.history-strip {
  width: min(900px, 92vw);
  margin-top: 18px;
}

.history-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 18px;
}

.history-end-label {
  grid-column: 1 / -1;
  margin-top: 10px;
  text-align: center;
  font-size: 30px;
  font-weight: 700;
  color: var(--ink);
}

.history-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
}

.history-item {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  border: none;
  padding: 0;
  display: block;
  line-height: 0;
  background-color: #fff;
  background-size: cover;
  background-position: center;
  box-shadow: var(--card-shadow);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.history-hidden {
  display: none;
}

.history-caption.root {
  font-size: 14px;
  font-weight: 700;
}

.choice-visited {
  outline: 3px solid #f6c84c;
  outline-offset: 2px;
}
.history-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 6px 8px 8px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--ink);
  text-align: center;
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
}

.current-caption {
  margin-top: 10px;
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  color: var(--ink);
}

.hidden {
  display: none;
}

.next-btn-idle {
  background: #ffffff;
}

.next-btn-ready {
  background: var(--accent);
}

.pill-btn {
  border: none;
  background: white;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 18px;
  box-shadow: var(--card-shadow);
}

.pill-btn-loading {
  position: relative;
  color: transparent;
  pointer-events: none;
  opacity: 0.75;
}

.pill-btn-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(31, 27, 22, 0.2);
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.ghost-btn {
  margin: 22px auto 0;
  display: block;
  padding: 14px 22px;
  border-radius: 999px;
  border: 2px dashed var(--accent);
  background: transparent;
  font-size: 18px;
  color: var(--ink);
}

.choices-error {
  text-align: center;
  color: #a63b2b;
  font-size: 14px;
  margin-top: 8px;
}

.choice-back-btn {
  display: inline-flex;
  margin: 0;
}

.choice-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 22px;
  flex-wrap: wrap;
}

.choice-read-btn {
  display: inline-flex;
  margin: 0;
}

.choice-read-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.voices {
  display: none;
}

.voices-card {
  background: white;
  padding: 20px;
  border-radius: 20px;
  box-shadow: var(--card-shadow);
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.voices-status {
  font-size: 16px;
  color: var(--muted);
}

.voices-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.voice-item {
  border: 2px solid rgba(31, 27, 22, 0.08);
  border-radius: 16px;
  padding: 12px;
  background: #fff8f1;
  font-size: 15px;
}

@media (min-width: 780px) {
  .headline {
    font-size: 30px;
  }

  .card {
    min-height: 170px;
  }

  .card-emoji {
    font-size: 64px;
  }
}
