/**
 * THE DESCENT — Stylesheet
 * Dark, atmospheric, Georgia-based typography matching the novel's voice.
 *
 * Layout: mobile-first single-column. At ≥768px, switches to a two-column
 * grid with the sidebar always visible. On phone, the sidebar is a slide-in
 * drawer toggled from the status bar.
 */

/* ─── RESET & BASE ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0a;
  --bg-panel: #111;
  --bg-input: #151515;
  --text: #c8c0b0;
  --text-dim: #7a7468;
  --text-bright: #e8e0d0;
  --accent-gold: #c9a84c;
  --accent-red: #aa4444;
  --accent-green: #5a8a5a;
  --accent-blue: #4a6a8a;
  --accent-purple: #7a5a8a;
  --border: #2a2622;
  --border-light: #3a3632;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 16px;             /* iOS: input field font ≥16px to suppress focus zoom */
  line-height: 1.65;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

/* ─── MOBILE-FIRST CONTAINER ─── */
.game-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;              /* dynamic viewport — accounts for mobile browser chrome */
  max-width: 1100px;
  margin: 0 auto;
  position: relative;
}

/* ─── HEADER ─── */
.game-header {
  flex: 0 0 auto;
  padding: 10px 16px 8px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}
.brand-eyebrow {
  font-family: Georgia, serif;
  font-size: 9px;
  letter-spacing: 6px;
  color: var(--text-dim);
  margin-bottom: 4px;
  text-transform: uppercase;
}
.brand-eyebrow a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: 1px;
  transition: all 0.2s ease;
}
.brand-eyebrow a:hover {
  color: var(--accent-gold);
  border-bottom-color: var(--accent-gold);
}
.game-title {
  font-size: 14px;
  letter-spacing: 3px;
  color: var(--text-dim);
  font-weight: normal;
  text-transform: uppercase;
}

/* ─── PAGE VIGNETTE ─── subtle radial darkening at the edges to focus
   the reader on the centre column. Pointer-events: none so it never
   blocks the UI underneath. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.35) 100%);
  pointer-events: none;
  z-index: 1;
}
.game-container { position: relative; z-index: 2; }

/* ─── STATUS BAR ─── */
#status-bar {
  flex: 0 0 auto;
  padding: 6px 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

#status-info {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
#status-info::-webkit-scrollbar { display: none; }

