/* ════════════════════════════════════════
   GRAVITY FALLS: SCATTERED PAGES
   Mobile-first · Dark forest · Hand-drawn
════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600&family=Courier+Prime:ital,wght@0,400;0,700;1,400&family=Caveat:wght@400;600&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --black:       #060c05;
  --forest:      #0a1208;
  --pine-dark:   #0f1a0d;
  --pine:        #1a2e18;
  --pine-mid:    #243d22;
  --pine-light:  #3a6035;
  --mist:        #8aab80;
  --fog:         #b8c8b0;
  --parchment:   #d4c9a8;
  --gold:        #b8922a;
  --gold-bright: #d4a830;
  --gold-dim:    #7a5e18;
  --amber:       #c07820;
  --red-warn:    #8b2020;
  --red-dim:     #5a1515;
  --bill-yellow: #e8c840;
  --ink:         #1c2818;
  --text-main:   #c8d8b8;
  --text-dim:    #6a8060;
  --text-faint:  #3a5030;
  --border:      rgba(90,130,70,0.2);
  --border-gold: rgba(180,146,42,0.3);
  --radius:      4px;

  /* Layout */
  --header-h:    52px;
  --input-h:     64px;
  --sidebar-w:   260px;
}

html {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: 'Courier Prime', monospace;
  background: var(--forest);
  color: var(--text-main);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ════════════════════════════════════════
   TITLE SCREEN
════════════════════════════════════════ */

.title-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: var(--black);
  overflow-y: auto;
}

/* Hero image — top portion, fades into dark at bottom */
.title-hero-img {
  width: 100%;
  padding-top: 56.25%;
  position: relative;
  flex-shrink: 0;
  background: url('../game-card.png') center top / cover no-repeat;
  mask-image: linear-gradient(to bottom, black 50%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, black 50%, transparent 100%);
}

/* Text panel — solid dark, full readability */
.title-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 1.5rem 1.5rem max(2rem, env(safe-area-inset-bottom));
  background: var(--black);
}

.title-super {
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  font-weight: 400;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--gold-dim);
  margin-bottom: 0.2rem;
}

.title-name {
  font-family: 'Cinzel', serif;
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  font-weight: 600;
  color: #f0e4c0;
  letter-spacing: 0.04em;
  line-height: 1.1;
  margin-bottom: 1rem;
  text-shadow: 0 0 40px rgba(180,140,50,0.3);
}

.title-tagline {
  font-family: 'Courier Prime', monospace;
  font-size: 0.88rem;
  color: #8aab80;
  line-height: 1.75;
  margin-bottom: 0.25rem;
}

.title-tagline em { color: #b0c498; font-style: italic; }

.title-divider {
  font-family: 'Courier Prime', monospace;
  font-size: 0.75rem;
  letter-spacing: 0.4em;
  color: rgba(180,146,42,0.4);
  margin: 1rem 0 1.2rem;
}

.title-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
}

.title-btn {
  display: block;
  width: 100%;
  max-width: 280px;
  padding: 0.9rem 2rem;
  font-family: 'Cinzel', serif;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.18s;
}

#start-btn {
  background: linear-gradient(180deg, #d4a830 0%, #b88820 100%);
  color: #0d1a0a;
  border: none;
  box-shadow: 0 2px 16px rgba(180,140,40,0.3);
}

#start-btn:hover {
  background: linear-gradient(180deg, #e8bc40 0%, #c89a28 100%);
  box-shadow: 0 4px 24px rgba(180,140,40,0.5);
  transform: translateY(-1px);
}

.title-btn-secondary {
  background: transparent;
  color: #6a8860;
  border: 1px solid rgba(90,130,70,0.35);
  font-size: 0.78rem;
}

.title-btn-secondary:hover {
  border-color: rgba(180,146,42,0.4);
  color: #a8c090;
}

.title-credit {
  margin-top: 1.5rem;
  font-family: 'Courier Prime', monospace;
  font-size: 0.62rem;
  color: #2e4228;
  letter-spacing: 0.06em;
  line-height: 1.6;
}

