:root {
  --paper: #f4eedf; --paper-2: #fbf7ec; --paper-3: #e9e0cb; --land: #e3d9c0; --line: #cfc3a6; --ink: #24211b; --ink-2: #5c5546; --ink-3: #7a7160;
  --sea: #dfe6dc; --accent: #b3402e; --accent-ink: #fff; --good: #0f8a72; --bad: #b3402e;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --panel-w: 400px; --top-h: 56px;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sea); color: var(--ink); font: 15px/1.4 var(--sans); overscroll-behavior: none; }
canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#top { touch-action: none; cursor: grab; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; line-height: 1.15; }
h2 { font-size: 22px; } h3 { font-size: 16px; }
p { margin: 0 0 10px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); } .small { font-size: 14px; }
.good { color: var(--good); } .bad { color: var(--bad); }
button, input, select { font: inherit; color: inherit; }
button { min-height: 44px; padding: 8px 14px; border: 1px solid var(--ink); background: var(--paper-2); border-radius: 3px; cursor: pointer; }
button:hover:not(:disabled) { background: var(--paper-3); }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover:not(:disabled) { background: #98321f; }
button.quiet { border-color: var(--line); background: transparent; }
button.danger { border-color: var(--bad); color: var(--bad); background: transparent; }
button:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=email], input[type=search], input:not([type]), select { width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--ink-3); background: #fff; border-radius: 3px; font-size: 16px; }
input[type=range] { width: 100%; min-height: 32px; accent-color: var(--accent); touch-action: pan-y; }
label { display: block; margin-bottom: 10px; }
label > span.l { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; color: var(--ink-2); margin-bottom: 2px; }
.row { display: flex; gap: 8px; align-items: center; } .row.wrap { flex-wrap: wrap; } .grow { flex: 1; min-width: 0; }
.between { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

/* top bar */
#bar { position: fixed; top: 0; left: 0; right: 0; min-height: calc(var(--top-h) + var(--sat)); padding: var(--sat) calc(12px + var(--sar)) 0 calc(12px + var(--sal)); display: flex; align-items: center; gap: 16px; background: var(--paper-2); border-bottom: 2px solid var(--ink); z-index: 3; }
#bar .brand { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 0 1 auto; }
#bar .brand b { font: 600 17px var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { display: inline-block; width: 12px; height: 12px; border-radius: 2px; flex: none; }
.stat { display: flex; flex-direction: column; line-height: 1.15; white-space: nowrap; }
.stat small { color: var(--ink-2); font-size: 12px; }
.stat b { font: 600 15px var(--mono); }
#bar .spacer { flex: 1; }
#bar button { min-height: 40px; min-width: 40px; padding: 4px 8px; }

/* nav */
#nav { position: fixed; left: calc(12px + var(--sal)); bottom: calc(12px + var(--sab)); display: flex; background: var(--paper-2); border: 1px solid var(--ink); border-radius: 3px; z-index: 3; }
#nav button { border: 0; border-right: 1px solid var(--line); border-radius: 0; background: transparent; padding: 6px 12px; position: relative; }
#nav button:last-child { border-right: 0; }
#nav button[aria-pressed=true] { background: var(--ink); color: var(--paper-2); }
.badge { display: inline-block; min-width: 18px; height: 18px; line-height: 18px; padding: 0 5px; margin-left: 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 12px; text-align: center; }

/* panel */
#panel { position: fixed; top: calc(var(--top-h) + var(--sat) + 2px); right: 0; bottom: 0; width: var(--panel-w); max-width: 100vw; padding-right: var(--sar); background: var(--paper); border-left: 2px solid var(--ink); display: flex; flex-direction: column; z-index: 2; }
#panel header { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
#panel .close { min-width: 44px; padding: 0; font-size: 20px; border-color: var(--line); background: transparent; }
#panel .body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 14px calc(14px + var(--sab)); overscroll-behavior: contain; }
.card { background: var(--paper-2); border: 1px solid var(--line); border-radius: 3px; padding: 10px 12px; margin-bottom: 8px; }
button.card { display: block; width: 100%; text-align: left; border-color: var(--line); color: inherit; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.kv small { display: block; color: var(--ink-2); font-size: 13px; }
.kv b { font: 600 16px var(--mono); }
.tag { display: inline-block; padding: 0 6px; border: 1px solid var(--ink-3); border-radius: 2px; font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.warn { background: #f7e4d6; border: 1px solid var(--bad); color: #6e2315; padding: 8px 10px; border-radius: 3px; margin-bottom: 10px; }
.note { font-size: 13px; color: var(--ink-2); }
.silhouette { display: block; width: 100%; height: 76px; margin-bottom: 4px; }
.choice { display: flex; gap: 6px; flex-wrap: wrap; }
.choice button[aria-pressed=true] { background: var(--ink); color: var(--paper-2); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--ink-2); font-weight: 500; font-size: 13px; }
td, th { padding: 6px 4px; border-bottom: 1px solid var(--line); }
td.r, th.r { text-align: right; font-family: var(--mono); }
tr.me { font-weight: 700; }
tr[data-action] { cursor: pointer; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 130px; }
.chart .tip { position: absolute; top: 0; pointer-events: none; background: var(--ink); color: var(--paper-2); padding: 3px 7px; font: 13px var(--mono); border-radius: 2px; white-space: nowrap; transform: translateX(-50%); display: none; }

/* cabin designer */
.cabinmap { display: block; width: 100%; height: auto; margin-bottom: 6px; }
#hangar { position: fixed; inset: 0; z-index: 6; background: var(--paper); display: flex; flex-direction: column; padding: var(--sat) var(--sar) 0 var(--sal); }
#hangar header { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 2px solid var(--ink); background: var(--paper-2); }
#hangar header select { margin-top: 4px; min-height: 40px; }
#hangar .close { min-width: 44px; padding: 0; font-size: 20px; border-color: var(--line); background: transparent; }
.hangar-map { overflow-x: auto; overflow-y: hidden; padding: 12px 16px; background: var(--sea); border-bottom: 1px solid var(--line); flex: none; -webkit-overflow-scrolling: touch; }
.hangar-map .cabinmap.big { margin: 0; min-height: 70px; }
.hangar-body { flex: 1; overflow-y: auto; padding: 12px 16px calc(16px + var(--sab)); max-width: 980px; width: 100%; margin: 0 auto; overscroll-behavior: contain; }
.hangar-summary { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: flex-end; margin-bottom: 8px; }
.meter { height: 10px; min-width: 120px; background: var(--paper-3); border-radius: 5px; overflow: hidden; margin-top: 6px; }
.meter span { display: block; height: 100%; background: var(--ink-2); }
.cabin-row { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.cabin-row select { min-height: 40px; }
.chip.big { width: 16px; height: 40px; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { min-width: 44px; padding: 0; font-size: 20px; }
.stepper .num { min-width: 64px; text-align: center; }
.hangar-foot { position: sticky; bottom: 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0 4px; margin-top: 10px; background: var(--paper); border-top: 2px solid var(--ink); }
.hangar-foot b { font-size: 20px; }
@media (max-width: 640px) { .cabin-row .grow { flex-basis: calc(100% - 26px); } .cabin-row { align-items: flex-start; } .chip.big { height: 44px; } .hangar-summary .kv b { font-size: 14px; } }
/* chat */
.chatlog { display: flex; flex-direction: column; gap: 6px; min-height: 120px; }
.msg { background: var(--paper-2); border: 1px solid var(--line); border-radius: 3px; padding: 6px 8px; }
.msg .who { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.msg .text { overflow-wrap: anywhere; }
.msg .acts { display: flex; gap: 10px; margin-top: 2px; }
.msg .acts button { min-height: 32px; padding: 2px 6px; font-size: 13px; color: var(--ink-2); border: 0; background: none; text-decoration: underline; }

/* title screen: the buttons are part of the artwork, so invisible real buttons sit over them */
.title { position: fixed; inset: 0; z-index: 3; display: flex; align-items: center; justify-content: center; background: #5aa7dc; padding: var(--sat) var(--sar) var(--sab) var(--sal); }
.title .art { position: relative; width: min(100%, calc((100dvh - var(--sat) - var(--sab)) * 2000 / 1116)); aspect-ratio: 2000 / 1116; }
.title img { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.title .zone { position: absolute; min-height: 44px; min-width: 44px; padding: 0; border: 0; background: transparent; border-radius: 16px; transform: translateY(-50%); top: 91.2%; height: 12%; }
.title .zone:hover:not(:disabled) { background: rgba(255,255,255,.12); }
.title .zone.settings { left: 26%; width: 13%; }
.title .zone.start { left: 40%; width: 20%; height: 13%; }
.title .zone.credits { left: 61%; width: 13%; }
/* sign-in and joining */
.sheet { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(460px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow-y: auto; background: var(--paper-2); border: 2px solid var(--ink); padding: 22px; z-index: 5; }
.sheet h1 { font-size: 34px; margin-bottom: 4px; }
.scrim { position: fixed; inset: 0; background: rgba(36,33,27,.35); z-index: 4; }
.check { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; }
.check input { width: 22px; height: 22px; flex: none; margin: 1px 0 0; accent-color: var(--accent); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 44px; height: 44px; padding: 0; border: 2px solid transparent; border-radius: 3px; }
.swatches button[aria-pressed=true] { outline: 3px solid var(--ink); outline-offset: 1px; }
.hubs { display: flex; flex-direction: column; gap: 6px; }
.hubs button { text-align: left; display: flex; justify-content: space-between; gap: 8px; }
.hubs button[aria-pressed=true] { background: var(--ink); color: var(--paper-2); }
#toast { position: fixed; left: 50%; bottom: calc(76px + var(--sab)); transform: translateX(-50%); max-width: min(520px, 90vw); background: var(--ink); color: var(--paper-2); padding: 10px 14px; border-radius: 3px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 9; }
#toast.show { opacity: 1; }
#season { position: fixed; left: calc(12px + var(--sal)); top: calc(var(--top-h) + var(--sat) + 12px); font-size: 13px; color: var(--ink-2); background: rgba(251,247,236,.85); padding: 2px 8px; border-radius: 2px; z-index: 1; pointer-events: none; }

/* tablets and small windows: the nav has to fit beside the panel */
@media (min-width: 641px) and (max-width: 1040px) and (min-height: 501px) {
  :root { --panel-w: min(400px, 50vw); }
  #nav { max-width: calc(100vw - var(--panel-w) - 24px); flex-wrap: wrap; }
  #nav button { padding: 6px 7px; font-size: 13px; }
}
/* phones held upright: the panel is a bottom sheet */
@media (max-width: 640px) {
  :root { --panel-w: 100vw; }
  #bar { gap: 10px; flex-wrap: wrap; padding-top: calc(var(--sat) + 4px); padding-bottom: 4px; }
  #bar .brand { flex: 1 1 100%; }
  #bar .hide-narrow { display: none; }
  #nav { left: 0; right: 0; bottom: 0; border-width: 1px 0 0; border-radius: 0; padding-bottom: var(--sab); }
  #nav button { flex: 1; padding: 6px 2px; font-size: 13px; }
  #panel { top: auto; height: 62dvh; left: 0; right: 0; border-left: 0; border-top: 2px solid var(--ink); bottom: calc(50px + var(--sab)); }
  #panel .body { padding-bottom: 14px; }
  #season { display: none; }
}
/* phones held sideways: rail on the left, panel on the right */
@media (max-height: 500px) and (min-width: 641px) {
  :root { --top-h: 44px; --panel-w: min(46vw, 400px); }
  #bar { gap: 12px; } #bar button { min-height: 36px; min-width: 36px; }
  .stat small { font-size: 11px; } .stat b { font-size: 14px; }
  #nav { flex-direction: column; left: calc(6px + var(--sal)); bottom: calc(6px + var(--sab)); }
  #nav button { border-right: 0; border-bottom: 1px solid var(--line); padding: 2px 8px; min-height: 42px; font-size: 13px; }
  #nav button:last-child { border-bottom: 0; }
  #season { display: none; }
}
