/* =====================================================================
   TwineJourney — styles.css
   A theme-driven design system. All colors/typography are CSS custom
   properties set at runtime by themes.js, so the entire interface
   re-skins itself instantly when a story's genre is detected.
   ===================================================================== */

:root {
  /* Sensible defaults; overwritten by the active theme. */
  --bg: #0c0d12;
  --bg-2: #14161f;
  --bg-grad: radial-gradient(1100px 700px at 50% -10%, #1a1d2b 0%, #0e1018 55%, #07080d 100%);
  --surface: rgba(22, 25, 36, 0.6);
  --surface-2: rgba(32, 36, 52, 0.7);
  --text: #e9ecf5;
  --text-dim: #9aa0b5;
  --accent: #8b9dff;
  --accent-2: #6ad6c7;
  --border: rgba(139, 157, 255, 0.26);
  --glow: rgba(139, 157, 255, 0.32);
  --font-display: 'Inter', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --body-size: 1.2rem;
  --body-leading: 1.8;
  --radius: 16px;
  --maxw: 760px;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --theme-fade: 700ms;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over our display rules below
   (id/class selectors otherwise out-specify the UA [hidden] rule). */
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  /* Smooth theme transitions on the root surfaces. */
  transition: background-color var(--theme-fade) var(--ease),
              color var(--theme-fade) var(--ease);
}

/* Background layers --------------------------------------------------- */
#ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--bg-grad);
  transition: background var(--theme-fade) var(--ease);
}
#vignette {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(120% 90% at 50% 30%, transparent 55%, rgba(0,0,0,0.55) 100%);
  mix-blend-mode: multiply;
}

/* App shell ----------------------------------------------------------- */
#app {
  position: relative;
  z-index: 2;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* Top bar ------------------------------------------------------------- */
#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px clamp(16px, 4vw, 40px);
  backdrop-filter: blur(10px) saturate(120%);
  background: linear-gradient(180deg, rgba(0,0,0,0.32), rgba(0,0,0,0));
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  font-family: var(--font-display);
  letter-spacing: 0.04em;
}
.brand-mark {
  color: var(--accent);
  font-size: 1.3rem;
  filter: drop-shadow(0 0 8px var(--glow));
  transition: color var(--theme-fade) var(--ease), transform 0.4s var(--ease);
}
.brand:hover .brand-mark { transform: rotate(180deg) scale(1.1); }
.brand-name { font-weight: 700; font-size: 1.05rem; }

.story-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  margin-left: 6px;
  min-width: 0;
}
.story-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 38vw;
}
.story-genre {
  font-size: 0.72rem;
  color: var(--accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.top-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.2s var(--ease), background 0.3s, border-color 0.3s, color 0.3s, opacity 0.2s;
}
.icon-btn:hover { transform: translateY(-2px); border-color: var(--accent); color: var(--accent); }
.icon-btn:active { transform: translateY(0) scale(0.96); }
.icon-btn:disabled { opacity: 0.35; cursor: default; transform: none; }

.theme-picker { position: relative; }
.theme-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  width: 230px;
  padding: 8px;
  background: var(--surface-2);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  z-index: 30;
  animation: pop 0.22s var(--ease);
}
.theme-menu-head {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  padding: 6px 10px 8px;
}
.theme-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  background: transparent;
  border: 0;
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.92rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.18s;
}
.theme-item:hover { background: var(--surface); }
.ti-glyph { width: 20px; text-align: center; color: var(--accent); }
.ti-label { flex: 1; }
.ti-check { opacity: 0; color: var(--accent); font-size: 0.7rem; }
.theme-item.active .ti-check { opacity: 1; }
.theme-item.active { background: var(--surface); }

/* Stage / screens ----------------------------------------------------- */
#stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: clamp(20px, 4vw, 48px);
}
.screen { width: 100%; max-width: var(--maxw); }

.screen-enter { animation: screenIn 0.5s var(--ease); }
.screen-leave { animation: screenOut 0.32s var(--ease) forwards; }
@keyframes screenIn { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes screenOut { to { opacity: 0; transform: translateY(-12px); } }

/* Landing ------------------------------------------------------------- */
#landing { padding-top: clamp(20px, 8vh, 90px); text-align: center; }
.hero-title {
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 6vw, 3.6rem);
  font-weight: 700;
  line-height: 1.05;
  margin: 0 0 18px;
  letter-spacing: -0.01em;
  background: linear-gradient(180deg, var(--text), var(--text-dim));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero-sub {
  font-size: clamp(1rem, 2.4vw, 1.18rem);
  color: var(--text-dim);
  max-width: 540px;
  margin: 0 auto 40px;
  line-height: 1.6;
}

.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: clamp(32px, 7vw, 64px);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.3s, background 0.3s, transform 0.3s var(--ease), box-shadow 0.3s;
  overflow: hidden;
}
.dropzone::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(400px 200px at 50% 0%, var(--glow), transparent 70%);
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none;
}
.dropzone:hover, .dropzone:focus-visible {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: 0 24px 60px rgba(0,0,0,0.4);
  outline: none;
}
.dropzone:hover::after, .dropzone:focus-visible::after { opacity: 0.6; }
.dropzone.drag {
  border-color: var(--accent);
  background: var(--surface-2);
  transform: scale(1.02);
}
.dz-icon {
  font-size: 2.4rem;
  color: var(--accent);
  filter: drop-shadow(0 0 14px var(--glow));
  animation: float 3s ease-in-out infinite;
}
.dz-title { font-family: var(--font-display); font-size: 1.2rem; font-weight: 600; }
.dz-sub { color: var(--text-dim); font-size: 0.92rem; }
.dz-sub code {
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 0.85em;
  color: var(--accent);
}