.title-credit-link { color: #3a5430; text-decoration: none; transition: color 0.15s; }
.title-credit-link:hover { color: #5a7848; }

/* Desktop — constrain to a centered card */
@media (min-width: 600px) {
  .title-screen {
    align-items: center;
    justify-content: center;
    background: #050a04;
  }
  .title-hero-img {
    width: 100%;
    max-width: 520px;
    padding-top: 0;
    height: 292px;
    border-radius: 8px 8px 0 0;
  }
  .title-content {
    width: 100%;
    max-width: 520px;
    border-radius: 0 0 8px 8px;
    border: 1px solid rgba(90,130,70,0.12);
    border-top: none;
    padding: 1.75rem 2rem 2rem;
  }
}


/* ════════════════════════════════════════
   MODAL
════════════════════════════════════════ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal.hidden { display: none; }

.modal-box {
  background: var(--pine-dark);
  border: 1px solid var(--border-gold);
  border-radius: 8px;
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
}

.modal-title {
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--parchment);
  margin-bottom: 0.5rem;
}

.modal-desc {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 1rem;
  line-height: 1.5;
}

.checkpoint-textarea {
  width: 100%;
  height: 160px;
  padding: 0.75rem;
  background: var(--black);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-main);
  font-family: 'Courier Prime', monospace;
  font-size: 0.72rem;
  resize: none;
  line-height: 1.5;
}

.checkpoint-textarea:focus { outline: none; border-color: var(--border-gold); }

.modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
  justify-content: flex-end;
}

.modal-btn-cancel,
.modal-btn-confirm {
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  font-family: 'Courier Prime', monospace;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
}

.modal-btn-cancel {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.modal-btn-confirm {
  background: var(--gold);
  border: none;
  color: var(--black);
  font-weight: 700;
}

.modal-btn-confirm:hover { background: var(--gold-bright); }

/* ════════════════════════════════════════
   GAME LAYOUT
════════════════════════════════════════ */

.game {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.game.hidden { display: none; }

/* ── Header ── */
.game-header {
  height: var(--header-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background: var(--pine-dark);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 50;
}

.game-title-small {
  font-family: 'Cinzel', serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gold-dim);
  letter-spacing: 0.06em;
}

.game-header-right {
  display: flex;
  gap: 4px;
  align-items: center;
}

.header-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: 'Courier Prime', monospace;
  font-size: 0.72rem;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.04em;
}

.header-btn:hover {
  border-color: var(--border);
  color: var(--parchment);
}

.header-btn-icon { font-size: 0.85rem; }

.header-btn-danger:hover {
  border-color: rgba(139,32,32,0.5);
  color: var(--red-warn);
}

/* ── Main layout ── */
.game-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ── Chat window ── */
.game-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1rem 0.5rem;
  scroll-behavior: smooth;
  /* Custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--pine-mid) transparent;
}

.chat-window::-webkit-scrollbar { width: 4px; }
.chat-window::-webkit-scrollbar-track { background: transparent; }
.chat-window::-webkit-scrollbar-thumb { background: var(--pine-mid); border-radius: 2px; }

/* ── Messages ── */
.message {
  margin-bottom: 1.5rem;
  animation: msgIn 0.25s ease;
}

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

/* Narrator (game) message */
.message-narrator .message-body {
  font-family: 'Courier Prime', monospace;
  font-size: 0.92rem;
  line-height: 1.8;
  color: var(--text-main);
  white-space: pre-wrap;
}

/* Strip checkpoint block from display */
.message-narrator .checkpoint-block {
  display: none;
}

/* Player message */
.message-player {
  display: flex;
  justify-content: flex-end;
}

.message-player .message-body {
  background: var(--pine);
  border: 1px solid var(--border);
  border-radius: 6px 6px 2px 6px;
  padding: 0.6rem 0.85rem;
  font-family: 'Courier Prime', monospace;
  font-size: 0.85rem;
  color: var(--fog);
  max-width: 80%;
  line-height: 1.5;
}

/* System message (opening scene, etc.) */
.message-system .message-body {
  font-family: 'Courier Prime', monospace;
  font-size: 0.88rem;
  color: var(--text-dim);
  font-style: italic;
  line-height: 1.7;
  border-left: 2px solid var(--border-gold);
  padding-left: 0.85rem;
  margin-left: 0.25rem;
}

/* Emphasis within narrator text */
.message-narrator .message-body em {
  color: var(--parchment);
  font-style: italic;
}

.message-narrator .message-body strong {
  color: var(--gold-dim);
  font-weight: 700;
}

/* Bill echo — visually distinct */
.message-echo .message-body {
  font-family: 'Courier Prime', monospace;
  font-size: 0.88rem;
  color: var(--bill-yellow);
  background: rgba(232,200,64,0.05);
  border: 1px solid rgba(232,200,64,0.15);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  text-align: center;
  letter-spacing: 0.08em;
  font-style: italic;
  animation: echoPulse 3s ease-in-out infinite;
}

@keyframes echoPulse {
  0%, 100% { opacity: 0.7; }
  50%       { opacity: 1; }
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 5px;
  padding: 0.75rem 1rem;
  align-items: center;
}

.typing-indicator.hidden { display: none; }

.typing-indicator span {
  width: 5px;
  height: 5px;
  background: var(--pine-light);
  border-radius: 50%;
  animation: typingDot 1.2s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

/* ── Input bar ── */
.input-bar {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 0.75rem 1rem max(0.75rem, env(safe-area-inset-bottom));
  background: var(--pine-dark);
  border-top: 1px solid var(--border);
}

.player-input {
  flex: 1;
  padding: 0.65rem 0.85rem;
  background: var(--black);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-main);
  font-family: 'Courier Prime', monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  resize: none;
  min-height: 42px;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.15s;
}

.player-input::placeholder { color: var(--text-faint); }
.player-input:focus { outline: none; border-color: var(--border-gold); }

.send-btn {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  background: var(--gold);
  border: none;
  border-radius: 6px;
  color: var(--black);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
}

.send-btn:hover  { background: var(--gold-bright); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { background: var(--pine-mid); color: var(--text-faint); cursor: not-allowed; }

/* ════════════════════════════════════════
   STATS SIDEBAR — MOBILE (drawer)
════════════════════════════════════════ */

.stats-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
}

.stats-backdrop.hidden { display: none; }

.stats-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--pine-dark);
  border-top: 1px solid var(--border-gold);
  border-radius: 12px 12px 0 0;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 70vh;
  overflow-y: auto;
}

