/* Torch & Tomb — carved stone, torchlight, old print. */

@font-face {
  font-family: "Cinzel";
  src: url("/static/fonts/cinzel.woff2") format("woff2");
  font-weight: 400 900;
  font-display: swap;
}
@font-face {
  font-family: "IM Fell English";
  src: url("/static/fonts/imfell.woff2") format("woff2");
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IM Fell English";
  src: url("/static/fonts/imfell-italic.woff2") format("woff2");
  font-style: italic;
  font-display: swap;
}

:root {
  --ink: #120d08;
  --panel: #241b11;
  --panel-2: #2e2417;
  --line: #3a2f1f;
  --line-2: #52412a;
  --gold-line: #6e5426;
  --bone: #f0e6d2;
  --dim: #a4937a;
  --parch: #ead9b0;
  --parch-2: #d9c491;
  --parch-ink: #33291a;
  --red: #a32431;
  --red-hi: #c53544;
  --torch: #e0913d;
  --gold: #c9a227;
  --ok: #6a9c58;
  --display: "Cinzel", "Palatino Linotype", serif;
  --tale: "IM Fell English", "Iowan Old Style", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  --text-scale: 1; /* story text size, set from the menu (85%–150%) */
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0 auto; max-width: 720px; color: var(--bone);
  font-family: var(--sans); display: flex; flex-direction: column;
  background:
    radial-gradient(120% 60% at 50% -5%, rgba(224, 145, 61, .14), transparent 60%),
    url("/static/stone.jpg") repeat top center / 380px,
    var(--ink);
  box-shadow: 0 0 90px 30px #000 inset;
}

/* ---------- top chrome: carved stone ---------- */
#topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 10px 8px;
  background: linear-gradient(180deg, #2c2115, #1d150c);
  border-bottom: 1px solid var(--gold-line);
  box-shadow: 0 2px 10px rgba(0,0,0,.6);
  position: sticky; top: 0; z-index: 10;
}
#topbar button {
  background: #170f08; color: var(--bone); border: 1px solid var(--line-2);
  border-radius: 8px; font-size: 16px; padding: 6px 10px;
}
#stats {
  flex: 1; display: flex; gap: 6px; overflow-x: auto;
  font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums;
}
.stat {
  display: flex; gap: 4px; align-items: center; white-space: nowrap;
  background: #170f08; border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 8px;
}
.stat b { font-weight: 600; }
.stat.hp b { color: var(--red-hi); }
.stat.torch b { color: var(--torch); }
.stat.gold b { color: var(--gold); }

#roombar {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 7px 14px; font-family: var(--display); font-weight: 600;
  font-size: 12px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--gold);
  background: linear-gradient(180deg, #1d150c, #160f08);
  border-bottom: 1px solid var(--line);
}
#s-brain {
  font-family: var(--mono); font-weight: 400; letter-spacing: 0;
  text-transform: none; color: var(--dim); font-size: 11px;
}

/* ---------- feed ---------- */
#feed {
  flex: 1; overflow-y: auto; padding: 14px 12px 8px;
  display: flex; flex-direction: column; gap: 10px;
  overscroll-behavior: contain;
}
/* scrollable children (roll chips) have no automatic min-height, so a
   long feed would crush them to slivers without this */