.landing-foot {
  margin-top: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.88rem;
  color: var(--text-dim);
}
.text-btn {
  background: none;
  border: 0;
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 0.92rem;
  cursor: pointer;
  padding: 4px 2px;
  transition: opacity 0.2s, letter-spacing 0.3s var(--ease);
}
.text-btn:hover { letter-spacing: 0.03em; }
.dot { opacity: 0.4; }
.muted { color: var(--text-dim); }

/* Reader -------------------------------------------------------------- */
#reader {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: clamp(12px, 4vh, 36px);
}
.passage {
  width: 100%;
  font-size: var(--body-size);
  line-height: var(--body-leading);
  color: var(--text);
  letter-spacing: 0.003em;
}
.passage p { margin: 0 0 1.1em; }
.passage p:first-letter {
  /* subtle drop-cap-ish emphasis is theme dependent; keep neutral */
}
.passage strong { color: var(--text); font-weight: 700; }
.passage em { color: var(--accent); font-style: italic; }

.passage.enter { animation: proseIn 0.55s var(--ease); }
.passage.leave { opacity: 0; transform: translateY(-8px); transition: opacity 0.18s, transform 0.18s; }
@keyframes proseIn {
  from { opacity: 0; transform: translateY(14px); filter: blur(3px); }
  to { opacity: 1; transform: none; filter: blur(0); }
}

/* Choices ------------------------------------------------------------- */
.choices {
  width: 100%;
  margin-top: 34px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.choice {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px 20px;
  text-align: left;
  font-family: var(--font-body);
  font-size: 1.04rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.25s var(--ease), border-color 0.3s, background 0.3s, box-shadow 0.3s;
  animation: choiceIn 0.5s var(--ease) backwards;
  animation-delay: calc(var(--i, 0) * 80ms + 120ms);
}
.choice::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
  transform: scaleY(0);
  transform-origin: bottom;
  transition: transform 0.3s var(--ease);
}
.choice::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--glow), transparent 60%);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.choice:hover {
  transform: translateX(6px);
  border-color: var(--accent);
  box-shadow: 0 12px 30px rgba(0,0,0,0.35);
}
.choice:hover::before { transform: scaleY(1); }
.choice:hover::after { opacity: 0.5; }
.choice:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.choice.chosen { transform: scale(0.97); border-color: var(--accent); background: var(--surface-2); }
.choice-arrow {
  color: var(--accent);
  font-size: 0.8rem;
  transition: transform 0.25s var(--ease);
  flex-shrink: 0;
}
.choice:hover .choice-arrow { transform: translateX(4px); }
.choice-label { flex: 1; }
@keyframes choiceIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.restart-choice { justify-content: center; }
.restart-choice .choice-arrow { display: none; }

/* Ending -------------------------------------------------------------- */
.ending {
  text-align: center;
  margin: 10px 0 22px;
  animation: proseIn 0.6s var(--ease);
}
.ending-mark {
  font-size: 2rem;
  color: var(--accent);
  filter: drop-shadow(0 0 12px var(--glow));
  animation: float 3s ease-in-out infinite;
}
.ending-text {
  font-family: var(--font-display);
  font-size: 1.4rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: 6px;
}

/* Reader footer / trail ----------------------------------------------- */
.reader-foot {
  width: 100%;
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.trail {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.trail-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  opacity: 0.4;
  transition: all 0.3s var(--ease);
}
.trail-dot.active {
  opacity: 1;
  background: var(--accent);
  box-shadow: 0 0 10px var(--glow);
  transform: scale(1.4);
}
.trail-count {
  margin-left: auto;
  font-size: 0.74rem;
  color: var(--text-dim);
  letter-spacing: 0.06em;
}

/* Toast --------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  z-index: 50;
  max-width: min(90vw, 460px);
  padding: 13px 20px;
  background: var(--surface-2);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 0.92rem;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0,0,0,0.5);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Keyframes ----------------------------------------------------------- */
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes pop { from { opacity: 0; transform: translateY(-8px) scale(0.97); } to { opacity: 1; transform: none; } }

/* Responsive ---------------------------------------------------------- */
@media (max-width: 600px) {
  .story-title { max-width: 30vw; }
  .story-genre { display: none; }
  #topbar { gap: 10px; padding: 12px 14px; }
  .icon-btn { width: 36px; height: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.08ms !important;
  }
}
