/* Mythwright — candlelit dark-fantasy theme. Semantic tokens, mobile-first. */
:root {
  --ink: #0e0c14;
  --ink-2: #15121d;
  --surface: #1c1825;
  --surface-2: #241f30;
  --surface-3: #2e2840;
  --border: #3a3350;
  --border-soft: #2a2538;

  --fg: #ede6d8;          /* parchment */
  --fg-muted: #a99fb5;
  --fg-dim: #766d85;

  --accent: #e0a44a;      /* candle gold */
  --accent-2: #c07a2e;
  --accent-soft: rgba(224, 164, 74, 0.14);

  --magic: #9a7ad6;       /* arcane violet */
  --good: #6fae6f;
  --bad: #d4604f;
  --crit: #f0c95a;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 220ms;

  --maxw: 760px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "EB Garamond", Georgia, serif;
  font-size: 18px;
  color: var(--fg);
  background:
    radial-gradient(1200px 600px at 50% -10%, #241b33 0%, transparent 60%),
    radial-gradient(900px 500px at 90% 110%, #1a2330 0%, transparent 55%),
    var(--ink);
  -webkit-font-smoothing: antialiased;
}
#app { min-height: 100%; min-height: 100dvh; display: flex; flex-direction: column; }
#screen { flex: 1; display: flex; flex-direction: column; }

h1, h2, h3, .display { font-family: "Cinzel", serif; letter-spacing: 0.02em; }
.muted { color: var(--fg-muted); }
.dim { color: var(--fg-dim); }
a { color: var(--accent); }

/* ---- buttons & inputs ---- */
.btn {
  font-family: "Cinzel", serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border: 1px solid var(--accent-2);
  border-radius: var(--radius-sm);
  padding: 13px 20px;
  cursor: pointer;
  transition: transform var(--dur) var(--ease), filter var(--dur) var(--ease), opacity var(--dur);
  box-shadow: 0 2px 0 rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.25);
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.3); }
.btn.ghost {
  background: var(--surface-2); color: var(--fg);
  border: 1px solid var(--border); box-shadow: none;
}
.btn.ghost:hover { background: var(--surface-3); }
.btn.full { width: 100%; }
.btn.sm { padding: 8px 14px; font-size: 14px; }

input, textarea, select {
  font-family: "EB Garamond", serif;
  font-size: 17px;
  color: var(--fg);
  background: var(--ink-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  width: 100%;
  outline: none;
  transition: border-color var(--dur);
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 64px; line-height: 1.4; }
label.field { display: block; margin: 14px 0 6px; font-size: 14px; color: var(--fg-muted); font-family: "Cinzel", serif; }

/* ---- generic layout ---- */
.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 22px; }
.center-screen { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.row { display: flex; gap: 10px; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grid { display: grid; gap: 12px; }
.hidden { display: none !important; }

/* ---- home ---- */
.brand { text-align: center; margin-bottom: 6px; }
.brand .logo { font-size: 13vw; line-height: 1; }
.brand h1 { font-size: 40px; margin: 6px 0 2px; color: var(--accent); text-shadow: 0 2px 20px rgba(224,164,74,0.25); }
.brand .tag { font-style: italic; color: var(--fg-muted); font-size: 19px; }
.gm-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: "Cinzel", serif; font-size: 12px; letter-spacing: 0.05em;
  padding: 5px 12px; border-radius: 999px; margin-top: 12px;
  border: 1px solid var(--border);
}
.gm-badge.live { color: var(--good); border-color: rgba(111,174,111,0.4); background: rgba(111,174,111,0.08); }
.gm-badge.demo { color: var(--accent); border-color: rgba(224,164,74,0.4); background: var(--accent-soft); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--fg-dim); font-family: "Cinzel"; font-size: 13px; margin: 4px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border-soft); }

