:root { --ink: #1f1a17; --paper: #f4ebda; --red: #9e3227; --maroon: #6e2a22; --gold: #f2c14e; --cream: #f7f3ea; --khaki: #6f7448; --panel: rgba(31, 26, 23, .78); }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; background: #1f1a17; color: var(--cream); font-family: Spectral, Georgia, serif; }
#game canvas { display: block; }
button { font-family: inherit; font-size: 16px; font-weight: 600; min-height: 44px; padding: 0 18px; border-radius: 8px; border: 0; background: var(--red); color: var(--cream); cursor: pointer; }
button:hover { background: #b23a2d; }
button.ghost { background: #e3d6bd; color: var(--ink); }
button.ghost:hover { background: #efe4cf; }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.box { background: var(--panel); border-radius: 12px; }
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button, #dialog { pointer-events: auto; }
#h-left { position: absolute; left: 20px; top: 18px; padding: 12px 16px; display: flex; flex-direction: column; gap: 5px; min-width: 240px; }
#h-zone { font-family: Anton, Impact, sans-serif; font-size: 26px; letter-spacing: 1px; line-height: 1.05; }
#h-sub { font-size: 14px; opacity: .92; }
.h-row { display: flex; gap: 16px; font-weight: 600; font-size: 15px; align-items: center; }
#h-money { color: var(--gold); }
.h-dis { display: flex; gap: 6px; align-items: center; }
.stam { height: 7px; border-radius: 4px; background: rgba(247, 243, 234, .22); overflow: hidden; }
#h-stam { height: 100%; background: #3c8a5a; border-radius: 4px; transition: width .1s; }
#h-right { position: absolute; right: 20px; top: 18px; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
#h-heat { display: flex; gap: 5px; padding: 7px 11px; }
.eye { width: 26px; height: 18px; color: rgba(247, 243, 234, .3); display: block; }
.eye svg { width: 26px; height: 18px; display: block; }
.eye.on { color: var(--gold); }
#h-heat.flash .eye.on { color: #ff6a4a; animation: blink .5s infinite alternate; }
@keyframes blink { to { color: var(--gold); } }
#minimap { width: 180px; height: 180px; border-radius: 50%; box-shadow: 0 0 0 4px var(--panel); }
#backend { font-size: 12px; opacity: .7; background: var(--panel); padding: 2px 8px; border-radius: 6px; }
#objective { position: absolute; left: 20px; bottom: 20px; width: 340px; padding: 12px 16px; display: flex; flex-direction: column; gap: 4px; }
#o-title { font-size: 13px; letter-spacing: 2px; color: var(--gold); font-weight: 600; }
#o-text { font-size: 16px; line-height: 1.4; }
#prompt { position: absolute; left: 50%; top: 62%; transform: translateX(-50%); background: rgba(31, 26, 23, .85); padding: 6px 14px; border-radius: 8px; font-size: 16px; white-space: nowrap; }
#prompt b { color: var(--gold); }
#progress { position: absolute; left: 50%; top: calc(62% + 40px); transform: translateX(-50%); width: 180px; height: 10px; background: rgba(31, 26, 23, .8); border-radius: 5px; overflow: hidden; }
#progress div { height: 100%; width: 0; background: var(--gold); }
#toasts { position: absolute; left: 50%; top: 18px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; width: min(560px, 90vw); }
.toast { background: rgba(31, 26, 23, .86); padding: 8px 14px; border-radius: 8px; font-size: 15px; line-height: 1.35; text-align: center; transition: opacity .6s, transform .6s; box-shadow: inset 3px 0 0 var(--gold); }
.toast.bad { box-shadow: inset 3px 0 0 #e0503a; }
.toast.good { box-shadow: inset 3px 0 0 #5bb57a; }
.toast.out { opacity: 0; transform: translateY(-6px); }
#banner { position: absolute; left: 0; right: 0; top: 30%; text-align: center; opacity: 0; transform: scale(.96); transition: opacity .4s, transform .4s; text-shadow: 0 3px 0 var(--ink), 0 0 18px rgba(0, 0, 0, .5); }
#banner.show { opacity: 1; transform: none; }
.b-title { font-family: Anton, Impact, sans-serif; font-size: 64px; color: var(--gold); letter-spacing: 1px; line-height: 1; }
.b-sub { font-size: 22px; margin-top: 6px; }
#arrow { position: absolute; left: 0; top: 0; width: 36px; height: 36px; }
#dialog { position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); width: min(680px, calc(100vw - 32px)); background: var(--paper); color: var(--ink); border-radius: 14px; padding: 16px 22px; box-shadow: 0 0 0 3px var(--red), 0 10px 30px rgba(0, 0, 0, .4); display: flex; flex-direction: column; gap: 10px; }
.d-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.d-name { font-family: Anton, Impact, sans-serif; font-size: 22px; letter-spacing: .5px; text-transform: uppercase; }
.d-role { font-size: 14px; color: var(--maroon); font-weight: 600; }
.d-text { font-size: 18px; line-height: 1.45; min-height: 52px; }
.d-choices { display: flex; flex-wrap: wrap; gap: 8px; }
.d-choices button { font-size: 15px; padding: 0 14px; }
.d-choices b { opacity: .7; margin-right: 4px; }

.overlay { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(20, 16, 14, .55); z-index: 5; padding: 16px; }
.overlay.show { display: flex; }
.overlay.dark { background: rgba(14, 10, 8, .88); }
.panel { background: var(--paper); color: var(--ink); border-radius: 16px; padding: 24px 28px; width: min(980px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 0 0 3px var(--red); }
.panel.small { width: min(560px, 100%); }
.panel h2 { font-family: Anton, Impact, sans-serif; font-weight: 400; font-size: 34px; margin: 0 0 14px; color: var(--maroon); letter-spacing: .5px; }
.panel h3 { margin: 14px 0 8px; font-size: 18px; }
.panel .hint { font-size: 14px; color: #5a4c40; margin: 14px 0 0; }
.panel .row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.dlist { display: flex; flex-direction: column; gap: 8px; }
.dlist button { display: flex; gap: 12px; text-align: left; align-items: center; padding: 10px 14px; background: #e9dcc4; color: var(--ink); font-weight: 400; }
.dlist button.cur { box-shadow: inset 0 0 0 2px var(--red); }
.dlist button:hover { background: #f1e6d2; }
.dlist strong { display: block; font-size: 17px; }
.dlist b { font-size: 20px; color: var(--red); }
.jcols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px; }
@media (max-width: 760px) { .jcols { grid-template-columns: 1fr; } }
.mlist { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.mlist li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 10px; border-radius: 6px; background: #ece2cf; font-size: 15px; }
.mlist li em { font-style: normal; color: #5a4c40; font-size: 14px; }
.mlist li.done { opacity: .7; }
.mlist li.done em { color: #2f6b4a; }
.mlist li.active { box-shadow: inset 0 0 0 2px var(--red); }
.mlist li.available em { color: var(--maroon); font-weight: 600; }
details { border-bottom: 1px solid rgba(31, 26, 23, .15); padding: 6px 0; }
summary { cursor: pointer; font-weight: 600; font-size: 16px; }
details p { font-size: 15px; line-height: 1.5; margin: 6px 0 4px; }
.panel.map canvas { width: 100%; height: auto; border-radius: 8px; image-rendering: pixelated; }
.help { display: grid; gap: 4px; font-size: 15px; line-height: 1.45; }
.busted, .ending { text-align: center; max-width: 640px; color: var(--cream); }
.busted p { font-size: 18px; line-height: 1.5; }
.panel.ending { background: transparent; box-shadow: none; color: var(--cream); text-align: left; }
.panel.ending p { font-size: 18px; line-height: 1.55; }
.panel.ending .hint { color: #c9bca5; }
#fade { position: fixed; inset: 0; background: #0e0b09; opacity: 0; pointer-events: none; transition: opacity .6s; z-index: 6; }
#fade.on { opacity: 1; }

#title { position: fixed; inset: 0; z-index: 10; background: var(--red); display: flex; flex-direction: column; overflow: auto; }
.flags { display: flex; height: 14px; flex: none; }
.flags i { flex: 1; }
.t-inner { margin: auto; padding: 32px 16px; width: min(860px, 100%); display: flex; flex-direction: column; gap: 14px; }
.t-tib { font-family: 'Noto Serif Tibetan', serif; font-size: 28px; color: var(--gold); }
#title h1 { margin: 0; font-family: Anton, Impact, sans-serif; font-weight: 400; font-size: clamp(48px, 10vw, 104px); line-height: .95; letter-spacing: 1px; }
.t-sub { margin: 0; font-size: 22px; font-style: italic; }
.t-intro { font-size: 18px; line-height: 1.55; margin: 6px 0; max-width: 680px; }
#t-buttons { display: flex; gap: 10px; }
#t-buttons button { font-size: 18px; min-height: 50px; padding: 0 28px; background: var(--gold); color: var(--ink); }
#t-buttons button.ghost { background: #e3d6bd; }
#t-status { font-size: 16px; min-height: 22px; }
#t-help { background: rgba(31, 26, 23, .35); border-radius: 12px; padding: 12px 16px; }
#t-help b { color: var(--gold); }
.panel .help b { color: var(--red); }
.t-note { font-size: 14px; opacity: .85; margin: 0; }

/* ---------------- touch controls ---------------- */
#touch { display: none; }
body.touch #touch { display: block; }
#game, #touch, #t-zone { touch-action: none; }
#t-zone { position: fixed; inset: 0; z-index: 2; }
body.blocked #touch { display: none; }
#stick { position: fixed; left: 0; top: 0; width: 112px; height: 112px; border-radius: 50%; background: rgba(31, 26, 23, .35); box-shadow: inset 0 0 0 3px rgba(247, 243, 234, .55); z-index: 3; pointer-events: none; }
#stick-knob { position: absolute; left: 31px; top: 31px; width: 50px; height: 50px; border-radius: 50%; background: rgba(242, 193, 78, .9); box-shadow: 0 2px 6px rgba(0, 0, 0, .35); }
#t-btns { position: fixed; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); z-index: 3; display: grid; grid-template-columns: repeat(2, 76px); gap: 10px; align-items: end; }
#t-btns button, #t-small button { touch-action: none; border-radius: 50%; padding: 0; min-height: 0; background: rgba(31, 26, 23, .7); color: var(--cream); box-shadow: inset 0 0 0 2px rgba(247, 243, 234, .45); font-size: 13px; letter-spacing: .5px; }
#t-btns button { width: 64px; height: 64px; justify-self: center; }
#t-btns button.big { width: 76px; height: 76px; font-size: 15px; background: rgba(158, 50, 39, .85); }
#t-btns button.gold { background: rgba(242, 193, 78, .92); color: var(--ink); }
#t-btns button.dim { opacity: .45; }
#t-btns button.down, #t-small button.down { transform: scale(.92); filter: brightness(1.25); }
#t-small { position: fixed; right: max(14px, env(safe-area-inset-right)); top: 50%; transform: translateY(-50%); z-index: 3; display: flex; flex-direction: column; gap: 8px; }
#t-small button { width: 44px; height: 44px; display: grid; place-items: center; }
#t-small svg { width: 22px; height: 22px; }
body.touch #prompt b { display: none; }
body.touch #objective { bottom: auto; top: 128px; left: 12px; width: min(300px, 46vw); padding: 8px 12px; }
body.touch #o-text { font-size: 14px; }
body.touch #dialog { bottom: max(12px, env(safe-area-inset-bottom)); }
@media (max-width: 900px), (max-height: 520px) {
  #h-left { left: 10px; top: 10px; padding: 8px 12px; min-width: 0; gap: 3px; }
  #h-zone { font-size: 19px; }
  #h-sub { font-size: 12px; }
  .h-row { font-size: 13px; gap: 10px; }
  #h-right { right: 10px; top: 10px; gap: 6px; }
  #minimap { width: 104px; height: 104px; }
  .eye, .eye svg { width: 18px; height: 13px; }
  #backend { display: none; }
  body.touch #objective { top: 104px; left: 10px; }
  #toasts { top: auto; bottom: 110px; }
  .toast { font-size: 13px; padding: 6px 10px; }
  .b-title { font-size: 40px; }
  .b-sub { font-size: 16px; }
  .d-text { font-size: 16px; min-height: 0; }
  #dialog { padding: 12px 14px; gap: 8px; }
  .panel { padding: 16px; }
  .panel h2 { font-size: 26px; }
  body.touch #t-small { top: 128px; transform: none; }
}
@media (max-height: 520px) {
  body.touch #t-small { top: 10px; right: 150px; flex-direction: row; transform: none; }
  #t-btns { grid-template-columns: repeat(4, auto); }
  body.touch #objective { width: min(280px, 40vw); }
}
@media (max-width: 600px) and (min-height: 521px) {
  body.touch #t-small { top: 160px; }
  body.touch #toasts { bottom: 200px; }
}