.stats-panel.open {
  transform: translateY(0);
}

.stats-inner {
  padding: 1.25rem 1rem max(1.25rem, env(safe-area-inset-bottom));
}

/* Handle bar */
.stats-inner::before {
  content: '';
  display: block;
  width: 36px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 1.25rem;
}

.stats-section {
  margin-bottom: 1.1rem;
  padding-bottom: 1.1rem;
  border-bottom: 1px solid var(--border);
}

.stats-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.stats-label {
  font-family: 'Cinzel', serif;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold-dim);
  margin-bottom: 0.4rem;
}

.stats-value {
  font-family: 'Courier Prime', monospace;
  font-size: 0.82rem;
  color: var(--fog);
  line-height: 1.4;
}

.stats-sub {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.stats-value-num {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--parchment);
}

.stats-thread {
  font-style: italic;
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.5;
}

/* Stat bars */
.stat-bar-wrap {
  height: 5px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.35rem;
}

.stat-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.sanity-bar   { background: var(--pine-light); width: 85%; }
.exposure-bar { background: var(--red-warn);   width: 0%; }

/* Sanity color states */
.sanity-bar[data-level="warning"]  { background: var(--amber); }
.sanity-bar[data-level="critical"] { background: var(--red-warn); }

/* Bill echo color states */
.echo-value { color: var(--mist); }
.echo-value[data-level="whisper"]  { color: var(--gold-dim); }
.echo-value[data-level="present"]  { color: var(--amber); }
.echo-value[data-level="loud"]     { color: var(--red-warn); animation: echoPulse 2s ease-in-out infinite; }
.echo-value[data-level="screaming"]{ color: var(--bill-yellow); animation: echoPulse 0.8s ease-in-out infinite; }