/* ---- choice cards (adventures & classes) ---- */
.choices { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 560px) { .choices.two { grid-template-columns: 1fr 1fr; } }
.choice {
  text-align: left; cursor: pointer;
  background: var(--surface); border: 1.5px solid var(--border-soft);
  border-radius: var(--radius); padding: 16px;
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease), background var(--dur);
}
.choice:hover { border-color: var(--accent-2); transform: translateY(-2px); }
.choice.selected { border-color: var(--accent); background: var(--accent-soft); }
.choice .ttl { font-family: "Cinzel"; font-weight: 600; font-size: 19px; display: flex; align-items: center; gap: 8px; }
.choice .sub { color: var(--fg-muted); font-size: 16px; margin-top: 4px; line-height: 1.35; }
.choice .stats { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.pill {
  font-family: "Cinzel"; font-size: 11px; letter-spacing: 0.03em;
  padding: 3px 9px; border-radius: 999px;
  background: var(--surface-3); color: var(--fg-muted); border: 1px solid var(--border-soft);
}

/* ---- lobby ---- */
.codebox { text-align: center; }
.code {
  font-family: "Cinzel"; font-weight: 700; font-size: 46px; letter-spacing: 0.18em;
  color: var(--accent); padding: 6px 0;
}
.roster { display: grid; gap: 8px; }
.roster .member {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 10px 12px;
}
.roster .member .av { font-size: 24px; }
.roster .member .who { font-family: "Cinzel"; font-weight: 600; }
.roster .member.pending { opacity: 0.7; font-style: italic; }
.tag-host { color: var(--accent); font-size: 12px; font-family: "Cinzel"; }
.offline { color: var(--fg-dim); }

/* ---- game table ---- */
/* 100vh first as a fallback, then 100dvh so it wins on mobile and tracks the
   keyboard/dynamic toolbar (paired with interactive-widget=resizes-content). */
.table { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  padding: 9px 14px; background: rgba(20,17,28,0.92);
  border-bottom: 1px solid var(--border-soft); backdrop-filter: blur(8px);
  padding-top: max(9px, env(safe-area-inset-top));
}
.topbar > .scene-box { min-width: 0; flex: 1; }
.topbar .scene-name { font-family: "Cinzel"; font-weight: 600; font-size: 15px; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .scene-sub { font-size: 13px; color: var(--fg-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--fg);
  border-radius: 10px; padding: 7px 10px; cursor: pointer; font-size: 16px;
}
.iconbtn:active { transform: scale(0.95); }
.hp-pill {
  font-family: "Cinzel"; font-size: 13px; padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--border); white-space: nowrap;
}

/* party strip */
.party-strip { display: flex; gap: 8px; overflow-x: auto; padding: 8px 14px; background: var(--ink-2); border-bottom: 1px solid var(--border-soft); }
.party-strip::-webkit-scrollbar { height: 0; }
.mini {
  flex: 0 0 auto; min-width: 96px; background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: 10px; padding: 7px 9px;
}
.mini.you { border-color: var(--accent-2); }
.mini.downed { border-color: var(--bad); opacity: 0.8; }
.mini .nm { font-family: "Cinzel"; font-size: 12px; font-weight: 600; display: flex; gap: 4px; align-items: center; }
.mini .nm .off { color: var(--fg-dim); font-size: 10px; }
.hpbar { height: 6px; border-radius: 4px; background: var(--surface-3); margin-top: 5px; overflow: hidden; }
.hpbar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--good), #9ece6a); transition: width var(--dur) var(--ease); }
.hpbar.low > span { background: linear-gradient(90deg, var(--bad), #e0825a); }
.mini .hptext { font-size: 11px; color: var(--fg-muted); margin-top: 3px; }

/* story feed */
.feed { flex: 1; overflow-y: auto; padding: 16px 14px 20px; scroll-behavior: smooth; }
.feed .beat { margin: 0 auto 16px; max-width: 640px; animation: rise var(--dur) var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.narration {
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border-soft); border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 14px 16px; line-height: 1.5; font-size: 18px;
}
.narration .gm-tag { font-family: "Cinzel"; font-size: 11px; letter-spacing: 0.08em; color: var(--accent); text-transform: uppercase; display: block; margin-bottom: 6px; }
.narration.demo { border-left-color: var(--fg-dim); }

.action-beat { font-style: italic; color: var(--fg-muted); text-align: center; font-size: 16px; }
.action-beat b { color: var(--fg); font-style: normal; }

.scene-beat { text-align: center; margin: 22px auto; }
.scene-beat .ln { font-family: "Cinzel"; color: var(--accent); letter-spacing: 0.08em; font-size: 15px; }
.scene-beat .ln::before, .scene-beat .ln::after { content: "✦"; margin: 0 10px; color: var(--accent-2); }
.scene-beat .desc { color: var(--fg-muted); font-style: italic; font-size: 15px; margin-top: 4px; }

.sys-beat { text-align: center; color: var(--fg-dim); font-size: 14px; font-family: "Cinzel"; }
.levelup-beat { text-align: center; color: var(--crit); font-family: "Cinzel"; font-weight: 600; font-size: 16px; text-shadow: 0 0 14px rgba(240,201,90,0.4); }

.chat-beat { font-size: 16px; }
.chat-beat .nm { color: var(--magic); font-family: "Cinzel"; font-size: 13px; }

/* dice roll chip */
.roll-beat { display: flex; justify-content: center; }
.roll {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 7px 14px; font-size: 15px;
}
.roll .die { font-size: 20px; animation: tumble 600ms var(--ease); }
@keyframes tumble { 0% { transform: rotate(-60deg) scale(0.5); opacity: 0; } 60% { transform: rotate(20deg) scale(1.15); } 100% { transform: none; opacity: 1; } }
.roll .who { font-family: "Cinzel"; font-size: 13px; color: var(--fg-muted); }
.roll .val { font-family: "Cinzel"; font-weight: 700; font-size: 17px; }
.roll .res { font-family: "Cinzel"; font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.roll .res.success { color: var(--good); background: rgba(111,174,111,0.12); }
.roll .res.failure { color: var(--bad); background: rgba(212,96,79,0.12); }
.roll.crit-hit { border-color: var(--crit); box-shadow: 0 0 16px rgba(240,201,90,0.25); }
.roll.crit-miss { border-color: var(--bad); }

/* composer */
.composer {
  border-top: 1px solid var(--border-soft); background: rgba(20,17,28,0.96);
  padding: 10px 14px; padding-bottom: max(10px, env(safe-area-inset-bottom));
  backdrop-filter: blur(8px);
}
.tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tab {
  font-family: "Cinzel"; font-size: 13px; padding: 6px 14px; border-radius: 999px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border-soft); color: var(--fg-muted);
}
.tab.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-2); }
.composer .send-row { display: flex; gap: 8px; align-items: flex-end; }
.composer .send-row textarea { flex: 1; min-height: 46px; max-height: 120px; }
.status-line { font-size: 13px; color: var(--fg-muted); margin: 8px 2px 2px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
#statusText { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ready-chip { color: var(--good); }
.reacts { display: flex; gap: 2px; flex: 0 0 auto; }
.reacts button { background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer; padding: 4px; opacity: 0.85; min-width: 34px; min-height: 34px; }
.reacts button:hover { opacity: 1; transform: scale(1.15); }
#resolveBtn { margin-top: 8px; }

/* gm thinking */
.gm-thinking {
  text-align: center; padding: 12px; color: var(--accent); font-family: "Cinzel"; font-size: 15px;
}
.gm-thinking .orbs { display: inline-flex; gap: 5px; margin-left: 6px; }
.gm-thinking .orbs i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); display: inline-block; animation: pulse 1.1s var(--ease) infinite; }
.gm-thinking .orbs i:nth-child(2) { animation-delay: 0.18s; }
.gm-thinking .orbs i:nth-child(3) { animation-delay: 0.36s; }
@keyframes pulse { 0%,100% { opacity: 0.3; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.1); } }