.status-room { color: var(--text-bright); font-weight: bold; flex-shrink: 0; }
.status-sep { color: #2a2622; margin: 0 4px; flex-shrink: 0; }
.status-timer { color: var(--accent-red); font-weight: bold; flex-shrink: 0; }
.status-shards { color: var(--accent-gold); flex-shrink: 0; }
.status-identity { color: var(--accent-purple); font-style: italic; flex-shrink: 0; }
.status-turns, .status-frags { flex-shrink: 0; }

.status-controls {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

.status-btn {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-dim);
  font-family: Georgia, serif;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.5px;
  min-height: 32px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.status-btn:hover { color: var(--text-bright); border-color: var(--accent-gold); }
.status-btn:active { background: #1a1816; }
.status-btn:disabled { opacity: 0.35; cursor: default; }
.status-btn:disabled:hover { color: var(--text-dim); border-color: var(--border-light); }

.status-btn-icon { font-size: 16px; min-width: 32px; padding: 4px 8px; }

/* Save-pulse — small dot + transient "saved" label that briefly glow gold
   each time auto-save fires. Default state is dim and quiet; the .firing
   class triggers a 1.4s gold pulse. */
.save-pulse {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 0 2px;
  flex-shrink: 0;
  font-family: Georgia, serif;
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--text-dim);
}
.save-pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #2a2622;
  transition: background 0.4s ease, box-shadow 0.4s ease;
}
.save-pulse-label {
  opacity: 0;
  transition: opacity 0.4s ease;
  white-space: nowrap;
}
.save-pulse.firing .save-pulse-dot {
  background: var(--accent-gold);
  box-shadow: 0 0 8px var(--accent-gold);
  animation: saveDotPulse 1.4s ease;
}
.save-pulse.firing .save-pulse-label {
  opacity: 1;
  color: var(--accent-gold);
  animation: saveLabelPulse 1.4s ease;
}
@keyframes saveDotPulse {
  0%   { background: #2a2622; box-shadow: none; }
  20%  { background: var(--accent-gold); box-shadow: 0 0 10px var(--accent-gold); }
  100% { background: #2a2622; box-shadow: none; }
}
@keyframes saveLabelPulse {
  0%   { opacity: 0; }
  20%  { opacity: 1; }
  80%  { opacity: 0.6; }
  100% { opacity: 0; }
}
/* On narrow screens the label hides — only the dot is visible */
@media (max-width: 540px) {
  .save-pulse-label { display: none; }
}

/* Audio-button state: gold tint when ambient sound is on */
#audio-btn[data-muted="false"] {
  color: var(--accent-gold);
  border-color: var(--accent-gold);
}

/* On narrow screens, hide button labels so the controls fit */
@media (max-width: 540px) {
  .status-btn .btn-label { display: none; }
  .status-btn { font-size: 16px; min-width: 32px; padding: 4px 8px; }
}

/* ─── OUTPUT ─── */
#output {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  scroll-behavior: smooth;
  min-height: 0;               /* allow flex shrinking */
}

.output-block {
  margin-bottom: 14px;
  animation: fadeIn 0.3s ease;
}

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

.output-block a {
  color: var(--accent-blue);
  text-decoration: underline;
  text-decoration-color: var(--border-light);
  text-underline-offset: 3px;
  font-weight: bold;
}
.output-block a:hover {
  color: var(--text-bright);
  text-decoration-color: var(--accent-blue);
}

.output-narration { color: var(--text); }
.output-system { color: var(--text-dim); font-size: 14px; font-style: italic; }
.output-input { color: var(--accent-blue); font-style: italic; font-size: 14px; margin-bottom: 6px; }
.output-prophecy {
  color: var(--accent-gold);
  border-left: 2px solid var(--accent-gold);
  padding-left: 16px;
  margin: 12px 0;
  font-style: italic;
}
.output-identity {
  color: var(--accent-purple);
  text-align: center;
  letter-spacing: 2px;
  font-size: 13px;
  margin: 12px 0;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.output-death {
  color: var(--accent-red);
  border-left: 2px solid var(--accent-red);
  padding-left: 16px;
  margin: 12px 0;
}

/* ─── SIDEBAR (mobile drawer, desktop sidebar) ─── */
.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 260px;
  max-width: 84vw;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  padding: 50px 16px 16px;     /* room for the close button */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 18px;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 20;
  box-shadow: -4px 0 24px rgba(0,0,0,0.5);
}
.sidebar.open { transform: translateX(0); }

.sidebar-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-dim);
  font-family: Georgia, serif;
  font-size: 18px;
  width: 32px;
  height: 32px;
  border-radius: 3px;
  cursor: pointer;
  line-height: 1;
}
.sidebar-close:hover { color: var(--text-bright); border-color: var(--accent-gold); }

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 15;
}
.sidebar-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.panel-header {
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.panel-empty {
  font-size: 13px;
  color: #3a3632;
  font-style: italic;
}

.inv-item {
  font-size: 14px;
  color: var(--text);
  padding: 4px 0;
  cursor: default;
}
.inv-item:hover { color: var(--text-bright); }

.frag-slot {
  display: inline-block;
  width: 30px;
  height: 24px;
  line-height: 24px;
  text-align: center;
  font-size: 10px;
  margin: 1px;
  border-radius: 3px;
}
.frag-empty { background: #1a1816; color: #2a2622; border: 1px solid #222; }
.frag-found { background: #1a1810; color: var(--accent-gold); border: 1px solid #3a3020; }

.catch-slot {
  display: block;
  padding: 4px 8px;
  margin: 2px 0;
  font-size: 11px;
  border-radius: 3px;
  font-style: italic;
}
.catch-empty { background: #1a1816; color: #2a2622; border: 1px solid #222; }
.catch-found { background: #1a1810; color: var(--accent-gold); border: 1px solid #3a3020; }

/* ─── CHOICES ─── */
#choices {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  max-height: 38vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.choice-btn {
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  color: var(--text);
  font-family: Georgia, serif;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 40px;
  flex: 0 1 auto;
  text-align: left;
  line-height: 1.35;
}
.choice-btn:hover {
  background: #1a1816;
  border-color: var(--accent-gold);
  color: var(--text-bright);
}
.choice-btn:active { background: #222; }
.choice-disabled { opacity: 0.4; cursor: default; }
.choice-disabled:hover {
  background: var(--bg-input);
  border-color: var(--border-light);
  color: var(--text);
}

/* On phones, choices stack to full width — much easier to tap */
@media (max-width: 540px) {
  .choice-btn {
    flex: 1 1 100%;
    text-align: center;
  }
}

/* ─── TEXT INPUT ─── */
#input-container {
  flex: 0 0 auto;
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  padding-bottom: env(safe-area-inset-bottom);   /* iPhone home indicator */
}

#input-form {
  display: flex;
  flex: 1;
  padding: 10px 12px;
  align-items: center;
  gap: 8px;
}

.input-prompt {
  color: var(--accent-blue);
  font-family: Georgia, serif;
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}

#text-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-bright);
  font-family: Georgia, serif;
  font-size: 16px;             /* keeps iOS from zooming on focus */
  padding: 10px 12px;
  border-radius: 4px;
  outline: none;
  min-height: 40px;
}
#text-input:focus { border-color: var(--border-light); }
#text-input::placeholder { color: #3a3632; font-style: italic; }

/* ─── RESTART (game over) ─── */
#restart-btn {
  display: none;
  flex: 0 0 auto;
  background: none;
  border: 1px solid var(--accent-red);
  color: var(--accent-red);
  font-family: Georgia, serif;
  font-size: 14px;
  padding: 14px 20px;
  margin: 12px 16px;
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  min-height: 44px;
}
#restart-btn:hover { background: #1a1010; }

/* ─── SCROLLBAR ─── */
#output::-webkit-scrollbar, #choices::-webkit-scrollbar, .sidebar::-webkit-scrollbar { width: 6px; }
#output::-webkit-scrollbar-track, #choices::-webkit-scrollbar-track, .sidebar::-webkit-scrollbar-track { background: var(--bg); }
#output::-webkit-scrollbar-thumb, #choices::-webkit-scrollbar-thumb, .sidebar::-webkit-scrollbar-thumb { background: #2a2622; border-radius: 3px; }
#output::-webkit-scrollbar-thumb:hover { background: #3a3632; }

/* ─── DESKTOP / WIDE LAYOUT (≥768px) ─── */
@media (min-width: 768px) {
  html, body { font-size: 15px; }

  .game-container {
    display: grid;
    grid-template-columns: 1fr 240px;
    grid-template-rows: auto auto 1fr auto auto;
  }

  .game-header   { grid-column: 1 / -1; padding: 14px 20px 10px; }
  .game-title    { font-size: 16px; letter-spacing: 4px; }
  .brand-eyebrow { font-size: 10px; letter-spacing: 8px; margin-bottom: 5px; }
  #status-bar    { grid-column: 1 / -1; }
  #output        { grid-column: 1; grid-row: 3; padding: 20px; }

  .sidebar {
    position: static;
    grid-column: 2;
    grid-row: 3;
    transform: none;
    box-shadow: none;
    width: auto;
    max-width: none;
    padding: 14px;
    z-index: auto;
  }
  .sidebar-close   { display: none; }
  .sidebar-overlay { display: none; }

  /* Hide the drawer toggle on desktop — sidebar is always visible */
  #sidebar-toggle { display: none; }

  #choices         { grid-column: 1; grid-row: 4; padding: 8px 20px; max-height: none; }
  #input-container { grid-column: 1 / -1; grid-row: 5; }

  .choice-btn { font-size: 13px; padding: 6px 14px; min-height: 32px; flex: 0 1 auto; text-align: left; }
  .inv-item   { font-size: 12px; padding: 3px 0; }
  .frag-slot  { width: 28px; height: 22px; line-height: 22px; font-size: 9px; }
  .panel-empty{ font-size: 12px; }
}

/* ─── FRAGMENT VIEWER MODAL ─── */
.prophecy-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.prophecy-modal.open {
  display: flex;
  animation: modalFade 0.25s ease;
}

@keyframes modalFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.prophecy-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.prophecy-modal-content {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-left: 3px solid var(--accent-gold);
  border-radius: 4px;
  padding: 28px 32px 22px;
  max-width: 600px;
  width: 100%;
  max-height: 86vh;
  max-height: 86dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  animation: modalLift 0.25s ease;
  font-family: Georgia, 'Times New Roman', serif;
}

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

.prophecy-modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-dim);
  border-radius: 3px;
  cursor: pointer;
  font-family: Georgia, serif;
  font-size: 18px;
  line-height: 1;
}
.prophecy-modal-close:hover { color: var(--text-bright); border-color: var(--accent-gold); }