/* Fragment pips */
.fragment-pips {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 0.4rem;
}

.pip {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid var(--text-faint);
  background: transparent;
  transition: all 0.3s;
}

.pip.found {
  background: var(--gold);
  border-color: var(--gold);
  box-shadow: 0 0 6px rgba(180,150,60,0.4);
}

.pip.decoded {
  background: var(--pine-light);
  border-color: var(--pine-light);
}

/* Trust list */
.trust-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.trust-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
}

.trust-name { color: var(--text-dim); }

.trust-level {
  font-size: 0.7rem;
  padding: 1px 7px;
  border-radius: 2px;
  background: rgba(255,255,255,0.04);
  color: var(--text-faint);
  border: 1px solid var(--border);
  transition: all 0.3s;
}

.trust-level[data-value="Acquaintance"] { color: var(--mist);      border-color: rgba(138,171,128,0.3); }
.trust-level[data-value="Trusted"]      { color: var(--gold-dim);  border-color: var(--border-gold); background: rgba(180,146,42,0.08); }
.trust-level[data-value="Confides"]     { color: var(--gold-bright); border-color: var(--gold); background: rgba(180,146,42,0.15); }

/* Inventory list */
.inventory-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.inventory-item {
  font-size: 0.78rem;
  color: var(--fog);
  padding-left: 10px;
  position: relative;
  line-height: 1.4;
}

.inventory-item::before {
  content: '—';
  position: absolute;
  left: 0;
  color: var(--text-faint);
}

.inventory-item.dim { color: var(--text-dim); }
.inventory-item.special { color: var(--bill-yellow); }

/* ════════════════════════════════════════
   TOAST
════════════════════════════════════════ */

.toast {
  position: fixed;
  bottom: max(5rem, calc(env(safe-area-inset-bottom) + 5rem));
  left: 50%;
  transform: translateX(-50%);
  background: var(--pine-mid);
  border: 1px solid var(--border-gold);
  color: var(--parchment);
  font-family: 'Courier Prime', monospace;
  font-size: 0.78rem;
  padding: 0.5rem 1.1rem;
  border-radius: 99px;
  letter-spacing: 0.04em;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 500;
}

.toast.show { opacity: 1; }
.toast.hidden { display: none; }

/* ════════════════════════════════════════
   DESKTOP — sidebar layout
════════════════════════════════════════ */

@media (min-width: 768px) {
  .game-layout {
    overflow: hidden;
  }

  /* Sidebar becomes fixed right column */
  .stats-panel {
    position: static;
    transform: none !important;
    width: var(--sidebar-w);
    flex-shrink: 0;
    border-top: none;
    border-left: 1px solid var(--border-gold);
    border-radius: 0;
    max-height: none;
    height: 100%;
    overflow-y: auto;
    /* Always visible on desktop */
    display: block !important;
  }

  .stats-inner::before { display: none; }

  .stats-inner {
    padding: 1.25rem 1rem;
  }

  .stats-backdrop { display: none !important; }

  /* Hide stats toggle button on desktop */
  #stats-toggle-btn { display: none; }

  /* Slightly larger chat text on desktop */
  .message-narrator .message-body {
    font-size: 0.95rem;
  }

  .chat-window {
    padding: 1.5rem 1.5rem 0.75rem;
  }
}

@media (min-width: 1024px) {
  :root { --sidebar-w: 280px; }

  .message-narrator .message-body { font-size: 1rem; }
}

/* ════════════════════════════════════════
   UTILITY
════════════════════════════════════════ */

.hidden { display: none !important; }

/* Accessible focus rings */
button:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--gold-dim);
  outline-offset: 2px;
}

/* Prevent iOS zoom on input focus */
@media (max-width: 767px) {
  input, textarea, select {
    font-size: 16px !important;
  }
}
