:root {
  --ink: #2a1a10;
  --parch: #f3e6c8;
  --parch2: #e8d6ae;
  --gold: #d9a441;
  --gold2: #f2c96a;
  --red: #a8281e;
  --text: #fff7e6;
  --shadow: 0 6px 30px rgba(0, 0, 0, 0.45);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0d0a08; color: var(--text); font-family: var(--serif); -webkit-user-select: none; user-select: none; touch-action: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
.hidden { display: none !important; }
button { font-family: var(--serif); }

#loading { position: fixed; inset: 0; display: grid; place-items: center; font-size: 22px; letter-spacing: 0.08em; color: var(--gold2); background: #0d0a08; z-index: 50; transition: opacity 0.6s; }
#loading.gone { opacity: 0; pointer-events: none; }

/* ------------------------------------------------ exploration HUD */
#objective { white-space: pre-line; position: fixed; top: 16px; left: 16px; max-width: min(420px, 70vw); padding: 10px 14px; background: rgba(20, 12, 6, 0.62); border-left: 3px solid var(--gold); border-radius: 4px; font-size: 16px; line-height: 1.35; text-shadow: 0 1px 2px #000; }
.obj-k { display: block; font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold2); margin-bottom: 2px; }
#prompt { position: fixed; left: 50%; bottom: 22%; transform: translateX(-50%); padding: 8px 16px; background: rgba(20, 12, 6, 0.7); border: 1px solid rgba(217, 164, 65, 0.6); border-radius: 999px; font-size: 16px; white-space: nowrap; }
#prompt b { color: var(--gold2); }
#marker { position: fixed; left: 0; top: 0; width: 0; height: 0; pointer-events: none; }
#marker .arrow { position: absolute; left: -11px; top: -22px; width: 0; height: 0; border-left: 11px solid transparent; border-right: 11px solid transparent; border-top: 18px solid var(--gold2); filter: drop-shadow(0 0 6px rgba(255, 200, 80, 0.8)); animation: bob 1.2s ease-in-out infinite; }
#marker .dist { position: absolute; left: -30px; top: -46px; width: 60px; text-align: center; font-size: 13px; color: var(--gold2); text-shadow: 0 1px 2px #000; }
#marker.edge .arrow { animation: none; }
@keyframes bob { 50% { margin-top: -6px; } }
#toast { position: fixed; top: 18%; left: 50%; transform: translateX(-50%); padding: 10px 20px; background: rgba(20, 12, 6, 0.78); border: 1px solid var(--gold); border-radius: 6px; font-size: 18px; }
#pause-btn { position: fixed; top: 14px; right: 14px; width: 40px; height: 40px; border-radius: 50%; border: 1px solid rgba(217, 164, 65, 0.6); background: rgba(20, 12, 6, 0.55); color: var(--gold2); font-weight: bold; cursor: pointer; z-index: 5; }
/* Sound on/off, always visible next to the pause button (also M, and in the menus).
   Layered above the title, pause, journal and chapter screens so it works everywhere. */
#sound-btn { position: fixed; top: 14px; right: 62px; width: 40px; height: 40px; border-radius: 50%; border: 1px solid rgba(217, 164, 65, 0.6); background: rgba(20, 12, 6, 0.55); color: var(--gold2); cursor: pointer; z-index: 46; display: grid; place-items: center; padding: 0; }
#sound-btn svg { width: 20px; height: 20px; }
#sound-btn .off, #sound-btn.muted .on { display: none; }
#sound-btn.muted .off { display: block; }
#sound-btn.muted { color: #d98a7a; }
#sound-btn:focus-visible, #pause-btn:focus-visible { outline: 2px solid var(--gold2); outline-offset: 2px; }

#minimap { position: fixed; top: 62px; right: 14px; width: 170px; height: 170px; border-radius: 50%; box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5); pointer-events: none; z-index: 4; }
#minimap canvas { display: block; width: 100%; height: 100%; border-radius: 50%; }
#minimap .north { position: absolute; top: -9px; left: 50%; transform: translateX(-50%); padding: 0 5px; font-size: 12px; font-weight: bold; color: #2a1a10; background: var(--gold2); border-radius: 8px; }

