/* Entry screen in the style of the original game's dialogs: a leather
   background inside the gold-and-blue dialog frame, gold plate buttons and
   the main menu artwork. The pictures themselves come from the player's
   downloaded game data (js/h3-art.js sets the --h3-* properties and the
   .h3-art class); until then the same layout is drawn with plain CSS. */
:root {
  color-scheme: dark;
  --ink: #ffffff;
  --muted: #e6dcc4;
  --gold: #f2d784;
  --gold-dark: #8a6a24;
  --frame-blue: #22388a;
  --leather: #4a2e17;
  --sidebar: 280px;
  /* Plain-CSS stand-ins for the original images. */
  --leather-fallback: radial-gradient(ellipse at 30% 20%, #6a4524 0, transparent 60%),
    radial-gradient(ellipse at 80% 90%, #5b3a1e 0, transparent 55%), linear-gradient(#4c2f17, #3a2312);
  --gold-plate: linear-gradient(#fff2b8, #e3c26a 18%, #c49a3e 50%, #a97f2b 82%, #6f4f16);
  font: 16px/1.45 Georgia, 'Times New Roman', Times, serif;
  color: var(--ink);
  background: #0b0907;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  min-height: 100vh;
  padding: 28px 20px;
  background: radial-gradient(ellipse at 50% 0, #3a1410 0, transparent 70%), #0b0907;
}
/* Behind the dialog: the main menu painting, blurred and darkened. */
.h3-art body:not(.playing) { background: transparent; }
.h3-art body::before {
  content: '';
  position: fixed;
  inset: -60px;
  z-index: -1;
  background: var(--h3-backdrop) 50% 30% / cover;
  filter: blur(18px) brightness(.32) saturate(1.2);
  pointer-events: none;
}
body.playing::before { display: none; }
button, input, select { font: inherit; }
button, input, select, summary, a { -webkit-tap-highlight-color: transparent; }
button, input:not([type=checkbox]), select { min-height: 44px; }

/* ---- buttons: the scenario screen's gold plate ("Begin") ------------------- */
button {
  padding: 8px 22px;
  color: #120c03;
  font-weight: bold;
  letter-spacing: .02em;
  border: 2px solid #5a4010;
  border-radius: 0;
  background: var(--gold-plate);
  box-shadow: inset 0 0 0 1px #fff3c066, inset 0 0 0 3px #7e5d1c, 1px 2px 0 #000;
  text-shadow: 0 1px 0 #f5df9f;
  cursor: pointer;
  line-height: 1.2;
}
button:hover:not(:disabled) { filter: brightness(1.12); }
button:active:not(:disabled) { box-shadow: inset 0 2px 6px #000a; transform: translateY(1px); }
button:disabled { color: #6a5a38; text-shadow: none; filter: saturate(.35) brightness(.8); cursor: default; }
.quiet {
  color: #f2d784;
  font-weight: normal;
  font-size: 14px;
  text-shadow: 1px 1px 0 #000;
  border-color: #b8913c;
  background: linear-gradient(#3b2614, #24160b);
  box-shadow: inset 0 0 0 1px #000, inset 0 0 0 2px #6c4f1d, 1px 2px 0 #000;
}
.quiet:disabled { color: #9a8a68; }
/* With the game data: the original button frames, stretched by their caps. */
.h3-art button {
  border-style: solid;
  border-width: 0 26px 0 27px;
  padding: 8px 4px;
  background: none;
  box-shadow: none;
  border-image: var(--h3-button) 0 26 0 27 fill / 0 26px 0 27px stretch;
}
.h3-art button:hover:not(:disabled) { filter: none; border-image-source: var(--h3-button-hover); }
.h3-art button:active:not(:disabled) { box-shadow: none; border-image-source: var(--h3-button-down); }
.h3-art button:disabled { filter: none; color: #5d4c26; border-image-source: var(--h3-button-off); }
.h3-art .quiet {
  border-width: 3px 9px;
  padding: 6px 6px;
  border-image: var(--h3-quiet-button) 3 9 fill / 3px 9px stretch;
}
.h3-art .quiet:hover:not(:disabled) { border-image-source: var(--h3-quiet-button-hover); }
.h3-art .quiet:active:not(:disabled) { border-image-source: var(--h3-quiet-button-down); }
.h3-art .quiet:disabled { color: #8a7a58; border-image-source: var(--h3-quiet-button-off); }

:focus-visible { outline: 2px solid #fff1b0; outline-offset: 3px; }
a { color: var(--gold); text-underline-offset: 4px; }
h1, h2, h3, p { margin: 0; }
h2, h3 { color: var(--gold); font-weight: bold; text-shadow: 1px 1px 0 #000, 0 0 6px #000; }
h2 { font-size: 22px; letter-spacing: .02em; }
h3 { font-size: 19px; }
p { margin: 8px 0; color: var(--muted); text-shadow: 1px 1px 0 #000; }
small, .small { font-size: 14px; }

/* ---- the dialog: leather inside the gold/blue frame ------------------------- */
#setup {
  max-width: 1080px;
  margin: 0 auto;
  position: relative;
  padding: 20px;
  border: 6px solid #e2bf62;
  outline: 1px solid #000;
  box-shadow: inset 0 0 0 2px #000, inset 0 0 0 6px var(--frame-blue), inset 0 0 0 8px #c9a24a,
    inset 0 0 0 9px #000, 0 0 0 2px #6d5218, 0 0 0 4px #000, 0 18px 60px #000;
  background: var(--leather-fallback);
}
.h3-art #setup {
  padding: 0;
  /* The frame tiles are 64px, but their band is only 14-16px deep. */
  border: 16px solid transparent;
  border-image: var(--h3-frame) 64 / 64px round;
  outline: 0;
  box-shadow: 0 0 0 1px #000, 0 18px 60px #000;
  background: var(--h3-parchment) 0 0 / 256px repeat border-box;
}

/* ---- title: the game's logo art once available ------------------------------- */
.castle-banner {
  min-height: 170px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  padding: 22px 24px 18px;
  border: 2px solid #000;
  box-shadow: 0 0 0 1px #b8913c, inset 0 0 40px #000;
  background: radial-gradient(ellipse at 50% 120%, #7a2416 0, transparent 70%), linear-gradient(#170c08, #2a120c);
}
.h3-art .castle-banner {
  min-height: 320px;
  justify-content: flex-end;
  align-items: flex-end;
  text-align: right;
  background: linear-gradient(270deg, #0008, transparent 40%), var(--h3-backdrop) 0 0 / cover no-repeat, #000;
}
.brand { text-shadow: 0 2px 2px #000, 0 0 14px #000; }
h1 {
  font: bold clamp(34px, 6vw, 64px)/1 'Times New Roman', Times, Georgia, serif;
  letter-spacing: .02em;
  color: #f8e3a0;
  background: linear-gradient(#fffbe6, #f4dc8c 35%, #c79a3a 60%, #f5dd92 80%, #9c7426);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(2px 3px 0 #000);
  text-shadow: none;
}
h1 span { display: block; font-size: .32em; line-height: 1.6; letter-spacing: .14em; text-transform: uppercase; }
.edition { margin: 8px 0 0; color: var(--gold); font-size: 15px; letter-spacing: .06em; }
/* The artwork carries the logo; keep the heading for assistive technology. */
.h3-art h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.h3-art .edition { font-size: 14px; }

/* ---- menu --------------------------------------------------------------------- */
.menu-content { display: flex; flex-direction: column; padding: 24px 24px 18px; }
.play-options { display: grid; grid-template-columns: .9fr 1.25fr; gap: 26px; }
.menu-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px solid #b8913c80; }
.menu-number { display: grid; place-items: center; width: 30px; height: 30px; flex: 0 0 30px; color: #120c03; font-weight: bold; font-size: 15px; border: 1px solid #000; background: var(--gold-plate); box-shadow: inset 0 0 0 1px #fff3c066; }
.menu-copy { min-height: 46px; margin-bottom: 16px; }
#solo { min-width: 0; padding-right: 26px; border-right: 1px solid #b8913c80; }
#online { min-width: 0; }
#play { width: 100%; font-size: 21px; min-height: 52px; text-transform: uppercase; letter-spacing: .06em; }
.preferences { margin-top: 16px; padding: 10px 0 0; border-top: 1px solid #b8913c55; }
summary { color: var(--gold); cursor: pointer; padding: 4px 0; text-shadow: 1px 1px 0 #000; }
.check-label { display: flex; align-items: center; gap: 8px; margin: 12px 0; cursor: pointer; text-shadow: 1px 1px 0 #000; }
input[type=checkbox] { width: 18px; height: 18px; margin: 0; accent-color: #c49a3e; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin: 12px 0; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; color: var(--gold); font-size: 14px; text-shadow: 1px 1px 0 #000; }
/* Text fields: the game's black inset boxes with a thin gold rule. */
input:not([type=checkbox]), select {
  background: #000000c0;
  color: #fff;
  padding: 8px 11px;
  border: 1px solid #b8913c;
  border-radius: 0;
  box-shadow: inset 2px 2px 4px #000, 0 0 0 1px #000;
  max-width: 100%;
  min-width: 0;
  font-size: 16px;
}
input::placeholder { color: #a99d86; opacity: 1; }
input:disabled, select:disabled { color: #c9bfa8; opacity: .7; }
#player-name { width: 100%; }
.room-entry { display: flex; align-items: end; gap: 10px; margin-top: 12px; }
.room-entry > button { flex: 1 0 auto; }
.join-fields { display: flex; gap: 8px; align-items: end; margin-left: auto; }
#room-code { text-transform: uppercase; width: 8.5em; letter-spacing: .1em; }
#online-status { font-size: 14px; margin-top: 12px; }
#room {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 24px;
  margin-top: 16px;
  padding-top: 18px;
  border-top: 1px solid #b8913c80;
}
.lobby-header { grid-column: 1 / -1; }
.lobby-settings, .lobby-players { min-width: 0; }
#setup.has-room .play-options { display: block; }
#setup.has-room #solo, #setup.has-room #online > .menu-copy,
#setup.has-room #online > .field, #setup.has-room .room-entry { display: none; }
#room h3 { margin-bottom: 10px; }
.invite-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
#invite { overflow-wrap: anywhere; flex: 1; min-width: 140px; font-size: 14px; }
#online-map { width: 100%; }
#map-description { font-size: 14px; max-height: 140px; overflow-y: auto; }
#map-description:empty { display: none; }
#room-roster { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 6px; }
#room-roster li { position: relative; min-height: 38px; padding: 8px 10px 8px 32px; border: 1px solid #b8913c; background: #000000a8; font-size: 14px; overflow-wrap: anywhere; }
#room-roster li::before { content: ''; position: absolute; top: 11px; left: 11px; width: 10px; height: 16px; border: 1px solid #f6dc9a; background: var(--banner, #a5a5a5); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 75%, 0 100%); }
#room-roster [data-color='0'] { --banner: #df3b37; }
#room-roster [data-color='1'] { --banner: #507ee6; }
#room-roster [data-color='2'] { --banner: #bb9b66; }
#room-roster [data-color='3'] { --banner: #49a052; }
#room-roster [data-color='4'] { --banner: #ed8a35; }
#room-roster [data-color='5'] { --banner: #b076df; }
#room-roster [data-color='6'] { --banner: #48b4b7; }
#room-roster [data-color='7'] { --banner: #e586b6; }
.download-panel { margin-top: 22px; padding: 12px 16px; border: 1px solid #b8913c; background: #000000a8; box-shadow: 0 0 0 1px #000, inset 0 0 12px #000; }
body:not(.data-ready) .download-panel { order: -1; margin: 0 0 22px; }
.eyebrow { font-size: 12px; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); text-shadow: 1px 1px 0 #000; }
.download-panel .eyebrow { font-size: 11px; }
#status { min-height: 1.5em; color: #fff; font-size: 14px; overflow-wrap: anywhere; }
.download-help { font-size: 13px; margin-bottom: 0; }
/* The game's loading bar: a gold bar in a black trough. */
progress { -webkit-appearance: none; appearance: none; width: 100%; height: 16px; margin-top: 10px; padding: 2px; border: 1px solid #b8913c; background: #000; accent-color: #d2ab50; }
progress::-webkit-progress-bar { background: #000; }
progress::-webkit-progress-value { background: linear-gradient(#fff2b8, #d8b155 45%, #8a6420); }
progress::-moz-progress-bar { background: linear-gradient(#fff2b8, #d8b155 45%, #8a6420); }
.menu-footer { margin: 16px 0 0; text-align: center; color: #d9c79f; font-size: 12px; letter-spacing: .06em; }

/* ---- playing ------------------------------------------------------------------- */
body.playing { padding: 0; overflow: hidden; background: #000; }
body.playing #setup { display: none; }
#stage { display: none; position: fixed; inset: 0; align-items: center; justify-content: center; background: #000; }
body.playing #stage { display: flex; }
#screen { width: min(100vw, calc(100vh * 4 / 3)); height: auto; aspect-ratio: 4 / 3; outline: none; image-rendering: auto; }
#message, #media-message { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: max-content; max-width: min(90vw, 560px); margin: 0; padding: 20px 24px; border: 3px solid #e2bf62; box-shadow: inset 0 0 0 2px var(--frame-blue), 0 0 0 1px #000, 0 6px 30px #000b; background: var(--h3-parchment, var(--leather-fallback)); color: var(--ink); text-shadow: 1px 1px 0 #000; }
#media-retry { margin: 8px; }
#note { display: none; position: fixed; bottom: 4px; left: 8px; color: #b8aa8a; font-size: 12px; pointer-events: none; }
body.playing #note { display: block; }
#online-sidebar { display: none; position: fixed; right: 0; top: 0; bottom: 0; width: var(--sidebar); padding: 18px 14px; background: var(--h3-parchment, var(--leather-fallback)); border-left: 3px solid #e2bf62; box-shadow: inset 2px 0 0 var(--frame-blue), inset 3px 0 0 #000; overflow-y: auto; z-index: 2; font-size: 14px; }
body.online-playing #online-sidebar { display: block; }
body.online-playing #stage { right: var(--sidebar); }
body.online-playing #screen { width: min(calc(100vw - var(--sidebar)), calc(100vh * 4 / 3)); }
#online-sidebar h2 { font-size: 22px; margin-top: 5px; }
#online-sidebar button { margin: 3px 3px 3px 0; padding: 7px 10px; }
.h3-art #online-sidebar button { padding: 7px 2px; }
.h3-art #online-sidebar .quiet { padding: 5px 4px; }
#end-day { width: 100%; font-size: 18px; }
#online-sidebar details { margin: 12px 0; border-top: 1px solid #b8913c; padding-top: 8px; }
#online-sidebar summary { color: var(--gold); }
#online-notice { white-space: pre-wrap; color: var(--ink); }
#online-questions:not(:empty) { border-bottom: 1px solid #b8913c; padding-bottom: 12px; }
.sidebar-help { border-top: 1px solid #b8913c; margin-top: 18px; padding-top: 12px; font-size: 13px; }

/* ---- narrow screens ---------------------------------------------------------------- */
@media (max-width: 820px) {
  body { padding: 18px 12px; }
  .h3-art .castle-banner { min-height: 240px; }
  .menu-content { padding: 22px 18px; }
  .play-options { grid-template-columns: 1fr; gap: 22px; }
  #solo { padding: 0 0 22px; border-right: 0; border-bottom: 1px solid #b8913c80; }
  .menu-copy { min-height: 0; }
  .preferences { margin-top: 12px; }
  #room { grid-template-columns: 1fr; gap: 18px; }
}
@media (max-width: 760px) {
  body.online-playing #online-sidebar { width: 100%; top: auto; height: 28vh; border-left: 0; border-top: 3px solid #e2bf62; box-shadow: inset 0 2px 0 var(--frame-blue); padding-top: 10px; }
  body.online-playing #stage { right: 0; bottom: 28vh; }
  body.online-playing #screen { width: min(100vw, calc(72vh * 4 / 3)); }
}
@media (max-width: 480px) {
  body { padding: 10px 8px; }
  #setup { padding: 12px; }
  /* A 64px frame is too heavy on a phone: draw it at half size. */
  .h3-art #setup { border-width: 12px; border-image-width: 48px; }
  .castle-banner { min-height: 150px; padding: 18px 14px 14px; }
  .h3-art .castle-banner { min-height: 185px; padding: 10px 12px; }
  .h3-art .edition { font-size: 12px; }
  .menu-content { padding: 18px 12px; }
  .edition { font-size: 13px; }
  .room-entry { flex-wrap: wrap; }
  .room-entry > button { width: 100%; }
  .join-fields { width: 100%; margin: 0; }
  .join-fields .field { flex: 1; }
  #room-code { width: 100%; }
  .download-panel { padding: 12px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; } }

/* ---- multiplayer room: the engine's original 800x600 setup screen ----------------- */
#room { display: block; padding-top: 0; border-top: 0; margin-top: 10px; }
#setup-screen { display: block; width: min(100%, 800px); height: auto; aspect-ratio: 4 / 3; margin: 14px auto 0; border: 2px solid #000; box-shadow: 0 0 0 1px #b8913c; touch-action: none; }
#setup-screen:focus-visible { outline-offset: 2px; }
.native-room-controls { margin-top: 16px; }
.native-room-controls .row a { margin-left: auto; font-size: 14px; }
.native-room-controls #room-roster { grid-template-columns: repeat(2,minmax(0,1fr)); }
#setup.has-room { max-width: 900px; }
/* In a room, give the original setup screen the space used by the title art. */
#setup.has-room .castle-banner, #setup.has-room .menu-heading, #room .lobby-header h3 { display: none; }
#setup.has-room .download-panel, #setup.has-room .menu-footer { display: none; }
#setup.has-room .menu-content { padding-top: 16px; padding-bottom: 16px; }
#setup.has-room #online-status { margin-top: 0; }
@media (max-width: 600px) {
  .native-room-controls #room-roster { grid-template-columns: 1fr; }
  #setup.has-room .menu-content { padding: 18px 8px; }
  .native-room-controls .row a { margin-left: 0; }
}