/* drawers */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 40; animation: fade var(--dur); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 92vw); z-index: 41;
  background: var(--ink-2); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  padding: 18px; overflow-y: auto; animation: slidein var(--dur) var(--ease);
  padding-top: max(18px, env(safe-area-inset-top));
}
@keyframes slidein { from { transform: translateX(100%); } to { transform: none; } }
.drawer h2 { color: var(--accent); margin-top: 0; }
.sheet-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.sheet-stat { background: var(--surface); border: 1px solid var(--border-soft); border-radius: 10px; padding: 8px; text-align: center; }
.sheet-stat .k { font-family: "Cinzel"; font-size: 12px; color: var(--fg-dim); }
.sheet-stat .v { font-family: "Cinzel"; font-size: 22px; font-weight: 700; }
.sheet-stat .m { font-size: 12px; color: var(--accent); }
.ability { background: var(--surface); border: 1px solid var(--border-soft); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.ability .an { font-family: "Cinzel"; font-weight: 600; color: var(--accent); }
.ability .ad { font-size: 15px; color: var(--fg-muted); }
.inv-list { display: flex; flex-wrap: wrap; gap: 6px; }
.cond { color: var(--bad); font-size: 13px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--surface-3); color: var(--fg); border: 1px solid var(--border);
  padding: 11px 18px; border-radius: 999px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity var(--dur), transform var(--dur) var(--ease);
  z-index: 60; font-size: 15px; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* modal */
[hidden] { display: none !important; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 70; padding: 18px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; max-width: 540px; max-height: 86vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal h2 { color: var(--accent); margin-top: 0; }
.modal ol { padding-left: 20px; line-height: 1.5; }
.modal li { margin-bottom: 8px; }

/* reactions */
#reactions { position: fixed; inset: 0; pointer-events: none; z-index: 55; overflow: hidden; }
.react-float { position: absolute; font-size: 30px; animation: floatup 2.2s var(--ease) forwards; }
@keyframes floatup { 0% { opacity: 0; transform: translateY(0) scale(0.6); } 15% { opacity: 1; } 100% { opacity: 0; transform: translateY(-180px) scale(1.3); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