/* ------------------------------------------------ dialogue */
#dialogue { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); width: min(820px, calc(100vw - 32px)); padding: 16px 22px 14px; background: linear-gradient(var(--parch), var(--parch2)); color: var(--ink); border-radius: 6px; box-shadow: var(--shadow), inset 0 0 0 2px rgba(120, 80, 30, 0.35); z-index: 10; }
.d-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
#d-name { font-weight: bold; font-size: 19px; color: var(--red); }
#d-title { font-size: 13px; font-style: italic; color: #6a4a2a; }
#d-text { margin: 0; font-size: 19px; line-height: 1.45; min-height: 2.9em; }
.d-more { position: absolute; right: 16px; bottom: 8px; font-size: 13px; color: #7a5a2a; opacity: 0; transition: opacity 0.2s; }
#dialogue.done .d-more { opacity: 1; animation: pulse 1.2s infinite; }
#dialogue[data-who="yusuf"] #d-name { color: #2a5a6a; }
#dialogue[data-who="sultan"] #d-name { color: #2f6a3a; }
@keyframes pulse { 50% { opacity: 0.4; } }

/* ------------------------------------------------ history card */
#card { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(10, 6, 2, 0.55); z-index: 20; padding: 16px; }
.card-inner { width: min(640px, 100%); max-height: 90vh; overflow: auto; padding: 28px 32px 22px; background: linear-gradient(#f6ebd0, #ead9b2); color: var(--ink); border-radius: 6px; box-shadow: var(--shadow), inset 0 0 0 6px rgba(160, 110, 40, 0.18), inset 0 0 0 7px rgba(120, 80, 30, 0.5); }
#card-kicker { font-size: 12px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--red); }
#card-title { margin: 6px 0 12px; font-size: 28px; }
#card-text { margin: 0; font-size: 18px; line-height: 1.55; }
.card-more { margin-top: 16px; text-align: right; font-size: 14px; color: #7a5a2a; animation: pulse 1.4s infinite; }

/* ------------------------------------------------ chapter title */
#chapter { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; background: radial-gradient(ellipse at center, rgba(30, 18, 8, 0.92), rgba(5, 3, 1, 0.98)); z-index: 45; opacity: 0; transition: opacity 0.5s; }
#chapter.in { opacity: 1; }
.ch-n { font-size: 14px; letter-spacing: 0.3em; text-transform: uppercase; color: var(--gold); }
.ch-title { margin: 10px 0 6px; font-size: clamp(34px, 6vw, 64px); font-weight: normal; color: var(--text); text-shadow: 0 0 30px rgba(217, 164, 65, 0.35); }
.ch-when { font-size: 18px; font-style: italic; color: var(--gold2); }
.ch-card { margin-top: 28px; font-size: 13px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--gold); }
.ch-text { max-width: 640px; margin: 8px 0 0; font-size: 18px; line-height: 1.6; color: #e8dcc4; }
.ch-more { margin-top: 26px; font-size: 14px; color: var(--gold); animation: pulse 1.4s infinite; }

#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity 0.6s; z-index: 40; }
#fade.on { opacity: 1; }

/* ------------------------------------------------ duel HUD */
#duel-hud { position: fixed; inset: 0; pointer-events: none; z-index: 6; }
#duel-hud .side { position: absolute; top: 18px; width: min(40vw, 420px); }
#duel-hud .p1 { left: 18px; }
#duel-hud .p2 { right: 18px; text-align: right; }
#duel-hud .name { font-size: 18px; font-weight: bold; text-shadow: 0 2px 3px #000; margin-bottom: 4px; letter-spacing: 0.04em; }
#duel-hud .bar { position: relative; height: 18px; background: rgba(0, 0, 0, 0.55); border: 2px solid rgba(242, 201, 106, 0.85); border-radius: 3px; overflow: hidden; transform: skewX(-14deg); }
#duel-hud .p2 .bar { transform: skewX(14deg); }
#duel-hud .bar div { position: absolute; top: 0; bottom: 0; }
#duel-hud .p1 .bar div { left: 0; }
#duel-hud .p2 .bar div { right: 0; }
#duel-hud .lag { background: #d84a2a; }
#duel-hud .hp { background: linear-gradient(#f6d77a, #d9a441); transition: width 0.05s; }
#duel-hud .bar.low .hp { background: linear-gradient(#ff8a5a, #c83a1a); }
#duel-hud .pips { margin-top: 6px; display: flex; gap: 6px; }
#duel-hud .p2 .pips { justify-content: flex-end; }
#duel-hud .pips i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--gold2); background: rgba(0, 0, 0, 0.4); }
#duel-hud .pips i.won { background: var(--gold2); box-shadow: 0 0 8px var(--gold2); }
#duel-hud .spirit-box { position: relative; margin-top: 6px; width: 60%; height: 10px; background: rgba(0, 0, 0, 0.5); border: 1px solid #a07a30; border-radius: 6px; overflow: hidden; }
#duel-hud .spirit { height: 100%; background: linear-gradient(90deg, #8a3a10, #f2a030); }
#duel-hud .spirit-box span { position: absolute; right: 6px; top: -1px; font-size: 9px; letter-spacing: 0.2em; color: rgba(255, 255, 255, 0.6); }
#duel-hud .spirit-box.full { box-shadow: 0 0 12px #ffb040; animation: pulse 0.6s infinite; }
#duel-hud .timer { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); font-size: 34px; font-weight: bold; color: var(--gold2); text-shadow: 0 2px 4px #000; }
#duel-hud .announce { position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%) scale(0.6); font-size: clamp(44px, 9vw, 96px); font-weight: bold; letter-spacing: 0.06em; color: var(--gold2); text-shadow: 0 0 24px rgba(255, 150, 40, 0.8), 0 4px 6px #000; opacity: 0; transition: transform 0.18s ease-out, opacity 0.18s; white-space: nowrap; }
#duel-hud .announce.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#duel-hud .announce.small { font-size: clamp(26px, 5vw, 46px); color: #ffe0a0; }
#duel-hud .moves { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; width: min(900px, 96vw); font-size: 13px; color: rgba(255, 247, 230, 0.8); text-shadow: 0 1px 2px #000; }
#duel-hud .moves b { color: var(--gold2); }

/* ------------------------------------------------ rocket HUD */
#rocket-hud { position: fixed; inset: 0; pointer-events: none; z-index: 6; }
#rocket-hud .vignette { position: absolute; inset: 0; background: radial-gradient(circle at center, transparent 0 34%, rgba(0, 0, 0, 0.94) 35%); opacity: 0; transition: opacity 0.2s; }
#rocket-hud.zoom .vignette { opacity: 1; }
#rocket-hud .cross { position: absolute; left: 50%; top: 50%; width: 30px; height: 30px; transform: translate(-50%, -50%); }
#rocket-hud .cross i { position: absolute; background: rgba(255, 240, 200, 0.85); box-shadow: 0 0 3px #000; }
#rocket-hud .cross i:first-child { left: 14px; top: 0; width: 2px; height: 30px; }
#rocket-hud .cross i:last-child { top: 14px; left: 0; height: 2px; width: 30px; }
#rocket-hud .readout { position: absolute; left: 18px; bottom: 18px; padding: 10px 14px; background: rgba(20, 12, 6, 0.6); border-left: 3px solid var(--gold); border-radius: 4px; font-size: 17px; line-height: 1.5; min-width: 180px; }
#rocket-hud .k { display: inline-block; width: 86px; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold2); }
#rocket-hud .wind { display: inline-block; color: #bfe3ff; }
#rocket-hud .wind-s { margin-left: 8px; font-size: 14px; }
#rocket-hud .ammo { position: absolute; right: 18px; bottom: 18px; display: flex; gap: 5px; }
#rocket-hud .ammo i { width: 7px; height: 34px; border-radius: 3px; background: linear-gradient(#5a5654 0 30%, #c8b06a 30%); box-shadow: 0 0 2px #000; }
#rocket-hud .ammo i.spent { opacity: 0.2; }
#rocket-hud .goal { position: absolute; top: 16px; left: 16px; padding: 10px 14px; background: rgba(20, 12, 6, 0.62); border-left: 3px solid var(--gold); border-radius: 4px; font-size: 16px; max-width: min(460px, 70vw); line-height: 1.4; }
#rocket-hud .goal b { color: var(--gold2); }
#rocket-hud .time { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); font-size: 30px; font-weight: bold; color: var(--gold2); text-shadow: 0 2px 4px #000; }
#rocket-hud .integrity { position: absolute; top: 20px; right: 70px; display: flex; align-items: center; gap: 8px; font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold2); }
#rocket-hud .integrity b { display: block; width: 160px; height: 12px; background: rgba(0, 0, 0, 0.5); border: 1px solid var(--gold); border-radius: 3px; overflow: hidden; }
#rocket-hud .integrity i { display: block; height: 100%; background: linear-gradient(90deg, #c8b49a, #f0dcc0); }
#rocket-hud .reload { position: absolute; left: 50%; top: 58%; transform: translateX(-50%); font-size: 15px; font-style: italic; color: rgba(255, 240, 210, 0.8); text-shadow: 0 1px 2px #000; }
#rocket-hud .hint { position: absolute; left: 50%; bottom: 90px; transform: translateX(-50%); padding: 8px 16px; max-width: min(640px, 92vw); text-align: center; background: rgba(20, 12, 6, 0.72); border: 1px solid rgba(217, 164, 65, 0.6); border-radius: 8px; font-size: 16px; line-height: 1.4; }
#rocket-hud .hint b { color: var(--gold2); }

/* ------------------------------------------------ title, pause, journal */
#title { position: fixed; inset: 0; display: flex; align-items: center; justify-content: flex-start; padding: 6vh 7vw; background: linear-gradient(90deg, rgba(12, 7, 3, 0.85), rgba(12, 7, 3, 0.35) 55%, transparent); z-index: 25; }
.t-inner { max-width: 520px; }
.t-kicker { font-size: 14px; letter-spacing: 0.32em; text-transform: uppercase; color: var(--gold); }
#title h1 { margin: 10px 0 8px; font-size: clamp(46px, 8vw, 86px); line-height: 0.95; font-weight: normal; color: var(--text); text-shadow: 0 0 40px rgba(217, 164, 65, 0.4); }
#title h1 span { font-style: italic; font-size: 0.55em; color: var(--gold2); }
.t-sub { margin: 0 0 26px; font-size: 18px; line-height: 1.5; color: #e8dcc4; }
.t-foot { margin-top: 26px; font-size: 13px; color: rgba(255, 247, 230, 0.6); }
.menu { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.menu button { min-width: 240px; padding: 11px 20px; font-size: 19px; text-align: left; color: var(--text); background: rgba(30, 18, 8, 0.6); border: 1px solid rgba(217, 164, 65, 0.55); border-radius: 4px; cursor: pointer; transition: background 0.15s, border-color 0.15s, transform 0.15s; }
.menu button:hover, .menu button:focus-visible { background: rgba(120, 70, 20, 0.6); border-color: var(--gold2); transform: translateX(4px); outline: none; }
.menu button:disabled { opacity: 0.4; cursor: default; transform: none; }
#pause, #journal, #help { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(8, 5, 2, 0.72); z-index: 28; padding: 16px; }
.p-inner { padding: 26px 34px; background: rgba(30, 18, 8, 0.92); border: 1px solid var(--gold); border-radius: 6px; box-shadow: var(--shadow); }
.p-inner h2, .j-inner h2 { margin: 0 0 16px; font-weight: normal; font-size: 30px; color: var(--gold2); }
.j-inner { width: min(860px, 100%); max-height: 88vh; overflow: auto; padding: 26px 32px; background: linear-gradient(#f6ebd0, #ead9b2); color: var(--ink); border-radius: 6px; box-shadow: var(--shadow); }
.j-inner h2 { color: var(--red); }
.j-inner article { padding: 12px 0; border-top: 1px solid rgba(120, 80, 30, 0.3); }
.j-inner h3 { margin: 0 0 4px; font-size: 20px; }
.j-inner p { margin: 0 0 6px; font-size: 16px; line-height: 1.5; }
.j-inner .empty { font-style: italic; }
.j-inner .close { margin-top: 14px; padding: 8px 22px; font-size: 16px; border: 1px solid #8a6a3a; background: #f8efd8; border-radius: 4px; cursor: pointer; }
.help-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.help-cols b { color: var(--red); }

/* ------------------------------------------------ touch */
#touch { display: none; }
body.touch #touch { display: block; position: fixed; inset: 0; pointer-events: none; z-index: 8; }
#touch .stick { position: absolute; left: 22px; bottom: 26px; width: 130px; height: 130px; border-radius: 50%; background: rgba(20, 12, 6, 0.35); border: 2px solid rgba(242, 201, 106, 0.45); pointer-events: auto; touch-action: none; }
#touch .knob { position: absolute; left: 40px; top: 40px; width: 50px; height: 50px; border-radius: 50%; background: rgba(242, 201, 106, 0.55); }
#touch .btns { position: absolute; right: 16px; bottom: 22px; display: none; flex-wrap: wrap-reverse; justify-content: flex-end; gap: 10px; width: 230px; }
#touch button { pointer-events: auto; touch-action: none; width: 66px; height: 66px; border-radius: 50%; border: 2px solid rgba(242, 201, 106, 0.6); background: rgba(20, 12, 6, 0.5); color: var(--text); font-size: 14px; }
#touch button.on { background: rgba(217, 164, 65, 0.6); }
body.touch.mode-explore .explore-btns, body.touch.mode-duel .duel-btns, body.touch.mode-rocket .rocket-btns { display: flex; }
body.touch.mode-duel #touch .b-special { border-color: #ffb040; }
body.touch #duel-hud .moves { display: none; }
body.touch #dialogue { bottom: 170px; }
@media (max-width: 640px) {
  #minimap { width: 118px; height: 118px; top: 60px; right: 10px; }
  #d-text { font-size: 17px; }
  #objective { font-size: 14px; top: 10px; left: 10px; }
  #duel-hud .name { font-size: 14px; }
  #duel-hud .timer { font-size: 26px; }
  #card-title { font-size: 22px; }
  #card-text, .ch-text { font-size: 16px; }
  #rocket-hud .readout { font-size: 14px; min-width: 0; bottom: 170px; }
  #rocket-hud .integrity { top: 64px; right: 16px; }
  .menu button { min-width: 200px; font-size: 17px; }
}
