:root {
  color-scheme: dark;
  --ink: #241b24;
  --panel: #f4e5bd;
  --panel-2: #fff5d8;
  --wine: #713848;
  --red: #c94f48;
  --gold: #f2c65a;
  --green: #8ecb73;
  --blue: #76c8dd;
  --shadow: 0 18px 44px rgba(22, 13, 23, .35);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #2b2430; color: #fff9e7; font-family: Inter, ui-rounded, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, a { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .52; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 4px solid #fff; outline-offset: 3px; }
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 200; background: #fff; color: #111; padding: .8rem 1rem; border-radius: .5rem; }
.skip-link:focus { top: 1rem; }
.game-shell { min-height: 100vh; display: grid; grid-template-rows: auto auto 1fr; }
.topbar { min-height: 58px; padding: .55rem clamp(.75rem, 2vw, 1.5rem); display: grid; grid-template-columns: 1fr minmax(220px, 420px) 1fr; align-items: center; gap: 1rem; background: #201a24; border-bottom: 3px solid #513d54; }
.back-link { color: #ffe6a6; font-weight: 900; text-decoration: none; letter-spacing: .02em; }
.siege-clock { text-align: center; font-variant-numeric: tabular-nums; }
.siege-clock > span { display: block; font-family: Georgia, serif; font-size: 1.45rem; font-weight: 900; line-height: 1; }
.progress-track { --progress: 0%; height: 8px; margin-top: .35rem; overflow: hidden; background: #0f0c11; border: 1px solid #6a556c; border-radius: 99px; }
.progress-track i { display: block; width: var(--progress); height: 100%; background: linear-gradient(90deg, #8fca71, #f2c65a, #d85a4b); transition: width .25s linear; }
.top-actions { justify-self: end; display: flex; gap: .45rem; }
.top-actions button { border: 2px solid #8e718e; border-radius: 999px; background: #392d3d; color: #fff6df; padding: .55rem .9rem; font-weight: 900; }
.resource-bar { display: grid; grid-template-columns: repeat(7, minmax(78px, 1fr)); gap: 2px; background: #120f15; border-bottom: 2px solid #4f3e51; }
.resource-bar > div { min-height: 52px; padding: .45rem .65rem; display: flex; align-items: baseline; justify-content: center; gap: .4rem; background: #302735; }
.resource-bar span { color: #cdbed0; font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.resource-bar strong { font-size: 1.05rem; color: #fff6d8; font-variant-numeric: tabular-nums; }
.resource-bar .resource-soup { background: #5a3e29; }
.resource-bar .resource-soup strong { color: #ffd765; }
.play-layout { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 360px); }
.castle-stage { position: relative; min-height: 0; overflow: hidden; background: #382f3d; }
#game-canvas { position: absolute; inset: 0; }
#game-canvas canvas { display: block; width: 100% !important; height: 100% !important; }
.briefing { position: absolute; z-index: 100; left: 50%; top: 50%; width: min(580px, calc(100% - 2rem)); transform: translate(-50%, -50%) rotate(-.4deg); padding: clamp(1.25rem, 3vw, 2.2rem); color: var(--ink); background: var(--panel-2); border: 5px solid #2d222b; border-radius: 18px; box-shadow: var(--shadow); }
.briefing::before { content: ""; position: absolute; inset: 9px; pointer-events: none; border: 2px dashed #c59151; border-radius: 11px; }
.briefing > * { position: relative; }
.kicker, .panel-label { margin: 0 0 .35rem; color: #963f3f; font-size: .72rem; font-weight: 1000; letter-spacing: .14em; text-transform: uppercase; }
.briefing h1 { margin: 0 0 .7rem; font: 900 clamp(2rem, 5vw, 3.4rem)/.94 Georgia, serif; letter-spacing: -.04em; }
.briefing p { line-height: 1.5; }
.briefing ul { padding-left: 1.15rem; line-height: 1.45; }
.primary-button { border: 3px solid #2a2027; border-radius: 12px; background: var(--gold); color: #251d20; padding: .85rem 1.1rem; font-weight: 1000; box-shadow: 0 5px 0 #8f5f2c; }
.primary-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #8f5f2c; }
.command-panel { min-height: 0; overflow: auto; padding: .75rem; background: #231c27; border-left: 3px solid #523e54; }
.panel-card { margin-bottom: .65rem; padding: .85rem; color: var(--ink); background: var(--panel); border: 3px solid #3a2935; border-radius: 14px; box-shadow: 0 7px 0 #151117; }
.panel-card h2 { margin: 0; font: 900 1.45rem/1 Georgia, serif; }
.panel-card p { margin: .45rem 0 .75rem; font-size: .88rem; line-height: 1.4; }
.action-list { display: grid; gap: .4rem; }
.job-button, .soup-button { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: .6rem; text-align: left; border: 2px solid #4a3541; border-radius: 10px; padding: .62rem .72rem; color: #241b21; background: #fff8df; }
.job-button strong, .soup-button strong { font-size: .92rem; }
.job-button span, .soup-button span { color: #6f5360; font-size: .7rem; font-weight: 800; }
.soup-button { margin-top: .45rem; background: #ffd457; }
.empty-action { padding: .7rem; border: 2px dashed #9e7e67; border-radius: 9px; color: #6d5557; font-size: .78rem; line-height: 1.35; }
.staff-list { display: grid; gap: .4rem; }
.staff-card { width: 100%; display: grid; grid-template-columns: 24px 18px 1fr; align-items: center; gap: .5rem; padding: .48rem; text-align: left; color: #2d2227; background: #fff7dc; border: 2px solid transparent; border-radius: 10px; }
.staff-card.selected { border-color: #963f3f; background: #fff; box-shadow: inset 5px 0 #963f3f; }
.staff-key { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; color: #fff; background: #3c2e38; font-weight: 900; }
.staff-dot { width: 16px; height: 16px; border: 3px solid #30232b; border-radius: 50%; background: var(--staff); }
.staff-card strong, .staff-card small, .staff-card em { display: block; }
.staff-card strong { font-size: .87rem; }
.staff-card small { color: #775f66; font-size: .68rem; }
.staff-card em { color: #963f3f; font-size: .68rem; font-style: normal; font-weight: 900; }
.alerts { display: grid; gap: .4rem; }
.alert { width: 100%; display: grid; grid-template-columns: auto 1fr; gap: .15rem .55rem; padding: .52rem; text-align: left; color: #2b2027; border: 2px solid #715563; border-radius: 9px; background: #fff8e8; }
.alert > span { grid-row: span 2; align-self: start; padding: .22rem .4rem; color: #fff; background: #6e4e5d; border-radius: 6px; font-size: .62rem; font-weight: 1000; text-transform: uppercase; }
.alert strong { font-size: .78rem; }
.alert small { color: #6d555d; font-size: .66rem; line-height: 1.25; }
.alert-incident { border-color: #b34843; background: #fff0d9; }
.alert-success { border-color: #5a9557; background: #eff7d9; }
.alert-warning { border-color: #c28b31; }
.result-overlay { position: fixed; z-index: 180; inset: 0; display: grid; place-items: center; padding: 1rem; background: rgba(19, 13, 20, .82); backdrop-filter: blur(8px); }
.result-overlay[hidden] { display: none; }
.result-card { position: relative; width: min(620px, 100%); padding: 2rem; color: var(--ink); background: var(--panel-2); border: 6px solid #2c2229; border-radius: 20px; box-shadow: var(--shadow); }
.result-grade { position: absolute; right: 1.5rem; top: -2.7rem; display: grid; place-items: center; width: 88px; height: 88px; color: #2b2225; background: var(--gold); border: 5px solid #2b2225; border-radius: 50%; font: 900 3.3rem/1 Georgia, serif; transform: rotate(7deg); }
.result-card h2 { margin: .2rem 0 .7rem; font: 900 2.3rem/1 Georgia, serif; }
.result-card p { line-height: 1.5; }
.result-actions { margin-top: 1.4rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.result-actions a { color: #713848; font-weight: 900; }
.settings-dialog { width: min(620px, calc(100% - 2rem)); padding: 0; color: var(--ink); background: var(--panel-2); border: 5px solid #2e232c; border-radius: 18px; box-shadow: var(--shadow); }
.settings-dialog::backdrop { background: rgba(20, 14, 21, .82); backdrop-filter: blur(6px); }
.settings-dialog form { padding: 1.2rem; }
.settings-dialog header { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: .7rem; }
.settings-dialog h2 { margin: 0; font: 900 2rem/1 Georgia, serif; }
.settings-dialog header button { width: 38px; height: 38px; color: #fff; background: #432f3d; border: 0; border-radius: 50%; font-size: 1.6rem; }
.settings-dialog label { display: flex; gap: .7rem; margin: .45rem 0; padding: .65rem; background: #fff9e8; border: 2px solid #ddc99d; border-radius: 10px; }
.settings-dialog input { width: 22px; height: 22px; accent-color: #8e3e45; }
.settings-dialog strong, .settings-dialog small { display: block; }
.settings-dialog small { margin-top: .15rem; color: #755e63; line-height: 1.3; }
.settings-dialog .primary-button { margin-top: .7rem; width: 100%; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.high-contrast .panel-card { background: #fff; }
.high-contrast .resource-bar > div { background: #111; }
@media (max-width: 980px) {
  .topbar { grid-template-columns: 1fr auto; }
  .siege-clock { grid-column: 1 / -1; grid-row: 2; }
  .play-layout { grid-template-columns: 1fr; grid-template-rows: minmax(430px, 62vh) auto; }
  .command-panel { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; border-left: 0; border-top: 3px solid #523e54; }
  .panel-card { margin: 0; }
  .alert-panel { grid-column: 1 / -1; }
  .alerts { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 650px) {
  .topbar { gap: .5rem; }
  .top-actions button { padding: .45rem .65rem; }
  .resource-bar { grid-template-columns: repeat(4, 1fr); }
  .resource-bar > div { min-height: 44px; padding: .35rem; flex-direction: column; gap: 0; align-items: center; }
  .resource-bar span { font-size: .58rem; }
  .play-layout { grid-template-rows: minmax(320px, 52vh) auto; }
  .command-panel { grid-template-columns: 1fr; }
  .alert-panel { grid-column: auto; }
  .alerts { grid-template-columns: 1fr; }
  .briefing h1 { font-size: 2rem; }
  .briefing ul { display: none; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .game-shell { grid-template-rows: auto auto 1fr; }
  .topbar { min-height: 42px; padding: .25rem .7rem; grid-template-columns: 1fr 250px 1fr; }
  .siege-clock { grid-column: auto; grid-row: auto; }
  .resource-bar > div { min-height: 34px; padding: .2rem .4rem; }
  .play-layout { grid-template-columns: minmax(0, 1fr) 300px; grid-template-rows: minmax(0, 1fr); }
  .command-panel { display: block; border-left: 3px solid #523e54; border-top: 0; padding: .4rem; }
  .panel-card { margin-bottom: .4rem; padding: .55rem; }
  .staff-panel, .alert-panel { display: none; }
  .briefing { width: min(520px, calc(100% - 1rem)); padding: 1rem 1.4rem; }
  .briefing p { margin: .4rem 0; }
  .briefing ul { display: none; }
}
