:root {
  --bg: #0b0f0d;
  --panel: rgba(14, 20, 17, 0.92);
  --line: #2c3a32;
  --text: #e4e9e4;
  --muted: #9fb0a5;
  --accent: #d9a441;
  --accent-ink: #1a1408;
  --err: #ff8a7a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }

#stage { position: fixed; inset: 0; }
/* The game follows the canvas' CSS size (SDL resizes the drawing buffer to match). */
#canvas { display: block; width: 100%; height: 100%; background: #000; outline: none; image-rendering: pixelated; }

#toolbar { position: absolute; z-index: 5; top: 10px; right: 10px; display: flex; gap: 6px; }
#toolbar[hidden] { display: none; }
#toolbar button {
  width: 34px; height: 34px; border-radius: 6px; border: 1px solid var(--line);
  background: rgba(10, 14, 12, 0.6); color: var(--text); font-size: 17px; cursor: pointer;
}
#toolbar button:hover { background: rgba(30, 40, 34, 0.85); }
#toolbar #btn-menu { width: auto; min-width: 64px; padding: 0 14px; font: 600 15px/1 system-ui, sans-serif; background: rgba(217, 164, 65, 0.85); color: var(--accent-ink); border-color: rgba(255, 230, 160, 0.8); }
#toolbar #btn-menu:hover { background: rgba(235, 185, 85, 0.95); }
#toolbar #btn-menu[hidden] { display: none; }

#overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: radial-gradient(ellipse at center, rgba(5, 8, 6, 0.55), rgba(5, 8, 6, 0.85));
  overflow-y: auto;
}
#overlay[hidden] { display: none; }
.card {
  width: min(460px, 100%); padding: 26px 26px 18px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
h1 { margin: 0; font: 600 34px/1.1 Georgia, "Times New Roman", serif; letter-spacing: 0.06em; color: var(--accent); }
.tag { margin: 6px 0 20px; color: var(--muted); font-size: 14px; }

.bar { height: 6px; border-radius: 3px; background: #1d2621; overflow: hidden; }
.bar span { display: block; height: 100%; width: 8%; background: var(--accent); transition: width 0.2s; }
#status { margin: 10px 0 4px; color: var(--muted); font-size: 13px; min-height: 1.4em; }

button.primary {
  font: inherit; font-weight: 600; font-size: 17px; padding: 11px 28px; border-radius: 7px; border: 0;
  background: var(--accent); color: var(--accent-ink); cursor: pointer;
}
button.primary:hover { filter: brightness(1.08); }
button.secondary {
  font: inherit; font-size: 15px; padding: 9px 22px; border-radius: 7px; border: 1px solid var(--line);
  background: transparent; color: var(--text); cursor: pointer;
}
button.secondary:hover { background: rgba(255, 255, 255, 0.07); }
button.secondary:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.hint { margin: 8px 0 16px; color: var(--muted); font-size: 12.5px; }
button.primary:focus-visible, #toolbar button:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.err { color: var(--err); white-space: pre-wrap; text-align: left; font-size: 13px; }

details { margin-top: 20px; text-align: left; }
summary { cursor: pointer; color: var(--muted); font-size: 13px; text-align: center; }
table { width: 100%; margin-top: 10px; border-collapse: collapse; font-size: 13px; }
th, td { padding: 4px 6px; border-top: 1px solid var(--line); vertical-align: top; }
th { text-align: left; font-weight: 500; color: var(--muted); white-space: nowrap; }
.note { color: var(--muted); font-size: 12px; margin: 10px 0 0; }

/* Touch controls: only while playing on a touch screen (web/boot.js shows and hides #touch). */
#touch { position: absolute; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none; }
#t-look { position: absolute; inset: 0; touch-action: none; }
#t-stick {
  position: absolute; left: max(18px, env(safe-area-inset-left)); bottom: max(18px, env(safe-area-inset-bottom));
  width: 132px; height: 132px; border-radius: 50%; touch-action: none;
  background: rgba(228, 233, 228, 0.12); border: 2px solid rgba(228, 233, 228, 0.35);
}
#t-knob {
  position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%;
  background: rgba(228, 233, 228, 0.35); pointer-events: none;
}
.tb {
  position: absolute; min-width: 56px; height: 56px; padding: 0 10px; border-radius: 28px; touch-action: none;
  border: 2px solid rgba(228, 233, 228, 0.4); background: rgba(10, 14, 12, 0.45); color: var(--text);
  font: 600 13px/1 system-ui, sans-serif; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
.tb.on { background: rgba(217, 164, 65, 0.7); color: var(--accent-ink); }
/* the right-hand cluster keeps clear of the hotbar (bottom centre, tapped to pick a slot) */
.tb[data-b="hit"]   { right: max(18px, env(safe-area-inset-right)); bottom: 96px; width: 72px; height: 72px; border-radius: 36px; }
.tb[data-b="use"]   { right: 108px; bottom: 44px; width: 72px; height: 72px; border-radius: 36px; }
.tb[data-b="jump"]  { right: 22px; bottom: 24px; }
.tb[data-b="sneak"] { right: 116px; bottom: 124px; }
@media (orientation: portrait) { #t-stick { bottom: max(50px, env(safe-area-inset-bottom)); } }
/* A menu is open on a touch screen: one big Back button (a finger has no Esc key); the page's own buttons step aside */
#t-back {
  position: absolute; z-index: 5; right: max(10px, env(safe-area-inset-right)); top: max(8px, env(safe-area-inset-top)); min-width: 84px; height: 46px; padding: 0 18px;
  border-radius: 23px; border: 2px solid rgba(228, 233, 228, 0.55); background: rgba(10, 14, 12, 0.8); color: var(--text);
  font: 600 16px/1 system-ui, sans-serif; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
#t-back:active { background: rgba(217, 164, 65, 0.8); color: var(--accent-ink); }
body.t-menu #toolbar { display: none; }
.tb[data-b="pause"] { left: 50%; top: 10px; margin-left: -38px; min-width: 76px; height: 48px; border-radius: 24px; font-size: 16px; background: rgba(217, 164, 65, 0.72); color: var(--accent-ink); border-color: rgba(255, 230, 160, 0.85); }
.tb[data-b="pack"]  { right: 10px; top: 56px; height: 44px; border-radius: 22px; }
.tb[data-b="journal"] { right: 80px; top: 56px; height: 44px; border-radius: 22px; }
.tb[data-b="prev"], .tb[data-b="next"] { top: 10px; height: 44px; border-radius: 22px; font-size: 22px; }
.tb[data-b="prev"] { left: calc(50% - 120px); }
.tb[data-b="next"] { left: calc(50% + 66px); }
@media (max-height: 420px) { #t-stick { width: 110px; height: 110px; } }
#ready .primary + .primary { margin-left: 10px; }

[hidden] { display: none !important; }

/* ---- the play page as a real page: header, card, about column (owner 2026-11-05: "not a pop-up with no way back") ---- */
#overlay { flex-direction: column; align-items: stretch; justify-content: flex-start; padding: 0; overflow-y: auto; }
.sitebar {
  position: sticky; top: 0; z-index: 3; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 18px;
  padding: 10px 170px 10px 18px; background: rgba(8, 12, 10, 0.94); border-bottom: 1px solid var(--line);   /* room on the right for the game's toolbar buttons */
}
.sitebar .brand { color: var(--accent); font: 600 17px/1 Georgia, "Times New Roman", serif; letter-spacing: 0.06em; text-decoration: none; }
.sitebar nav { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.sitebar nav a { color: var(--text); font-size: 14px; text-decoration: none; padding: 4px 2px; border-bottom: 2px solid transparent; }
.sitebar nav a:hover, .sitebar nav a:focus-visible { border-bottom-color: var(--accent); outline: none; }
.page { display: grid; grid-template-columns: minmax(300px, 460px) minmax(0, 560px); gap: 24px; justify-content: center; align-items: start; padding: 22px 16px 40px; }
.page .card { width: 100%; }
.about { padding: 22px 24px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font-size: 14.5px; line-height: 1.55; }
.about h2 { margin: 0 0 8px; font: 600 24px/1.2 Georgia, "Times New Roman", serif; color: var(--accent); }
.about h3 { margin: 18px 0 6px; font-size: 15px; color: var(--accent); }
.about p { margin: 0 0 10px; }
.about a { color: var(--accent); }
@media (max-width: 900px) { .page { grid-template-columns: minmax(0, 560px); } }
@media (max-width: 520px) { .sitebar { padding: 8px 12px; padding-right: 12px; margin-top: 56px; flex-direction: column; align-items: flex-start; gap: 6px; } .sitebar nav { gap: 2px 12px; flex-wrap: nowrap; } .sitebar nav a { font-size: 13px; white-space: nowrap; } .page { padding: 14px 10px 30px; } .about { padding: 16px 14px; } }

.tool-link {
  display: inline-flex; align-items: center; height: 34px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--line);
  background: rgba(10, 14, 12, 0.6); color: var(--text); font-size: 13px; text-decoration: none;
}
.tool-link:hover { background: rgba(30, 40, 34, 0.85); }

/* account panel */
.acct { margin-top: 18px; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: left; }
.acct .hint { margin: 0 0 6px; }
.linklike { font: inherit; font-size: 13px; padding: 4px 0; border: 0; background: none; color: var(--accent); cursor: pointer; text-decoration: underline; }
.linklike:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
#acct-form { margin-top: 10px; display: grid; gap: 10px; }
#acct-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
#acct-form input {
  font: inherit; font-size: 15px; padding: 9px 10px; border-radius: 6px; border: 1px solid var(--line); background: #0d1411; color: var(--text);
}
#acct-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.acct-buttons { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
button.small { font-size: 14px; padding: 8px 16px; }
.acct-msg { margin: 8px 0 0; min-height: 1.3em; font-size: 13px; color: var(--muted); }
.acct-msg.bad { color: var(--err); }
.acct-msg.good { color: #8fdc9f; }

/* touch controls showing: keep the page's own toolbar (?, full screen, Home) clear of the item arrows and the Pack / Saga buttons */
#stage:has(#touch:not([hidden])) #toolbar { top: 108px; }

/* character choice */
.charpick { margin: 14px 0 4px; }
.chars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 8px 0; }
.char { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px 6px; border: 1px solid var(--line, rgba(255,255,255,.18)); border-radius: 8px; background: rgba(255,255,255,.04); color: inherit; font: inherit; font-size: 12px; cursor: pointer; }
.char[aria-pressed="true"] { border-color: #e0a63c; background: rgba(224,166,60,.16); }
.char:focus-visible { outline: 2px solid #e0a63c; outline-offset: 2px; }
.fig { position: relative; display: block; width: 26px; height: 40px; }
.fig i { position: absolute; display: block; }
.fig i:nth-child(1) { left: 3px; top: 0; width: 20px; height: 9px; }
.fig .head { left: 5px; top: 5px; width: 16px; height: 14px; background: #eec09c; }
.fig .body { left: 2px; top: 20px; width: 22px; height: 20px; }
@media (max-width: 420px) { .chars { grid-template-columns: repeat(2, 1fr); } }

.steps { margin: 6px 0 14px 18px; padding: 0; }
.steps li { margin: 6px 0; line-height: 1.45; }
.ctl { width: 100%; border-collapse: collapse; font-size: 12.5px; margin: 8px 0; }
.ctl th, .ctl td { border-top: 1px solid rgba(255,255,255,.12); padding: 5px 6px; text-align: left; vertical-align: top; }
.ctl tr:first-child th { border-top: 0; color: #e0a63c; }
.ctl th:first-child { white-space: nowrap; }
@media (max-width: 700px) { .ctl { font-size: 11.5px; } .ctl th, .ctl td { padding: 4px 3px; } }
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ctl { min-width: 560px; }

/* the admin menu */
.adm { margin-top: 12px; }
.adm summary { cursor: pointer; }
.adm-bar { margin: 8px 0; }
.adm-table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.adm-table th, .adm-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid rgba(255,255,255,0.12); vertical-align: middle; }
.adm-table td:last-child { white-space: nowrap; }
.adm-table td button { margin-right: 6px; }

/* the smallest phones (320 px): the site links wrap instead of running off the edge */
@media (max-width: 360px) { .sitebar nav { flex-wrap: wrap; gap: 2px 10px; } .sitebar nav a { font-size: 12.5px; } }
/* a table placed straight in a details block (the card's control list) scrolls sideways instead of running past the card */
details > table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