#feed > * { flex-shrink: 0; }
.dm-card {
  background: linear-gradient(180deg, #281e12, #221a0f);
  border: 1px solid var(--line);
  outline: 1px solid rgba(110, 84, 38, .35); outline-offset: -4px;
  border-radius: 8px; padding: 12px 15px;
  box-shadow: 0 3px 14px rgba(0,0,0,.45);
}
.dm-card .who {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px;
}
.dm-card .who .label {
  font-family: var(--display); font-size: 10.5px; letter-spacing: .22em;
  text-transform: uppercase; color: var(--gold); font-weight: 600;
}
.tier {
  font-family: var(--mono); font-size: 9px; padding: 2px 6px;
  border-radius: 4px; border: 1px solid #6b4a25; color: var(--torch);
}
.dm-card .prose {
  font-family: var(--tale); font-size: calc(16.5px * var(--text-scale));
  line-height: 1.5; color: #e8dcbf; white-space: pre-wrap;
}
.dm-card .prose em { color: var(--torch); font-style: italic; }
.dm-card .prose::first-letter {
  font-size: 1.9em; line-height: .9; color: var(--red-hi);
  font-family: var(--display); padding-right: 1px;
}
.dm-card.recap { border-color: #63262e; }
.dm-card.recap .who .label { color: var(--red-hi); }

.roll-chip {
  font-family: var(--mono); font-size: calc(11.5px * var(--text-scale));
  color: var(--dim);
  background: rgba(10, 7, 4, .8); border: 1px dashed var(--line-2);
  border-radius: 8px; padding: 6px 10px;
  font-variant-numeric: tabular-nums; overflow-x: auto; white-space: nowrap;
}
.roll-chip.player { border-color: var(--gold-line); color: #cbb87f; }
.player-msg {
  align-self: flex-end; max-width: 84%;
  background: linear-gradient(180deg, #3b141d, #300f17);
  border: 1px solid var(--red); border-radius: 10px 10px 2px 10px;
  padding: 8px 13px; font-size: calc(14px * var(--text-scale));
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.system-msg {
  align-self: center; font-size: calc(13px * var(--text-scale)); color: var(--dim);
  font-family: var(--tale); font-style: italic; text-align: center;
  padding: 2px 10px;
}

#thinking[hidden] { display: none; }
#thinking {
  display: flex; align-items: center; gap: 8px; padding: 8px 16px;
  font-size: 13.5px; color: var(--dim); font-family: var(--tale); font-style: italic;
}
#thinking span {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--torch); box-shadow: 0 0 8px 2px rgba(224,145,61,.5);
  animation: flicker 900ms infinite alternate;
}
@keyframes flicker { from { opacity: .3; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  #thinking span, #dice-total.rolled { animation: none !important; }
}

/* ---------- input ---------- */
#inputbar {
  position: sticky; bottom: 0;
  background: linear-gradient(180deg, #1d150c, #120d08);
  border-top: 1px solid var(--gold-line);
  padding: 6px 10px calc(env(safe-area-inset-bottom) + 10px);
}
#chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; }
.chip {
  flex: 0 0 auto; font-size: 12px; padding: 7px 12px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line-2);
  color: var(--bone); font-weight: 600;
}
#entry { display: flex; gap: 8px; }
#input {
  flex: 1; background: var(--panel); border: 1px solid var(--line-2);
  border-radius: 999px; padding: 11px 16px; font-size: 15px;
  color: var(--bone); outline: none;
}
#input:focus { border-color: var(--torch); }
#send {
  width: 46px; height: 46px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--red-hi), var(--red) 65%);
  border: 1px solid var(--red-hi); color: var(--bone); font-size: 17px;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
}
#send:disabled, .chip:disabled, .die:disabled { opacity: .4; }

/* ---------- panels ---------- */
.panel {
  position: fixed; inset: 0; z-index: 20; overflow-y: auto;
  max-width: 720px; margin-inline: auto;
  background: url("/static/stone.jpg") repeat top center / 380px, var(--ink);
  padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: linear-gradient(180deg, #2c2115, #1d150c);
  border-bottom: 1px solid var(--gold-line); position: sticky; top: 0; z-index: 2;
}
.panel-head h2 {
  font-family: var(--display); font-weight: 800; font-size: 19px;
  letter-spacing: .08em; margin: 0; color: var(--parch);
}
.close {
  background: none; border: 1px solid var(--line-2); color: var(--bone);
  border-radius: 8px; font-size: 14px; padding: 6px 10px;
}
.ornament {
  height: 44px; margin: 4px auto 0; max-width: 440px;
  background: url("/static/divider.jpg") no-repeat center / contain;
  mix-blend-mode: screen; opacity: .9;
}

/* hero art (login / chargen) */
.hero-art { position: relative; }
.hero-art img { width: 100%; display: block; max-height: 46vh; object-fit: cover; object-position: top; }
.hero-art.small img { max-height: 26vh; }
.hero-fade {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 35%, var(--ink) 98%);
}
.hero-title {
  position: absolute; left: 0; right: 0; bottom: 8px; text-align: center;
}
.hero-title small {
  font-family: var(--display); font-size: 10px; letter-spacing: .3em;
  text-transform: uppercase; color: var(--torch);
}
.hero-title h1 {
  font-family: var(--display); font-weight: 800; font-size: 38px;
  letter-spacing: .06em; margin: 2px 0 0; color: var(--parch);
  text-shadow: 0 2px 14px #000, 0 0 40px rgba(224,145,61,.25);
}
.hero-art.small .hero-title h1 { font-size: 26px; }
.hero-title h1 span { color: var(--red-hi); }