.prophecy-modal-header {
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
.prophecy-modal-id {
  color: var(--accent-gold);
  font-size: 13px;
  letter-spacing: 3px;
  font-weight: bold;
}
.prophecy-modal-title {
  color: var(--text-bright);
  font-size: 15px;
  font-style: italic;
}

.prophecy-modal-text {
  color: var(--accent-gold);
  font-size: 15px;
  font-style: italic;
  line-height: 1.7;
  white-space: pre-wrap;
  padding: 8px 0 16px;
}

.prophecy-modal-footer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.prophecy-modal-foundin { font-style: italic; }
.prophecy-modal-hint { letter-spacing: 1px; }

/* P-slots are clickable when found */
.frag-found {
  cursor: pointer;
  transition: all 0.15s;
}
.frag-found:hover {
  background: #2a2412;
  border-color: var(--accent-gold);
  color: var(--text-bright);
  transform: scale(1.08);
}

/* ─── TUTORIAL / WELCOME MODAL ─── */
.tutorial-modal {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.tutorial-modal.open {
  display: flex;
  animation: modalFade 0.3s ease;
}
.tutorial-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.tutorial-modal-content {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-left: 3px solid var(--accent-blue);
  border-radius: 4px;
  padding: 28px 32px 22px;
  max-width: 640px;
  width: 100%;
  max-height: 88vh;
  max-height: 88dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.7);
  animation: modalLift 0.3s ease;
  font-family: Georgia, 'Times New Roman', serif;
}
.tutorial-modal-header {
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
.tutorial-modal-id {
  color: var(--accent-blue);
  font-size: 12px;
  letter-spacing: 3px;
  font-weight: bold;
  text-transform: uppercase;
}
.tutorial-modal-title {
  color: var(--text-bright);
  font-size: 18px;
  letter-spacing: 4px;
  text-transform: uppercase;
}
.tutorial-modal-body { color: var(--text); font-size: 15px; line-height: 1.7; }
.tutorial-modal-body p { margin-bottom: 12px; }
.tutorial-modal-body p:last-child { margin-bottom: 0; }
.tutorial-modal-body strong { color: var(--text-bright); font-weight: bold; }
.tutorial-modal-body em { color: var(--text-dim); }
.intro-section-label {
  color: var(--accent-blue);
  letter-spacing: 2px;
  font-size: 12px;
  text-transform: uppercase;
  margin-top: 16px !important;
  margin-bottom: 8px !important;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.tutorial-modal-body code {
  font-family: Consolas, 'Courier New', monospace;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--accent-gold);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 13px;
}
.tut-icons { display: block; margin-top: 6px; padding-left: 8px; font-size: 13px; line-height: 2.0; }
.tut-icon {
  display: inline-block;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  color: var(--accent-gold);
  padding: 2px 8px;
  border-radius: 3px;
  margin-right: 4px;
  font-size: 14px;
  min-width: 20px;
  text-align: center;
}
.tutorial-flavor { color: var(--text-dim); font-size: 13px; padding-top: 6px; border-top: 1px dashed var(--border); margin-top: 12px !important; }
.tutorial-modal-footer {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  text-align: center;
}
.tutorial-modal-btn {
  background: var(--bg-input);
  border: 1px solid var(--accent-blue);
  color: var(--accent-blue);
  font-family: Georgia, serif;
  font-size: 15px;
  padding: 12px 32px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 1px;
  min-height: 44px;
}
.tutorial-modal-btn:hover {
  background: #1a1820;
  border-color: var(--text-bright);
  color: var(--text-bright);
}

/* ─── LANDSCAPE PHONE — short height, compact header ─── */
@media (orientation: landscape) and (max-height: 500px) {
  .game-header { padding: 6px 16px; }
  .game-title  { font-size: 12px; letter-spacing: 2px; }
  #output      { padding: 12px 16px; }
  #choices     { max-height: 35vh; }
}
