:root { font-family: Segoe UI, Arial, sans-serif; color: #ece9da; background: #111e22; font-synthesis: none; }
* { box-sizing: border-box; }
html { height: 100%; overflow: hidden; }
body { margin: 0 auto; padding: 14px 20px; max-width: 1800px; height: 100vh; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 10px; overflow: hidden; }
header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.eyebrow { font-size: 10px; letter-spacing: 2px; color: #b9bdab; font-weight: 700; }
h1 { font-family: Georgia, serif; font-size: 28px; margin: 3px 0 0; }
h1 span { color: #e9bb65; }
#castle-title { color: inherit; }
.battle-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.battle-actions button { font-size: 12px; padding: 9px 6px; line-height: 1.4; }
.battle-actions span { display: block; margin-top: 5px; font-size: 10px; font-weight: 400; }
#raid { background: #446f67; border-color: #7cac94; color: #f4f0d9; }
#raid:hover { background: #548377; }
#retreat { margin-top: 9px; border-color: #d5b073; color: #f4d79c; }
[hidden] { display: none !important; }
dialog { width: min(540px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow-y: auto; padding: 22px; color: #ece9da; background: #192d31; border: 1px solid #687d69; border-radius: 16px; box-shadow: 0 20px 80px #0008; }
dialog::backdrop { background: #091417bb; backdrop-filter: blur(3px); }
.settings-heading { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.settings-heading h2 { margin: 6px 0 0; font-family: Georgia, serif; font-size: 24px; }
dialog p { font-size: 13px; line-height: 1.5; color: #c3d0c5; }
.save-panel { padding: 14px; margin: 14px 0; border: 1px solid #425a57; border-radius: 10px; background: #22383b; }
.save-panel h3 { font-size: 15px; margin: 0 0 10px; }
.save-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.save-actions button { font-size: 13px; min-height: 44px; }
.save-note { margin-bottom: 0; font-size: 11px; color: #aabeb2; }
.save-confirmation { padding: 12px; border: 1px solid #d2ae6b; border-radius: 10px; }
.save-confirmation p { color: #f1d5a3; margin-top: 0; }
#save-message { min-height: 20px; color: #c5e9ac; }
#save-message.error { color: #ffba9e; }
#restart { margin-top: 10px; }
@media (max-width: 500px) { dialog { padding: 14px; } .settings-heading h2 { font-size: 21px; } .save-panel { padding: 10px; } }
main { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; min-height: 0; }
.game { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; gap: 8px; min-width: 0; min-height: 0; }
.resources { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.resource { display: flex; align-items: center; justify-content: space-between; gap: 6px; background: #203238; border: 1px solid #3b4b49; border-radius: 9px; padding: 10px 12px; color: #c1caba; font-size: 12px; }
.resource b { font-size: 23px; color: #f2e9cf; font-variant-numeric: tabular-nums; }
.command-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #263b3c; border: 1px solid #526354; border-radius: 9px; padding: 5px 10px; min-height: 40px; font-size: 12px; color: #f0cf8d; }
.command-bar button { color: #f4e3bd; border-color: #a48b59; padding: 6px 8px; }
.command-bar [hidden] { display: none; }
/* Fit the entire 3:2 map to BOTH dimensions of its available area. */
.map-viewport { min-width: 0; min-height: 0; container-type: size; display: flex; align-items: center; justify-content: center; background: #15282a; border-radius: 12px; }
.map-wrap { box-sizing: content-box; width: min(calc(100cqw - 2px), calc(150cqh - 3px)); aspect-ratio: 3 / 2; flex: none; position: relative; border-radius: 12px; overflow: hidden; border: 1px solid #63755c; background: #718763; }
canvas { display: block; width: 100%; height: 100%; touch-action: manipulation; cursor: crosshair; }
.map-badge { position: absolute; top: 10px; left: 10px; pointer-events: none; background: #162b26db; border: 1px solid #87977c66; border-radius: 6px; padding: 7px 10px; font-size: 9px; letter-spacing: 1px; }
.map-badge span { color: #e9bb65; padding: 0 5px; }
.status { display: flex; justify-content: space-between; align-items: start; gap: 12px; padding: 5px 2px; min-height: 40px; max-height: 64px; overflow-y: auto; font-size: 12px; line-height: 1.4; color: #d5dcca; }
#wave { white-space: nowrap; color: #e9bb65; }
aside { min-width: 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; scrollbar-color: #7d927e #1c2d32; padding: 2px 5px 2px 2px; }
.panel { padding: 14px; background: #1c2d32; border: 1px solid #34464a; border-radius: 12px; margin-bottom: 10px; }
.panel:last-child { margin-bottom: 0; }
.rival-panel { border-color: #75634c; }
.rival-stats { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.rival-stats strong { color: #edc785; }
#rival-progress { display: block; width: 100%; height: 8px; margin: 10px 0; accent-color: #d9ac5f; }
#rival-clock { font-size: 12px; color: #e7c88e; font-variant-numeric: tabular-nums; }
h2 { font-size: 15px; margin: 0 0 10px; }
button { font: inherit; cursor: pointer; color: #ece9da; background: #2b3e41; border: 1px solid #4b5d59; border-radius: 7px; padding: 10px; transition: background .15s; }
button:hover { background: #3d5353; }
button:focus-visible, aside:focus-visible { outline: 3px solid #ffe0a0; outline-offset: -3px; }
button:disabled { opacity: .45; cursor: default; }
.quiet { background: transparent; font-size: 12px; }
.primary { width: 100%; background: #d9ac5f; color: #202c2b; border-color: #ebc981; font-weight: 700; }
.primary:hover { background: #efc879; }
#timer { font-size: 34px; font-variant-numeric: tabular-nums; font-weight: 600; margin: 4px 0 10px; }
.panel p { font-size: 12px; line-height: 1.5; color: #aebdb8; margin: 10px 0 0; }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.tools button { text-align: left; font-size: 13px; min-height: 50px; }
.tools span { display: block; font-size: 10px; margin-top: 5px; color: #b5c3b8; }
.tools .active { border-color: #e4b86d; background: #4b4a35; }
.full { width: 100%; }
#workers { margin-top: 8px; }
#selection { font-size: 12px; color: #e7c88e; padding: 12px 0; }
#shelter-status { font-size: 13px; line-height: 1.6; color: #e7c88e; }
[data-tool="demolish"] { border-color: #896356; }
summary { cursor: pointer; font-size: 14px; font-weight: 600; }
ol { padding-left: 18px; font-size: 12px; line-height: 1.7; color: #b7c6bd; margin-bottom: 0; }
li + li { margin-top: 6px; }
footer { display: flex; justify-content: space-between; gap: 10px; color: #849891; font-size: 10px; }
footer span { color: #b9ae8b; }
@media (max-width: 1100px) {
  body { padding: 10px 12px; }
  main { grid-template-columns: minmax(0, 1fr) 270px; gap: 10px; }
  .resource { flex-wrap: wrap; padding: 7px 9px; }
  .resource b { font-size: 21px; }
}
@media (max-width: 700px) and (orientation: portrait), (max-width: 700px) and (min-height: 501px) {
  body { padding: 8px; gap: 7px; }
  h1 { font-size: 23px; }
  header .eyebrow { font-size: 8px; letter-spacing: 1px; }
  main { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1.2fr) minmax(0, 1fr); gap: 8px; }
  .game { gap: 5px; }
  .resources { gap: 4px; }
  .resource { font-size: 10px; padding: 5px 7px; gap: 2px; }
  .resource b { font-size: 18px; }
  .command-bar { min-height: 36px; font-size: 11px; }
  .command-bar button { font-size: 10px; }
  .status { min-height: 32px; max-height: 48px; font-size: 11px; }
  .map-badge { top: 5px; left: 5px; font-size: 6px; padding: 5px; }
  aside { border-top: 1px solid #526354; padding-top: 8px; }
  footer { font-size: 9px; }
  footer > span { display: none; }
}
@media (max-height: 600px) and (min-width: 701px), (max-height: 500px) and (orientation: landscape) {
  body { padding: 6px 10px; gap: 6px; grid-template-rows: auto minmax(0, 1fr); }
  header .eyebrow, footer { display: none; }
  h1 { font-size: 22px; margin: 0; }
  header button { padding: 6px 10px; }
  main { grid-template-columns: minmax(0, 1fr) 250px; gap: 8px; }
  .game { gap: 5px; }
  .resource { padding: 4px 7px; font-size: 10px; }
  .resource b { font-size: 18px; }
  .command-bar { min-height: 32px; padding: 3px 7px; font-size: 11px; }
  .command-bar button { font-size: 10px; padding: 4px; }
  .status { min-height: 30px; max-height: 42px; font-size: 11px; }
  .map-badge { top: 4px; left: 4px; font-size: 6px; padding: 4px; }
}
@media (max-width: 700px) and (max-height: 650px) and (orientation: portrait) {
  body { grid-template-rows: auto minmax(0, 1fr); gap: 5px; }
  header .eyebrow, footer { display: none; }
  h1 { font-size: 20px; }
  header button { padding: 7px; }
  main { grid-template-rows: minmax(0, 1fr) 120px; }
  .resource { flex-direction: column; align-items: start; padding: 3px 6px; font-size: 9px; }
  .resource b { font-size: 16px; }
  .command-bar { min-height: 32px; }
}