/* character sheets: parchment */
#sheets { padding: 14px 12px; display: flex; flex-direction: column; gap: 14px; }
.sheet {
  border-radius: 4px; padding: 16px 15px; position: relative;
  background:
    radial-gradient(ellipse at 25% 15%, rgba(255,255,255,.25), transparent 55%),
    linear-gradient(160deg, var(--parch), var(--parch-2));
  color: var(--parch-ink);
  box-shadow: 0 4px 16px rgba(0,0,0,.5), inset 0 0 40px rgba(140, 110, 60, .25);
}
.sheet.dead { filter: grayscale(.7) brightness(.8); }
.sheet h3 { font-family: var(--display); font-weight: 800; margin: 0; font-size: 19px; }
.sheet .sub { font-family: var(--tale); font-size: 13px; color: #6d5c3d; margin-bottom: 8px; }
.abilities { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.ab {
  background: #f6ecd4; border: 1px solid #b39e6d; border-radius: 6px;
  text-align: center; padding: 5px 1px;
}
.ab small { font-size: 8.5px; letter-spacing: .1em; color: #8a7346; font-weight: 700; }
.ab b { display: block; font-family: var(--mono); font-size: 15px; }
.ab i { font-family: var(--mono); font-size: 10px; font-style: normal; color: var(--red); font-weight: 700; }
.combatrow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-top: 8px; }
.cr {
  background: var(--parch-ink); color: var(--parch); border-radius: 6px;
  text-align: center; padding: 7px 2px;
}
.cr small { font-size: 8.5px; letter-spacing: .1em; color: #b7a680; }
.cr b { display: block; font-family: var(--mono); font-size: 16px; }
.inv { margin-top: 10px; font-size: 13px; line-height: 1.55; font-family: var(--tale); }
.inv b {
  font-family: var(--display); font-size: 9.5px; letter-spacing: .14em; color: #8a7346;
}
.hpbar { height: 7px; border-radius: 4px; background: #c9b483; overflow: hidden; margin-top: 8px; }
.hpbar i { display: block; height: 100%; background: var(--ok); }
.hpbar.hurt i { background: var(--torch); }
.hpbar.crit i { background: var(--red-hi); }

/* menus & shared controls */
.menu-list { padding: 16px 14px; display: flex; flex-direction: column; gap: 18px; }
.menu-list h3 {
  font-family: var(--display); font-size: 11px; letter-spacing: .2em;
  text-transform: uppercase; color: var(--gold); margin: 0 0 8px;
}
#brains { display: flex; gap: 8px; }
.brain {
  flex: 1; display: flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--panel); border: 1px solid var(--line-2); color: var(--bone);
  border-radius: 10px; padding: 10px 6px; font-size: 13px; font-weight: 600;
}
.brain.on { border-color: var(--torch); box-shadow: 0 0 0 1px var(--torch), 0 0 12px rgba(224,145,61,.25); }
.logo {
  width: 22px; height: 22px; border-radius: 6px; display: grid;
  place-items: center; font-weight: 800; font-size: 11px; color: #fff;
}
.lg-c { background: #b4562c; } .lg-x { background: #24292f; border: 1px solid #555; }
.lg-g { background: #2f6fd6; }
.rolls {
  font-family: var(--mono); font-size: 11px; color: var(--dim);
  background: rgba(10,7,4,.8); border: 1px dashed var(--line-2); border-radius: 8px;
  padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; overflow-x: auto;
}
.rolls div { white-space: nowrap; }
.wide-btn {
  width: 100%; background: var(--panel); border: 1px solid var(--line-2);
  color: var(--bone); border-radius: 10px; padding: 12px; font-size: 14px;
  font-weight: 600; font-family: var(--sans);
}
.wide-btn.seal {
  background: radial-gradient(circle at 35% 25%, var(--red-hi), var(--red) 70%);
  border-color: var(--red-hi);
  font-family: var(--display); font-weight: 700; letter-spacing: .06em;
  box-shadow: 0 3px 10px rgba(0,0,0,.5);
}
.wide-btn.big { padding: 15px; font-size: 16px; }
.wide-btn.half { width: auto; flex: 1; }
.wide-btn.danger { border-color: #63262e; color: var(--red-hi); }
.wide-btn:disabled { opacity: .4; }
#password, #cg-name, #dice-reason, #cg-premise {
  width: 100%; background: var(--panel); border: 1px solid var(--line-2);
  border-radius: 10px; padding: 12px 14px; color: var(--bone); font-size: 15px;
}
#cg-premise {
  font-family: var(--tale); resize: vertical; min-height: 74px;
  line-height: 1.4;
}
#cg-premise:focus { border-color: var(--torch); outline: none; }
.err { color: var(--red-hi); font-size: 13px; min-height: 1em; margin: 0; }
.hint { color: var(--dim); font-size: 12px; font-style: italic; margin: 0; font-family: var(--tale); }

/* ---------- dice tray ---------- */
#dice-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.die {
  font-family: var(--display); font-weight: 800; font-size: 21px;
  color: var(--parch); padding: 20px 4px; border-radius: 12px;
  background:
    radial-gradient(circle at 35% 25%, #3b2d1a, #241b11 75%);
  border: 1px solid var(--gold-line);
  box-shadow: 0 3px 8px rgba(0,0,0,.5), inset 0 1px 0 rgba(240,230,210,.12);
}
.die:active { transform: translateY(1px); }
.die.wide { padding: 12px; font-size: 17px; }
.dice-opts { display: flex; gap: 10px; align-items: stretch; }
.stepper {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px;
}
.stepper button {
  background: none; border: none; color: var(--parch); font-size: 22px;
  padding: 8px 14px;
}
.stepper span { font-family: var(--mono); font-size: 18px; }
.font-stepper { padding: 3px 0; margin-bottom: 8px; }
.stepper .stepper-label { font-size: 11px; color: var(--dim); font-family: var(--sans); }
.dice-result {
  text-align: center; padding: 6px 0 2px;
}
#dice-total {
  font-family: var(--display); font-weight: 800; font-size: 54px;
  color: var(--parch); text-shadow: 0 0 24px rgba(224,145,61,.4);
  line-height: 1;
}
#dice-total.rolled { animation: dicepop .35s ease-out; }
@keyframes dicepop {
  0% { transform: scale(.6) rotate(-8deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
#dice-detail { font-family: var(--mono); font-size: 12px; color: var(--dim); margin-top: 4px; }

/* ---------- end of tale ---------- */
.end-scene { text-align: center; padding-top: 40px; }
.end-icon { font-size: 64px; line-height: 1; filter: drop-shadow(0 0 24px rgba(224,145,61,.35)); }
.end-title {
  font-family: var(--display); font-weight: 800; font-size: 30px;
  letter-spacing: .06em; margin: 4px 0 0; color: var(--parch);
  text-shadow: 0 2px 14px #000;
}
.end-epitaph {
  font-family: var(--tale); font-style: italic; font-size: 17px;
  line-height: 1.5; color: #e8dcbf; margin: 4px 18px;
}
#end-strip { margin-bottom: 8px; }
#end-strip[hidden] { display: none; }

/* ---------- character creation ---------- */
/* class portraits (generated) */
.cls-icon {
  width: 30px; height: 30px; border-radius: 50%; object-fit: cover;
  border: 1px solid var(--gold-line); flex: 0 0 auto;
  box-shadow: 0 1px 4px rgba(0,0,0,.5);
}
.roster-icon { width: 38px; height: 38px; }
.cg-class-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.sheet .portrait {
  float: right; width: 64px; height: 64px; border-radius: 50%;
  object-fit: cover; border: 2px solid #8a7346; margin: 0 0 6px 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
}

#cg-roster { display: flex; flex-direction: column; gap: 8px; }
.cg-hero {
  display: flex; align-items: center; gap: 11px;
  background: var(--panel); border: 1px solid var(--gold-line);
  border-radius: 10px; padding: 10px 13px;
}
.cg-hero-body { flex: 1; }
.cg-hero .nm { font-family: var(--display); font-weight: 700; font-size: 15px; color: var(--parch); }
.cg-hero .cls { font-size: 12px; color: var(--dim); font-family: var(--tale); font-style: italic; }
.cg-hero button { background: none; border: none; color: var(--red-hi); font-size: 15px; }
.cg-abilities { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; margin-bottom: 10px; }
.cg-abilities .ab { background: var(--panel); border-color: var(--line-2); }
.cg-abilities .ab small { color: var(--gold); }
.cg-abilities .ab b { color: var(--bone); font-size: 17px; }
.cg-abilities .ab i { color: var(--torch); }
#cg-classes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.cg-class {
  text-align: left; background: var(--panel); border: 1px solid var(--line-2);
  border-radius: 10px; padding: 10px 12px; color: var(--bone);
}
.cg-class.on { border-color: var(--torch); box-shadow: 0 0 0 1px var(--torch); }
.cg-class .t { font-family: var(--display); font-weight: 700; font-size: 14px; }
.cg-class .d { font-size: 11px; color: var(--dim); margin-top: 2px; }
.cg-class .rec { color: var(--ok); font-size: 10px; font-weight: 700; letter-spacing: .08em; }
.cg-row { display: flex; gap: 8px; margin-top: 10px; }
#cg-rolled[hidden] { display: none; }
#cg-name { margin-bottom: 2px; }

button { cursor: pointer; font-family: inherit; }
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--torch); outline-offset: 1px;
}
