/* Elyndris: lantern light on slate. Each colour carries one meaning:
   lantern = you / your turn, verdigris = allies & good news, blood = harm,
   crystal = the revive crystal, bone = text. */
:root {
  --night: #151b26;
  --stone: #1e2633;
  --stone-hi: #2a3444;
  --edge: #3a4658;
  --bone: #e9e0c9;
  --ash: #9097a3;
  --lantern: #f2b04e;
  --verdigris: #5fae98;
  --blood: #c0453b;
  --crystal: #7fd6e8;
  --display: "IM Fell English", Georgia, "Times New Roman", serif;
  --ui: "Alegreya Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--night); color: var(--bone);
  font: 16px/1.45 var(--ui); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.muted { color: var(--ash); }
.msg { color: #ef8a7f; min-height: 1.4em; margin: .4em 0 0; }

h1, h2, h3 { font-family: var(--display); font-weight: 400; margin: 0; }
h1 { font-size: clamp(3.2rem, 9vw, 5.6rem); line-height: .95; color: var(--lantern);
  text-shadow: 0 0 24px rgba(242,176,78,.35), 0 2px 0 #000; letter-spacing: .01em; }
h2 { font-size: 1.75rem; line-height: 1.1; }
h3 { font-size: 1.2rem; color: #d9c79a; margin: 0 0 .45rem; }

button, input, select {
  font: 500 1rem var(--ui); color: var(--bone); border-radius: 3px; min-height: 40px;
}
input, select {
  background: #10151e; border: 1px solid var(--edge); padding: 8px 10px; min-width: 0;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.5);
}
input::placeholder { color: #6c7380; }
button {
  cursor: pointer; padding: 8px 14px; border: 1px solid #485569;
  background: linear-gradient(#2e394a, #222b38); box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 2px 0 #0a0d13;
}
button:hover:not(:disabled) { background: linear-gradient(#36435a, #28323f); }
button:active:not(:disabled) { transform: translateY(1px); box-shadow: inset 0 1px 0 rgba(255,255,255,.05); }
button.primary { color: #2a1a06; font-weight: 700; border-color: #c88a2e;
  background: linear-gradient(#f6c46c, #e0982f); box-shadow: inset 0 1px 0 rgba(255,255,255,.4), 0 2px 0 #6e4512; }
button.primary:hover:not(:disabled) { background: linear-gradient(#fbd083, #e8a33c); }
button.danger { color: #fff; border-color: #8d2c24; background: linear-gradient(#cf5448, #a6352c); }
button.quiet { background: none; border: none; box-shadow: none; color: var(--ash); padding: 4px 0; min-height: 0;
  text-decoration: underline; text-underline-offset: 3px; }
button.quiet:hover:not(:disabled) { background: none; color: var(--bone); }
button:disabled { opacity: .35; cursor: default; }
:focus-visible { outline: 2px solid var(--lantern); outline-offset: 2px; }

.row { display: flex; gap: 8px; margin: 8px 0; align-items: center; }
.row > input { flex: 1; }

/* ---------- login & lineage: panels over the living cave ---------- */
#hero { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
body:has(#game:not(.hidden)) #hero { display: none; }
.screen {
  position: relative; z-index: 1; width: min(420px, calc(100% - 32px));
  margin: 0 0 0 max(16px, 8vw); padding: 12vh 0 32px;
}
#login .tagline { font-family: var(--display); font-style: italic; font-size: 1.25rem; color: #d9c79a;
  margin: .6rem 0 2rem; max-width: 26ch; text-shadow: 0 1px 2px #000; }
#login form, #chars {
  background: linear-gradient(rgba(21,27,38,.92), rgba(21,27,38,.88));
  border: 1px solid var(--edge); border-top: 2px solid var(--lantern); padding: 22px 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6); backdrop-filter: blur(3px);
}
#chars { margin-top: 10vh; padding-top: 22px; }
#chars h2 { margin-bottom: .8rem; }
#chars h3 { margin-top: 1.4rem; }
.screen label { display: block; margin: 0 0 14px; color: var(--ash); font-size: .95rem; }
.screen label input { display: block; width: 100%; margin-top: 4px; }

.char { display: grid; grid-template-columns: 48px 1fr auto; gap: 12px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid rgba(58,70,88,.6); }
.char img, .species img { image-rendering: pixelated; width: 48px; height: 48px; }
.char .name { font-family: var(--display); font-size: 1.35rem; line-height: 1; }
.species { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.species button { display: flex; flex-direction: column; align-items: center; padding: 6px 4px; gap: 2px;
  font-size: .9rem; background: #141a24; }
.species button[aria-checked="true"] { border-color: var(--lantern); color: var(--lantern);
  box-shadow: inset 0 0 0 1px var(--lantern), 0 0 14px rgba(242,176,78,.25); }
#fallen { list-style: none; padding: 0; margin: 0; font-size: .95rem; }
#fallen li { padding: 4px 0; color: var(--ash); }
#fallen li b { font-family: var(--display); font-weight: 400; color: var(--bone); font-size: 1.1rem; }

/* ---------- game ---------- */
#game { display: flex; height: 100vh; height: 100dvh; }
#stage { position: relative; flex: 1; min-width: 0; background: #06070b; }
#canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: pointer; }
#zone-name { position: absolute; top: 14px; left: 18px; font-family: var(--display); font-size: 1.6rem;
  text-shadow: 0 2px 6px #000, 0 0 2px #000; pointer-events: none; }
#turn-banner { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); pointer-events: none;
  padding: 6px 18px; font-family: var(--display); font-size: 1.15rem; background: rgba(10,13,20,.8);
  border: 1px solid var(--edge); border-radius: 2px; white-space: nowrap; }
#turn-banner.mine { color: #2a1a06; background: var(--lantern); border-color: #ffd58f;
  box-shadow: 0 0 22px rgba(242,176,78,.55); }
#turn-banner .timer { font-family: var(--ui); font-size: .9rem; opacity: .75; margin-left: .5em; }

#dpad { position: absolute; right: 14px; bottom: 14px; display: none; grid-template-columns: repeat(3, 52px); gap: 5px; }
#dpad button { height: 52px; font-size: 1.3rem; padding: 0; background: rgba(30,38,51,.82); }
@media (pointer: coarse) { #dpad { display: grid; } }

/* the journal column */
#journal { width: 340px; flex: none; display: flex; flex-direction: column; overflow-y: auto; padding: 18px 18px 12px;
  background: linear-gradient(90deg, #11161f, var(--stone) 14px); border-left: 1px solid #000;
  box-shadow: inset 1px 0 0 var(--edge); }
#journal > * { flex-shrink: 0; }
#journal > section { padding: 14px 0; border-top: 1px solid rgba(58,70,88,.7); }
#journal > section.grow { flex: 1 0 auto; display: flex; flex-direction: column; min-height: 220px; }

#hero-card { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
#self-portrait { width: 56px; height: 56px; image-rendering: pixelated; background: #10151e;
  border: 1px solid var(--edge); box-shadow: inset 0 0 12px rgba(242,176,78,.2); }
#self-name { color: var(--lantern); }
#self-sub { margin: 2px 0 0; font-size: .95rem; }

.meter { position: relative; height: 10px; background: #0d1118; border: 1px solid #000; margin: 6px 0; }
.meter > div { height: 100%; width: 0; transition: width .3s; }
.meter.hp { height: 18px; }
.meter.hp > div { background: linear-gradient(#d65a4e, #9e3128); }
.meter.hp span { position: absolute; inset: 0; text-align: center; font-size: .82rem; font-weight: 700; line-height: 16px;
  text-shadow: 0 1px 2px #000; }
.meter.xp { height: 5px; }
.meter.xp > div { background: #b9a26a; }
@media (prefers-reduced-motion: reduce) { .meter > div { transition: none; } }

#stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); margin: 10px 0 8px; }
#stat-grid div { text-align: center; }
#stat-grid dt { font-size: .78rem; color: var(--ash); }
#stat-grid dd { margin: 0; font-size: 1.15rem; font-weight: 700; }
#stat-grid .coins dd { color: var(--lantern); }

#crystal { display: flex; align-items: center; gap: 8px; padding: 8px 0 14px; color: var(--ash); font-size: .9rem; }
.gem { width: 16px; height: 16px; transform: rotate(45deg); border: 1px solid #3f6f7c; background: #10151e; }
.gem.full { background: linear-gradient(135deg, #e6fbff, var(--crystal) 45%, #2f8aa3);
  border-color: #c8f4ff; box-shadow: 0 0 10px rgba(127,214,232,.7); }

#turn-info { font-size: 1.1rem; }
#turn-info .combat { color: var(--blood); }
#order { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 4px 0 12px; }
#order li { position: relative; width: 44px; text-align: center; font-size: .75rem; color: var(--ash); }
#order img { width: 40px; height: 40px; image-rendering: pixelated; display: block; margin: 0 auto 2px;
  background: #10151e; border: 1px solid var(--edge); }
#order li.foe img { border-color: #6b2c27; }
#order li.ally img { border-color: #2f5f53; }
#order li.current img { border-color: var(--lantern); box-shadow: 0 0 10px rgba(242,176,78,.6); }
#order li.current { color: var(--lantern); }
#order li.down img { filter: grayscale(1) brightness(.6); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.actions .primary { grid-column: span 2; }

#party .member { display: flex; justify-content: space-between; padding: 3px 0; }
#party .leader::after { content: " (leader)"; color: var(--ash); font-size: .85rem; }
#party .offline { color: var(--ash); }

.inv { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 3px 0; }
.inv span { flex: 1; }
.inv .qty { color: var(--ash); }
.inv button { min-height: 30px; padding: 3px 10px; font-size: .9rem; }

#log { flex: 1; overflow-y: auto; font-size: .93rem; min-height: 140px; max-height: 38vh; padding-right: 4px; }
#log div { padding: 1px 0; }
#log .sys { color: var(--ash); font-style: italic; }
#log .party { color: var(--verdigris); }
#log .combat { color: #d8c49a; }
#log .bad { color: #ef8a7f; }
#log .good { color: #8fd3bd; }
.chat select { flex: none; }

/* ---------- dialogs ---------- */
#modal { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  background: rgba(4,6,10,.72); padding: 16px; }
#modal-body { width: min(620px, 100%); max-height: 90vh; overflow-y: auto; padding: 24px 26px;
  background: var(--stone); border: 1px solid var(--edge); border-top: 2px solid var(--lantern);
  box-shadow: 0 24px 80px rgba(0,0,0,.7); }
#modal-body h3 { font-size: 1.7rem; color: var(--bone); margin-bottom: .5rem; }
#modal-body p { max-width: 62ch; }
.passage { font-family: var(--display); font-size: 1.3rem; line-height: 1.65; padding: 16px 18px; margin: 12px 0;
  background: #121821; border-left: 3px solid #6a3f8f; user-select: none; color: #b9b2a0; }
.passage .done { color: var(--bone); }
.passage .wrong { color: #ef8a7f; text-decoration: underline wavy; }
.passage .caret { box-shadow: inset 2px 0 0 var(--lantern); }
textarea { width: 100%; min-height: 110px; font: 1.15rem/1.5 var(--display); color: var(--bone);
  background: #0f141c; border: 1px solid var(--edge); padding: 10px 12px; border-radius: 3px; }
.shop-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 8px 0;
  border-bottom: 1px solid rgba(58,70,88,.6); }
.shop-item b { font-family: var(--display); font-weight: 400; font-size: 1.15rem; }
.shop-item .desc { grid-column: 1; font-size: .9rem; color: var(--ash); }
.shop-item button { grid-row: span 2; align-self: center; }
.price { color: var(--lantern); font-weight: 700; }

@media (max-width: 820px) {
  #game { flex-direction: column; }
  #stage { flex: none; height: 58vh; height: 58dvh; }
  #journal { width: 100%; background: var(--stone); box-shadow: inset 0 1px 0 var(--edge); }
  .screen { margin: 0 auto; padding-top: 8vh; }
  #chars { margin-top: 4vh; }
}

/* touch: keep the turn banner clear of the d-pad */
@media (pointer: coarse) {
  #turn-banner { bottom: auto; top: 54px; font-size: 1rem; max-width: calc(100% - 24px); white-space: normal; text-align: center; }
}
/* narrow: put the turn controls first under the map, where a thumb can reach them */
@media (max-width: 820px) {
  #zone-name { font-size: 1.3rem; }
  #dungeon-actions { order: -1; border-top: none !important; padding-top: 0 !important; margin-bottom: 6px; }
}

/* ---------- music control ---------- */
#music { position: fixed; left: 14px; bottom: 14px; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: 4px 12px 4px 4px; background: rgba(21,27,38,.88); border: 1px solid var(--edge); border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0,0,0,.45); color: var(--ash); font-size: .85rem; }
#music button { width: 32px; height: 32px; min-height: 0; padding: 0; border-radius: 50%; display: grid; place-items: center; }
#music button svg { width: 18px; height: 18px; fill: none; stroke: var(--bone); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#music button[aria-pressed="true"] svg { stroke: var(--ash); }
#music input[type="range"] { width: 96px; min-height: 0; padding: 0; background: none; border: none; box-shadow: none;
  accent-color: var(--lantern); }
#music output { min-width: 3ch; text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 820px) {
  /* in game on narrow screens the map's bottom-left is free; on other screens keep it out of the panel */
  #music { bottom: auto; top: 10px; left: auto; right: 10px; }
  #music input[type="range"] { width: 72px; }
}

/* ---------- dice ---------- */
#dice-tray { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); display: flex; gap: 18px;
  pointer-events: none; z-index: 3; }
.die { display: flex; flex-direction: column; align-items: center; width: 132px; text-align: center;
  transition: opacity .35s, transform .35s; }
.die.leaving { opacity: 0; transform: translateY(-14px); }
.die .dice { position: relative; display: flex; align-items: flex-end; justify-content: center; height: 88px; }
.die .main, .die .ghost { position: relative; }
.die .main svg { width: 82px; height: 82px; filter: drop-shadow(0 6px 10px rgba(0,0,0,.6)); }
.die .ghost { margin-right: -10px; opacity: .45; }
.die .ghost svg { width: 46px; height: 46px; }
.die svg .body { fill: #2a3444; stroke: #0b0e14; stroke-width: 3; }
.die svg .face { fill: #36435a; }
.die svg .edge { stroke: #55657e; stroke-width: 1.5; fill: none; }
.die .num, .die .ghost span { position: absolute; inset: 0; display: grid; place-items: center; padding-top: 10px;
  font: 700 1.9rem var(--display); color: var(--bone); text-shadow: 0 2px 2px #000; }
.die .ghost span { font-size: 1.05rem; padding-top: 6px; }
.die .label { margin-top: 4px; font: 1.05rem var(--display); color: var(--bone); text-shadow: 0 1px 3px #000, 0 0 2px #000; }
.die .label em { display: block; font: italic .8rem var(--ui); color: var(--ash); }
.die .detail { font-size: .85rem; color: #d9c79a; text-shadow: 0 1px 2px #000; font-variant-numeric: tabular-nums; }
.die.tumbling .main svg { animation: tumble .65s cubic-bezier(.2,.7,.3,1); }
.die.tumbling .num { opacity: .55; }
@keyframes tumble {
  0% { transform: translate(-40px, -60px) rotate(-200deg) scale(.6); }
  60% { transform: translate(6px, 4px) rotate(20deg) scale(1.05); }
  100% { transform: none; }
}
.die.landed .main svg { animation: land .3s ease-out; }
@keyframes land { 0% { transform: scale(1.15); } 100% { transform: scale(1); } }
.die.success .body { fill: #24443d; stroke: #5fae98; }
.die.success .face { fill: #2e5a50; }
.die.fail .body { fill: #4a2522; stroke: #c0453b; }
.die.fail .face { fill: #5c2e2a; }
.die.crit .body { fill: #5a4216; stroke: #f2b04e; }
.die.crit .face { fill: #7a5a1c; }
.die.crit .main svg { filter: drop-shadow(0 0 14px rgba(242,176,78,.9)); }
.die.fumble .body { fill: #2a0e0e; stroke: #7a1f1a; }
.die.fumble .num { color: #ef8a7f; }
@media (prefers-reduced-motion: reduce) { .die, .die .main svg { animation: none !important; transition: none; } }
#log .roll { color: #cfc6ae; }
#log .roll.success, #log .roll.crit { color: #9fd8c5; }
#log .roll.fail, #log .roll.fumble { color: #e7a69d; }

/* ---------- abilities and skills ---------- */
#abilities { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; }
.ability { display: grid; grid-template-columns: 1fr auto auto; gap: 0 6px; align-items: baseline; }
.ability .ab-name { font-size: .92rem; }
.ability .ab-lvl { font-weight: 700; font-variant-numeric: tabular-nums; }
.ability .ab-mod { font-size: .8rem; color: var(--ash); min-width: 2.2ch; text-align: right; }
.ability .ab-bar { grid-column: 1 / -1; height: 3px; background: #0d1118; margin-top: 2px; }
.ability .ab-bar > div { height: 100%; background: #b9a26a; }
.skills { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.skills button { min-height: 32px; padding: 4px 10px; font-size: .9rem; }
.skills button span { color: var(--ash); font-size: .8rem; margin-left: 4px; }

/* ---------- minigames ---------- */
.mg-bar, .mg-range { display: block; width: 100%; height: auto; border: 1px solid var(--edge); background: #10151e;
  touch-action: none; user-select: none; }
.mg-range { max-width: 420px; margin: 0 auto; cursor: crosshair; }
.mg-status { min-height: 1.5em; margin: 10px 0; color: #d9c79a; }
.mg-big { min-height: 56px; font-size: 1.05rem; flex: 1; }
.mg-foot { justify-content: flex-end; }
.mg-haul { display: flex; gap: 16px; align-items: stretch; }
.mg-haul canvas { border: 1px solid var(--edge); flex: none; width: 90px; height: 200px; }
.mg-hands { display: flex; flex-direction: column; gap: 10px; flex: 1; }
.mg-hands .pressed { background: linear-gradient(#5a6a86, #3a465a); }
.mg-count { color: var(--ash); margin: 4px 0; font-size: .9rem; }
.mg-prompt { font-size: 1.15rem; line-height: 1.5; margin: 6px 0 14px; }
.mg-prompt.runes { font-family: var(--display); font-size: 1.3rem; }
.mg-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mg-options button { min-height: 52px; text-align: left; }
.mg-options button.chosen { border-color: var(--lantern); }
.mg-timer { height: 4px; background: #0d1118; margin-top: 12px; }
.mg-timer > div { height: 100%; background: var(--lantern); width: 100%; }
.mg-feedback { margin: 0 0 6px; }
.mg-feedback.good { color: #8fd3bd; }
.mg-feedback.bad { color: #ef8a7f; }
.mg-score { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; margin: 14px 0; }
.mg-score dt { font-size: .8rem; color: var(--ash); }
.mg-score dd { margin: 0; font-size: 1.4rem; font-weight: 700; }
.mg-score.levelup dd { color: var(--lantern); text-shadow: 0 0 12px rgba(242,176,78,.6); }
@media (max-width: 560px) { .mg-options { grid-template-columns: 1fr; } }
/* in game on wide screens, keep the music control clear of the turn banner */
@media (min-width: 821px) {
  body:has(#game:not(.hidden)) #music { top: 14px; bottom: auto; left: auto; right: 354px; }
}
