@font-face {
  font-family: 'Cinzel';
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url('fonts/cinzel-latin-wght-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Cormorant Garamond';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('fonts/cormorant-garamond-latin-wght-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Cormorant Garamond';
  font-style: italic;
  font-weight: 300 700;
  font-display: swap;
  src: url('fonts/cormorant-garamond-latin-wght-italic.woff2') format('woff2');
}

:root {
  --gold: #d9b45b;
  --gold-hi: #f6dc92;
  --gold-lo: #8a6a2a;
  --ink: #160f08;
  --text: #eadfc2;
  --muted: #b7a276;
  --red: #e0513a;
  --green: #5fd35a;
  --display: 'Cinzel', 'Trajan Pro', Palatino, 'Palatino Linotype', Georgia, serif;
  --body: 'Cormorant Garamond', Palatino, 'Palatino Linotype', Georgia, serif;
  --noise: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.55 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #05060a;
  font-family: var(--body);
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
}

#view {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  outline: none;
}
#view.dragging { cursor: grabbing !important; }
#ground { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
/* the scenario's colour grade over the GPU ground and the sprites alike (renderer.js grades in 2D without the GPU) */
#grade { position: absolute; inset: 0; pointer-events: none; mix-blend-mode: soft-light; }

.hidden { display: none !important; }

button {
  font-family: var(--display);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--gold-hi);
  background: linear-gradient(180deg, #5a4128 0%, #3a2918 55%, #2a1d10 100%);
  border: 1px solid var(--gold-lo);
  border-radius: 3px;
  padding: 5px 12px;
  cursor: pointer;
  text-shadow: 0 1px 1px #000;
  box-shadow: inset 0 1px 0 rgba(255, 230, 170, 0.25), 0 1px 3px rgba(0, 0, 0, 0.6);
  transition: filter 0.12s, border-color 0.12s;
}
button:hover { filter: brightness(1.2); border-color: var(--gold); }
button:active { filter: brightness(0.9); transform: translateY(1px); }

/* ---------- wood + parchment surfaces ---------- */
.wood {
  background:
    var(--noise),
    repeating-linear-gradient(90deg, rgba(255, 220, 160, 0.035) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.08) 0 1px, transparent 1px 23px),
    linear-gradient(180deg, #4d3520 0%, #3a2716 45%, #26190d 100%);
  border: 1px solid #0c0703;
  box-shadow: inset 0 1px 0 rgba(255, 220, 150, 0.22), inset 0 -2px 0 rgba(0, 0, 0, 0.5), 0 4px 18px rgba(0, 0, 0, 0.65);
}
.inset {
  background:
    var(--noise),
    linear-gradient(180deg, rgba(10, 8, 5, 0.78), rgba(22, 16, 9, 0.84));
  border: 1px solid var(--gold-lo);
  outline: 1px solid rgba(0, 0, 0, 0.85);
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.8), 0 0 0 3px rgba(40, 26, 12, 0.9), 0 0 0 4px rgba(217, 180, 91, 0.35);
  border-radius: 3px;
}
.panel {
  background: var(--noise), linear-gradient(180deg, rgba(34, 26, 15, 0.94), rgba(20, 14, 8, 0.95));
  border: 1px solid var(--gold-lo);
  outline: 1px solid rgba(0, 0, 0, 0.7);
  border-radius: 4px;
  box-shadow: inset 0 1px 0 rgba(255, 220, 150, 0.18), 0 6px 22px rgba(0, 0, 0, 0.6);
}
.parchment {
  background:
    var(--noise),
    radial-gradient(ellipse at 50% 40%, rgba(255, 244, 214, 0.97) 0%, rgba(233, 214, 170, 0.97) 60%, rgba(196, 166, 112, 0.97) 100%);
  color: #3a2a16;
  border: 2px solid #6b4e22;
  outline: 3px solid rgba(20, 12, 4, 0.85);
  box-shadow: inset 0 0 40px rgba(120, 80, 30, 0.45), inset 0 0 0 5px rgba(255, 240, 200, 0.35), inset 0 0 0 6px rgba(110, 80, 34, 0.55), 0 20px 60px rgba(0, 0, 0, 0.75);
  border-radius: 6px;
}

/* ---------- top bar ---------- */
/* three columns: the age sits centred on the screen while both sides fit
   beside it, and is pushed aside (never over the resources or the buttons)
   once they don't */
#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  height: 40px;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; column-gap: 8px;
  padding: 0 12px;
  z-index: 3;
  border-top: none;
}
#resbar { display: flex; gap: 6px; }
.res {
  display: flex; align-items: center; gap: 6px;
  min-width: 92px;
  height: 28px;
  padding: 0 10px 0 4px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.35));
  border: 1px solid rgba(217, 180, 91, 0.35);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.7);
  font-family: var(--display);
  font-weight: 700;
  font-size: 15px;
  color: #fff3d0;
  text-shadow: 0 1px 2px #000;
  font-variant-numeric: tabular-nums;
  transition: background 0.3s;
}
.res img { width: 24px; height: 24px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.8)); }
.res.flash { background: linear-gradient(180deg, rgba(160, 30, 20, 0.8), rgba(90, 10, 5, 0.6)); }
.res.gain .v { color: #b6ff9a; }
.res.pop.full .v { color: #ff9a7a; }
/* goods: one pill for the whole store, listed on hover */
.res.goods { position: relative; min-width: 0; cursor: default; }
.res.goods .pop {
  display: none; position: absolute; top: 32px; left: -8px; z-index: 20; width: 260px; padding: 8px 10px;
  background: linear-gradient(180deg, rgba(36, 24, 14, 0.97), rgba(20, 13, 8, 0.97)); border: 1px solid var(--gold-lo); border-radius: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.7); font-size: 13px; font-weight: 400; color: #f1e4c4;
}
.res.goods:hover .pop { display: block; }
.res.goods .gl { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; }
.res.goods .gl span { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.res.goods .gl img { width: 18px; height: 18px; }
.res.goods .gn { margin-top: 6px; font-size: 11.5px; font-style: italic; color: var(--muted); line-height: 1.35; font-family: var(--body, inherit); }
/* the moon on the tide: its phase says when the next spring tide comes */
#tide .moon { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; vertical-align: -1px;
  background: #e8dfc4; box-shadow: inset -4px 0 0 #3a3226, 0 0 4px rgba(232, 223, 196, 0.4); }
#tide .moon.m2 { box-shadow: inset -7px 0 0 #3a3226; }
#tide .moon.m1 { box-shadow: inset -2px 0 0 #3a3226, 0 0 5px rgba(232, 223, 196, 0.5); }
#tide .moon.m0 { box-shadow: 0 0 7px rgba(255, 244, 210, 0.85); }
#info .task img { width: 16px; height: 16px; vertical-align: -3px; }
#info .task .warn { color: #ffae7a; }
#age {
  align-self: stretch; padding: 0 12px; /* room for the glow */
  overflow: hidden; /* last resort on a very narrow bar: the text is cut at its left end, never drawn over its neighbours */
  font-family: var(--display);
  font-size: 15px; font-weight: 700;
  color: var(--gold-hi);
  letter-spacing: 0.08em;
  text-shadow: 0 1px 2px #000, 0 0 12px rgba(217, 180, 91, 0.35);
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  white-space: nowrap;
}
#age > :empty { display: none; } /* an empty #speed or #tide takes no gap */
#age .sep { color: var(--gold-lo); font-size: 12px; }
#renown { margin-left: 10px; color: #f4d99a; }
#renown::before { content: '\2726 '; color: var(--gold-hi); }
#age:not(:has(#speed:not(:empty), #tide:not(:empty))) .sep { display: none; } /* nothing after the age: no separator */
#speed:not(:empty) + #tide:not(:empty)::before { content: '· '; }
#speed { font-size: 12px; color: var(--muted); }
#age.advancing { padding: 0; }
#age.advancing > :is(#scen-name, .sep) { display: none; }
#age-progress { width: 210px; min-width: 0; flex: 0 1 auto; font-size: 11px; letter-spacing: 0.02em; }
.age-progress-label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 3px; }
#age-progress-name { overflow: hidden; text-overflow: ellipsis; }
#age-progress-value { flex: 0 0 auto; color: #fff3d0; font-variant-numeric: tabular-nums; }
.age-progress-track { height: 7px; overflow: hidden; border: 1px solid var(--gold-lo); border-radius: 2px; background: #191107; box-shadow: inset 0 1px 2px #000; }
#age-progress-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #a58034, #f6dc92); }
#topbtns { grid-column: 3; justify-self: end; display: flex; align-items: center; gap: 6px; }
#music { display: flex; align-items: center; gap: 3px; margin-right: 8px; }
#music button { padding: 4px 7px; min-width: 26px; line-height: 1; }
#music svg { width: 10px; height: 10px; fill: currentColor; display: block; margin: 1px auto; }
#btn-stats { padding: 4px 7px; line-height: 1; }
#btn-stats svg { width: 12px; height: 12px; fill: currentColor; display: block; }

/* performance panel (F3): each figure green / orange / red */
#perf {
  position: absolute; left: 14px; bottom: 200px; z-index: 4;
  width: 250px; padding: 8px 10px 6px;
  background: rgba(12, 8, 4, 0.82); border: 1px solid var(--gold-lo); border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.55;
  pointer-events: auto;
}
#perf.hidden { display: none; }
#perf .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px;
  font-family: var(--display); font-weight: 700; font-size: 12px; letter-spacing: 0.08em; color: var(--gold-hi); }
#perf .copy { padding: 2px 8px; font-size: 10px; }
#perf .rows div { display: flex; justify-content: space-between; gap: 10px; }
#perf .rows span { color: #cfc3a6; }
#perf .rows b { font-weight: 700; }
#perf .good b { color: #6fe06a; }
#perf .warn b { color: #f2b23a; }
#perf .bad b { color: #ff5a4a; }
#perf .info b { color: #e8dcc0; }
#btn-sound { padding: 4px 7px; line-height: 1; margin-right: 2px; }
#btn-sound svg { width: 12px; height: 12px; display: block; fill: currentColor; }
#btn-sound svg .on, #btn-sound svg .x { fill: none; stroke: currentColor; stroke-width: 1.2; stroke-linecap: round; }
#btn-sound svg .x, #btn-sound.off svg .on { display: none; }
#btn-sound.off svg .x { display: inline; }
#btn-sound.off, #btn-music.off { color: var(--muted); }
#btn-music { position: relative; }
#btn-music.off::after { content: ''; position: absolute; left: 6px; right: 6px; top: 50%; height: 1.5px; background: currentColor; transform: rotate(-40deg); } /* struck through */
#track {
  max-width: 190px; margin-left: 5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--body); font-style: italic; font-size: 14px;
  color: #f0dfb4; text-shadow: 0 1px 2px #000;
}
#btn-music.off ~ #track { opacity: 0.45; }

/* ---------- messages & banner ---------- */
#messages {
  position: absolute; top: 52px; left: 14px;
  display: flex; flex-direction: column; gap: 3px;
  pointer-events: none;
  z-index: 2;
}
.msg {
  font-family: var(--body);
  font-weight: 700;
  font-size: 17px;
  color: #f4e8c8;
  text-shadow: 0 1px 2px #000, 0 0 6px #000;
  animation: msgIn 0.25s ease-out;
  transition: opacity 0.8s;
}
.msg.warn { color: #ffb08a; }
.msg.good { color: #b8f0a0; }
.msg.fade { opacity: 0; }
@keyframes msgIn { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }

#banner {
  position: absolute; top: 20%; left: 0; right: 0;
  text-align: center;
  font-family: var(--display);
  font-weight: 900;
  font-size: 34px;
  letter-spacing: 0.12em;
  color: var(--gold-hi);
  text-shadow: 0 2px 4px #000, 0 0 24px rgba(0, 0, 0, 0.9), 0 0 40px rgba(217, 180, 91, 0.35);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s;
  z-index: 2;
}
#banner.show { opacity: 1; }
#banner.red { color: #ffb09a; text-shadow: 0 2px 4px #000, 0 0 24px rgba(0, 0, 0, 0.9), 0 0 40px rgba(220, 60, 40, 0.5); }
#banner small { display: block; font-family: var(--body); font-weight: 600; font-size: 18px; letter-spacing: 0.04em; color: #f0e2c0; margin-top: 4px; }

/* a question for the player (Sea People families asking for land) */
#prompt {
  position: absolute; top: 92px; left: 50%; transform: translateX(-50%); z-index: 3; max-width: 520px;
  padding: 8px 14px; text-align: center; color: #f1e4c4; font-size: 14px;
  background: linear-gradient(180deg, rgba(36, 24, 14, 0.94), rgba(20, 13, 8, 0.94)); border: 1px solid var(--gold-lo); border-radius: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
}
#prompt .pq { font-family: var(--display); font-weight: 700; color: var(--gold-hi); margin-bottom: 6px; }
#prompt .pq i { color: var(--muted); font-style: normal; margin-left: 6px; }
#prompt button { margin: 2px 4px 6px; }
#prompt .pn { display: block; font-size: 12px; font-style: italic; color: var(--muted); }
#objectives .dip { margin: 4px 0 6px; }
#objectives .dip b { font-family: var(--display); }
#objectives .dip .foe { color: #ff9a7a; font-size: 12px; }
#objectives .dip .ally { color: #9dff9a; font-size: 12px; }
#objectives .dip div { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
#wonder-timer {
  position: absolute; top: 50px; left: 50%; transform: translateX(-50%);
  padding: 6px 18px;
  font-family: var(--display); font-weight: 700; font-size: 15px;
  color: var(--gold-hi);
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--gold-lo);
  border-radius: 4px;
  z-index: 2;
}

#objectives {
  position: absolute; top: 50px; right: 14px;
  width: 330px;
  padding: 14px 16px;
  z-index: 3;
}
#objectives h3 { font-family: var(--display); color: var(--gold); font-size: 15px; letter-spacing: 0.08em; margin-bottom: 8px; }
#objectives li { list-style: none; font-size: 16px; line-height: 1.35; margin: 5px 0; padding-left: 22px; position: relative; }
#objectives li::before { content: '\25C7'; position: absolute; left: 2px; color: var(--gold); }
#objectives li.done { color: var(--green); }
#objectives li.done::before { content: '\2714'; color: var(--green); }
#objectives .note { font-size: 14px; color: var(--muted); font-style: italic; margin-top: 8px; }

/* ---------- bottom bar ---------- */
#bottombar {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 184px;
  display: grid;
  grid-template-columns: 300px 1fr 336px;
  grid-template-rows: minmax(0, 1fr); /* panels fit the bar instead of spilling below the screen */
  gap: 14px;
  padding: 14px 14px 12px;
  z-index: 3;
}
#bottombar::before {
  content: '';
  position: absolute; left: 0; right: 0; top: -1px; height: 3px;
  background: linear-gradient(90deg, transparent, var(--gold-lo) 10%, var(--gold) 50%, var(--gold-lo) 90%, transparent);
}

#cmd {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 5px;
  padding: 8px;
}
.cmdbtn {
  position: relative;
  padding: 0;
  border: 1px solid #0a0603;
  border-radius: 3px;
  background-size: cover;
  background-position: center;
  box-shadow: inset 0 0 0 1px rgba(255, 220, 150, 0.35), inset 0 -6px 10px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}
.cmdbtn:hover { filter: brightness(1.25) saturate(1.1); box-shadow: inset 0 0 0 1px var(--gold-hi), 0 0 8px rgba(246, 220, 146, 0.6); }
.cmdbtn.more { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; background: linear-gradient(180deg, #60482c, #2a1d10); font-size: 11px; }
.cmdbtn.more small { font-size: 10px; color: var(--text); font-variant-numeric: tabular-nums; }
.cmdbtn .badge {
  position: absolute; left: 2px; bottom: 1px;
  font-family: var(--display); font-size: 12px; font-weight: 900;
  color: #fff; text-shadow: 0 0 2px #000, 0 0 3px #000;
}
.cmdbtn.poor { filter: grayscale(0.6) brightness(0.75); }
.cmdbtn.poor::after { content: ''; position: absolute; inset: 0; box-shadow: inset 0 0 0 2px rgba(220, 60, 40, 0.8); }
.cmdbtn.locked { filter: grayscale(1) brightness(0.45); }
.cmdbtn.active { box-shadow: inset 0 0 0 2px var(--gold-hi), 0 0 10px rgba(246, 220, 146, 0.8); }
.cmdslot { border-radius: 3px; background: rgba(0, 0, 0, 0.25); box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.7); }

#info {
  display: flex; gap: 14px;
  padding: 10px 14px;
  overflow: hidden;
}
#info .portrait {
  flex: 0 0 auto;
  width: 104px; height: 128px;
  border: 1px solid var(--gold-lo);
  border-radius: 3px;
  background: radial-gradient(ellipse at 50% 35%, #6c7c8c, #2c3440);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.7);
  object-fit: contain;
  display: block;
}
#info .details { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
#info .details > * { flex-shrink: 0; } /* never squash the bar or a line to fit */
#info .details > :empty { display: none; }
#info .name { font-family: var(--display); font-size: 18px; font-weight: 700; color: var(--gold-hi); letter-spacing: 0.04em; text-shadow: 0 1px 2px #000; }
#info .owner { font-size: 14px; color: var(--muted); font-style: italic; }
#info .hp { position: relative; height: 14px; width: 220px; max-width: 100%; background: #1a0e08; border: 1px solid #000; border-radius: 2px; box-shadow: 0 0 0 1px rgba(217, 180, 91, 0.3); }
#info .hp i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(180deg, #7dea6a, #2e9a2a); border-radius: 1px; transition: width 0.2s; }
#info .hp i.mid { background: linear-gradient(180deg, #f2d45a, #b08a1a); }
#info .hp i.low { background: linear-gradient(180deg, #ff7a5a, #b0281a); }
#info .hp span { position: absolute; inset: 0; text-align: center; font-family: var(--display); font-size: 10px; font-weight: 700; line-height: 13px; color: #fff; text-shadow: 0 0 2px #000, 0 0 3px #000; }
#info .stats { display: flex; gap: 14px; flex-wrap: wrap; font-size: 15px; color: #e8dcc0; }
#info .stats b { font-family: var(--display); font-size: 11px; color: var(--muted); font-weight: 700; letter-spacing: 0.06em; margin-right: 3px; }
#info .task { font-size: 16px; font-style: italic; color: #f0e2c0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#info .carry { display: flex; align-items: center; gap: 6px; font-family: var(--display); font-weight: 700; font-size: 14px; }
#info .carry img { width: 22px; height: 22px; }
#info .desc { font-size: 15px; color: var(--muted); line-height: 1.25; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
#info .queue { flex: 0 1 auto; display: flex; flex-wrap: wrap; gap: 5px; align-self: center; align-items: flex-end; max-width: 40%; }
#info .queue:empty { display: none; }
#info .queue .q { position: relative; width: 40px; height: 40px; border: 1px solid var(--gold-lo); border-radius: 2px; background-size: cover; cursor: pointer; }
#info .queue .q:first-child { width: 50px; height: 50px; }
#info .queue .q i { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--gold-hi); box-shadow: 0 0 4px var(--gold); }
#info .queue .q:hover::after { content: '\2715'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #ff8a70; font-size: 20px; background: rgba(0, 0, 0, 0.45); }
#info .queue .q b { position: absolute; right: 2px; bottom: 3px; font-family: var(--display); font-size: 13px; font-weight: 900; color: #fff; text-shadow: 0 0 2px #000, 0 0 3px #000; }
#info .queue.long .q { width: 32px; height: 32px; }
#info .queue.long .q:first-child { width: 42px; height: 42px; }
#info .multi { flex: 1; display: grid; grid-template-columns: repeat(auto-fill, 42px); gap: 4px; align-content: start; overflow: hidden; }
#info .multi .m { position: relative; width: 42px; height: 42px; border: 1px solid var(--gold-lo); border-radius: 2px; background-size: cover; cursor: pointer; }
#info .multi .m i { position: absolute; left: 2px; right: 2px; bottom: 2px; height: 3px; background: #1a0e08; }
#info .multi .m i b { display: block; height: 100%; background: var(--green); }
#info .multi .m:hover { filter: brightness(1.3); }
#info .empty { margin: auto; text-align: center; color: var(--muted); font-style: italic; font-size: 16px; line-height: 1.5; }
#info .empty b { font-family: var(--display); font-style: normal; color: var(--gold); font-size: 13px; letter-spacing: 0.08em; }

#mini { position: relative; display: flex; align-items: center; justify-content: center; padding: 6px; }
#minimap { display: block; width: 100%; height: 100%; object-fit: contain; image-rendering: auto; cursor: crosshair; }
#btn-idle {
  position: absolute; left: 6px; bottom: 6px;
  width: 42px; height: 42px; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
#btn-idle img { width: 38px; height: 38px; border-radius: 2px; }
#btn-idle span { position: absolute; right: 2px; bottom: 0; font-size: 13px; font-weight: 900; color: #fff; text-shadow: 0 0 3px #000; }
#btn-idle.none { filter: grayscale(1) brightness(0.6); }

#tooltip {
  position: absolute;
  max-width: 300px;
  padding: 9px 12px;
  background: var(--noise), linear-gradient(180deg, rgba(40, 30, 16, 0.97), rgba(22, 15, 8, 0.97));
  border: 1px solid var(--gold);
  border-radius: 3px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.7);
  pointer-events: none;
  z-index: 20;
  font-size: 15px;
  line-height: 1.3;
}
#tooltip .tt-name { font-family: var(--display); font-weight: 700; color: var(--gold-hi); font-size: 14px; letter-spacing: 0.04em; }
#tooltip .tt-key { color: var(--muted); font-family: var(--display); font-size: 11px; margin-left: 6px; }
#tooltip .tt-cost { display: flex; gap: 10px; margin: 5px 0 3px; font-family: var(--display); font-weight: 700; font-size: 13px; }
#tooltip .tt-cost span { display: flex; align-items: center; gap: 3px; }
#tooltip .tt-cost img { width: 18px; height: 18px; }
#tooltip .tt-cost .no { color: var(--red); }
#tooltip .tt-desc { color: #e0d2b0; }
#tooltip .tt-req { color: var(--red); font-style: italic; margin-top: 3px; }

/* ---------- full-screen menus ---------- */
.screen {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.15) 0%, rgba(0, 0, 0, 0.72) 100%);
  z-index: 10;
  animation: fadeIn 0.35s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.menu-box {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 26px 34px 22px;
  text-align: center;
  position: relative;
}
.menu-box.small-box { width: min(380px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 10px; }
.menu-box h1 {
  font-family: var(--display); font-weight: 900;
  font-size: 44px; letter-spacing: 0.08em;
  color: #5a3a12;
  text-shadow: 0 1px 0 rgba(255, 240, 200, 0.8), 0 2px 6px rgba(120, 80, 20, 0.35);
}
.menu-box h2 { font-family: var(--display); font-size: 28px; color: #5a3a12; letter-spacing: 0.08em; margin-bottom: 6px; }
.menu-box .subtitle { font-style: italic; font-size: 19px; color: #6b5030; margin: 2px 0 16px; }
.crest { font-size: 30px; color: #8a5a1a; line-height: 1; margin-bottom: 2px; }
.menu-box button { font-size: 13px; }
.menu-box button.big { font-size: 18px; padding: 10px 44px; margin: 14px 0 10px; letter-spacing: 0.14em; }
.menu-box button.small { font-size: 11px; padding: 3px 9px; }
button:disabled { opacity: 0.55; cursor: default; filter: none; transform: none; }

/* ---------- the main menu: a title page, and a page for each thing to do ---------- */
#menu .page { display: none; animation: fadeIn 0.25s ease-out; }
#menu[data-page="home"] #page-home, #menu[data-page="setup"] #page-setup,
#menu[data-page="lobby"] #page-lobby, #menu[data-page="help"] #page-help { display: flex; flex-direction: column; }
/* the title page stands on the map itself: darker behind the words, the land showing around them */
#menu[data-page="home"] { background: radial-gradient(ellipse 46% 72% at center, rgba(5, 6, 10, 0.76) 0%, rgba(5, 6, 10, 0.4) 62%, rgba(0, 0, 0, 0.62) 100%); }
/* the title fills the first screen; a page about the game follows below it (scroll, or "About the game") */
#page-home { align-items: center; text-align: center; width: 100%; max-height: 100vh; overflow-y: auto; padding: 0 16px; scrollbar-width: thin; scrollbar-color: rgba(217, 180, 91, 0.45) transparent; }
.home-hero { flex: none; min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px 0; }
#page-home .crest { font-size: 34px; color: var(--gold); text-shadow: 0 2px 6px #000; margin-bottom: 6px; }
#page-home h1 {
  font-family: var(--display); font-weight: 900;
  font-size: clamp(34px, 6vw, 62px); letter-spacing: 0.1em; line-height: 1.1;
  color: var(--gold-hi);
  text-shadow: 0 2px 6px #000, 0 0 28px rgba(217, 180, 91, 0.35);
}
#page-home .subtitle { font-style: italic; font-size: 21px; color: var(--text); text-shadow: 0 1px 4px #000; margin: 4px 0 30px; }
.home-nav { display: flex; flex-direction: column; gap: 10px; width: min(380px, calc(100vw - 32px)); }
.home-nav button { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 11px 18px 10px; border-radius: 4px; box-shadow: inset 0 1px 0 rgba(255, 230, 170, 0.25), 0 4px 14px rgba(0, 0, 0, 0.6); }
.home-nav button b { font-size: 17px; letter-spacing: 0.14em; }
.home-nav button span { font-family: var(--body); font-weight: 500; font-style: italic; font-size: 15px; letter-spacing: 0; color: var(--muted); }
#home-more { margin-top: 22px; font-style: italic; font-size: 17px; color: var(--muted); text-decoration: none; text-shadow: 0 1px 4px #000; }
#home-more::after { content: ' \25BE'; font-style: normal; }
#home-more:hover, #home-more:focus-visible { color: var(--gold-hi); }

/* the page about the game: what it is, screenshots, the ways to play, the controls
   (its top margin keeps the parchment's outline and shadow off the title screen) */
.about { flex: none; width: min(760px, 100%); margin: 48px 0 40px; padding: 26px 34px 20px; text-align: left; user-select: text; -webkit-user-select: text; }
.about h2 { font-family: var(--display); font-size: 26px; letter-spacing: 0.08em; color: #5a3a12; text-align: center; margin-bottom: 12px; }
.about h3 { margin: 22px 0 8px; }
.about p, .about li { font-size: 17px; line-height: 1.45; color: #3a2a16; }
.about p { margin-bottom: 8px; }
.about .lead { font-size: 19px; }
.about ul { display: grid; gap: 8px; padding-left: 20px; margin-bottom: 8px; }
.about b { font-family: var(--display); font-size: 13px; letter-spacing: 0.04em; color: #4a300e; }
.about figure { margin: 14px 0 6px; }
.about img { display: block; width: 100%; height: auto; border: 1px solid #6b4e22; border-radius: 3px; box-shadow: 0 3px 12px rgba(60, 35, 10, 0.35); }
.about figcaption { margin-top: 5px; font-style: italic; font-size: 15px; color: #6b5030; text-align: center; }
.about .shots { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.about a { color: #7a4a10; text-underline-offset: 2px; }
.about footer { margin-top: 18px; padding-top: 12px; border-top: 1px solid rgba(107, 78, 34, 0.4); text-align: center; font-style: italic; font-size: 16px; color: #6b5030; }
@media (max-width: 640px) { .about { padding: 20px 18px 16px; } .about .shots { grid-template-columns: 1fr; } }

/* the other pages: a head (back, title), a body that scrolls, and a foot for the one thing to press */
.page.menu-box { overflow: hidden; padding: 18px 30px 20px; }
#page-setup { width: min(1080px, calc(100vw - 32px)); }
#page-help { width: min(900px, calc(100vw - 32px)); }
.page-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding-bottom: 10px; margin-bottom: 14px; border-bottom: 1px solid rgba(107, 78, 34, 0.4); }
.page-head button { justify-self: start; }
.page-head h2 { margin: 0; font-size: 24px; }
.page-body { flex: 1; min-height: 0; overflow: auto; padding: 2px; }
.page-foot { display: flex; justify-content: center; padding-top: 12px; margin-top: 12px; border-top: 1px solid rgba(107, 78, 34, 0.4); }
.page-foot button.big { margin: 0; }
.menu-box h3, .about h3 { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-family: var(--display); font-weight: 700; font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: #6b4a1c; }
.menu-box h3::after, .about h3::after { content: ''; flex: 1; height: 1px; background: rgba(107, 78, 34, 0.35); }
.setup, .help { display: grid; gap: 6px 30px; align-items: start; text-align: left; }
.setup { grid-template-columns: 1fr 1fr; }
.setup section > h3:not(:first-child), #players-row, #room-chat { margin-top: 14px; }
.help { grid-template-columns: 1fr 1.15fr; }
@media (max-width: 900px) { .setup, .help { grid-template-columns: 1fr; } }

#scen-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.scen {
  cursor: pointer;
  border: 2px solid rgba(107, 78, 34, 0.5);
  border-radius: 4px;
  padding: 6px 6px 7px;
  text-align: center;
  background: rgba(255, 250, 235, 0.35);
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}
.scen:hover { transform: translateY(-2px); border-color: #8a5a1a; }
.scen.sel { border-color: #7a4a10; background: rgba(255, 236, 180, 0.7); box-shadow: 0 0 0 2px rgba(217, 160, 60, 0.5), 0 6px 14px rgba(90, 60, 20, 0.35); }
.scen canvas { width: 100%; aspect-ratio: 2 / 1; display: block; margin-bottom: 4px; image-rendering: auto; }
.scen .sn { font-family: var(--display); font-weight: 700; font-size: 13px; color: #4a300e; }
#scen-info, #mode-info { font-size: 15px; font-style: italic; line-height: 1.3; color: #5a4020; }
#scen-info { min-height: 58px; margin: 9px 0 4px; }
#mode-info { min-height: 20px; margin: -2px 0 4px; }

.menu-row { display: flex; align-items: center; gap: 12px; margin: 8px 0; }
.menu-row label { flex: none; font-family: var(--display); font-weight: 700; font-size: 13px; color: #5a3a12; letter-spacing: 0.08em; width: 84px; }
#menu-seed { flex: 1; font-family: var(--display); font-size: 13px; color: #5a4020; }
.seg { flex: 1; display: flex; border-radius: 3px; overflow: hidden; }
.seg button { flex: 1; min-width: 0; border-radius: 0; padding: 5px 2px; }
.seg button.on { background: linear-gradient(180deg, #b88a3a, #7a5418); color: #fff8e0; border-color: #5a3a10; opacity: 1; }
#tide { margin-left: 10px; font-size: 13px; color: #9fc8e8; letter-spacing: 0.02em; }
#tide.low { color: #e8cf96; }
#civ-pick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.civ { display: flex; flex-direction: column; align-items: center; padding: 5px 2px 3px; cursor: pointer; border: 2px solid rgba(107, 78, 34, 0.35); border-radius: 4px; background: rgba(255, 250, 235, 0.3); transition: border-color 0.12s, background 0.12s; }
.civ img { width: 40px; height: 40px; border-radius: 3px; box-shadow: 0 1px 3px rgba(60, 40, 10, 0.5); }
.civ span { font-family: var(--display); font-weight: 700; font-size: 10px; color: #4a300e; margin-top: 3px; letter-spacing: 0.02em; }
.civ:hover { border-color: #8a5a1a; }
.civ.on { border-color: #7a4a10; background: rgba(255, 236, 180, 0.8); box-shadow: 0 0 0 2px rgba(217, 160, 60, 0.5); }
.civ .rnd { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; font-size: 26px; color: #6b4e22; font-family: var(--display); }
/* multiplayer: the games open to join, the room before a match, chat */
.mp-bar { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 4px; }
.mp-bar label { font-family: var(--display); font-weight: 700; font-size: 13px; color: #5a3a12; letter-spacing: 0.08em; }
#mp-name, #chat-input, #chat-line { font: inherit; font-size: 15px; color: #3a2408; background: rgba(255, 250, 235, 0.6); border: 1px solid rgba(107, 78, 34, 0.5); border-radius: 3px; padding: 4px 8px; }
#mp-name { width: 190px; }
#mp-status { min-height: 20px; margin: 6px 0 10px; font-size: 14px; color: #8a3a1a; font-style: italic; }
#mp-games { display: flex; flex-direction: column; gap: 5px; min-height: 190px; }
.mp-game { display: grid; grid-template-columns: 1.4fr 1.2fr 1.5fr 0.9fr auto; align-items: center; gap: 10px; padding: 7px 12px; border: 1px solid rgba(107, 78, 34, 0.35); border-radius: 4px; background: rgba(255, 250, 235, 0.35); font-size: 15px; color: #4a300e; text-align: left; }
.mp-game b { font-family: var(--display); font-size: 12px; letter-spacing: 0.03em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-game .st { font-style: italic; color: #6b5030; }
.mp-empty { padding: 60px 0; font-size: 16px; font-style: italic; color: #7a5a30; }
#room-note { justify-self: end; text-align: right; font-size: 15px; font-style: italic; color: #5a4020; }
#chat-log { height: 84px; overflow-y: auto; font-size: 14px; color: #4a300e; line-height: 1.35; margin-bottom: 4px; }
#chat-log b { font-family: var(--display); font-size: 11px; letter-spacing: 0.03em; }
#chat-input { width: 100%; box-sizing: border-box; }
#chat-line { position: absolute; left: 50%; bottom: 196px; transform: translateX(-50%); width: min(520px, calc(100vw - 32px)); z-index: 20; background: rgba(30, 22, 12, 0.85); color: #f4e4c0; border-color: #b88a3a; }
.seat .who.off { opacity: 0.55; }
.menu-box.in-room .seg button:disabled, .menu-box.in-room .scen.locked { cursor: default; }
.menu-box.in-room .scen.locked:hover { transform: none; }
#seats { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.seat { display: grid; grid-template-columns: 14px 96px 150px 96px 26px; align-items: center; gap: 8px; }
.seat b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .swatch { width: 14px; height: 14px; border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(40, 24, 6, 0.55); }
.seat b { font-family: var(--display); font-size: 12px; color: #4a300e; letter-spacing: 0.04em; }
.seat .who { font-size: 14px; color: #5a4020; }
.seat select { font: inherit; font-size: 13px; color: #3a2408; background: rgba(255, 250, 235, 0.55); border: 1px solid rgba(107, 78, 34, 0.5); border-radius: 3px; padding: 2px 4px; }
.seat button.x { padding: 0 6px; font-size: 14px; line-height: 18px; }
#seat-add { margin-top: 2px; }
#civ-info { min-height: 58px; font-size: 15px; color: #5a4020; line-height: 1.3; margin-top: 9px; }
#civ-info b { font-family: var(--display); font-size: 12px; color: #4a300e; letter-spacing: 0.04em; }

/* ---------- technology tree ---------- */
.tree-box { width: min(1500px, calc(100vw - 24px)); height: calc(100vh - 24px); display: flex; flex-direction: column; padding: 12px 16px 10px; position: relative; }
.tree-head { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.tree-head h2 { margin: 0; font-size: 22px; }
#tree-civs { display: flex; gap: 3px; flex: 1; flex-wrap: wrap; }
#tree-civs button { font-size: 11px; padding: 3px 8px; }
#tree-civs button.on { background: linear-gradient(180deg, #b88a3a, #7a5418); color: #fff8e0; }
#tree-body { flex: 1; overflow: auto; display: grid; grid-template-columns: 124px repeat(6, minmax(120px, 1fr)); align-content: start; border-top: 1px solid rgba(107, 78, 34, 0.4); }
.tree-age { position: sticky; top: 0; z-index: 1; background: rgba(233, 214, 170, 0.97); font-family: var(--display); font-weight: 700; font-size: 12px; color: #4a300e; text-align: center; padding: 5px 2px; border-bottom: 1px solid rgba(107, 78, 34, 0.5); border-left: 1px solid rgba(107, 78, 34, 0.2); }
.tree-bld { display: flex; align-items: center; gap: 6px; padding: 4px; border-bottom: 1px solid rgba(107, 78, 34, 0.25); font-family: var(--display); font-weight: 700; font-size: 11px; color: #4a300e; }
.tree-bld img { width: 36px; height: 36px; border-radius: 3px; }
.tree-cell { display: flex; flex-wrap: wrap; gap: 3px; align-content: flex-start; padding: 4px; border-bottom: 1px solid rgba(107, 78, 34, 0.25); border-left: 1px solid rgba(107, 78, 34, 0.15); }
.tree-node { width: 34px; height: 34px; border-radius: 3px; background-size: cover; border: 1px solid #3a2a16; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4); position: relative; cursor: default; }
.tree-node.unit { border-radius: 50%; }
.tree-node.own { border: 2px solid #c07a10; box-shadow: 0 0 0 1px #fff2c0, 0 0 8px rgba(220, 140, 20, 0.7); }
.tree-node.lack { filter: grayscale(1) brightness(0.8); opacity: 0.35; }
.tree-node.have { outline: 2px solid #3f9a3a; }
#tree-tip { min-height: 38px; margin-top: 6px; padding-top: 5px; border-top: 1px solid rgba(107, 78, 34, 0.4); font-size: 14px; line-height: 1.3; color: #4a3014; text-align: left; }
#tree-tip b { font-family: var(--display); font-size: 12px; }

.help ol { padding-left: 24px; font-size: 16px; line-height: 1.32; color: #4a3014; }
.help li { margin-bottom: 9px; padding-left: 2px; }
.help li::marker { font-family: var(--display); font-weight: 700; font-size: 13px; color: #7a5a30; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; align-items: baseline; font-size: 16px; line-height: 1.25; color: #4a3014; }
.keys dt { font-family: var(--display); font-weight: 700; font-size: 11.5px; letter-spacing: 0.04em; color: #4a300e; white-space: nowrap; }

.vol { display: flex; align-items: center; gap: 10px; justify-content: space-between; font-family: var(--display); font-weight: 700; font-size: 12px; color: #5a3a12; }
.vol input[type=range] { width: 180px; accent-color: #8a5a1a; }

#end-title { font-size: 56px; }
#end-title.defeat { color: #6e1a0e; }
#end-stats { margin: 6px auto 8px; border-collapse: collapse; font-size: 17px; min-width: 360px; }
#end-stats td { padding: 3px 14px; border-bottom: 1px solid rgba(107, 78, 34, 0.25); text-align: left; }
#end-stats td:last-child { text-align: right; font-family: var(--display); font-weight: 700; color: #4a300e; }
.end-buttons { display: flex; gap: 10px; justify-content: center; align-items: center; }

/* ---------- loading ---------- */
#loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #1c150c 0%, #05060a 75%);
  z-index: 30;
  transition: opacity 0.5s;
}
#loading.hidden { display: flex !important; opacity: 0; pointer-events: none; }
#loading .box { width: 420px; text-align: center; }
#loading h2 { font-family: var(--display); font-weight: 900; font-size: 30px; letter-spacing: 0.1em; color: var(--gold-hi); text-shadow: 0 2px 6px #000, 0 0 20px rgba(217, 180, 91, 0.3); margin-bottom: 18px; }
#loading .crest { color: var(--gold); }
#loading-status { font-size: 18px; font-style: italic; color: var(--muted); margin-bottom: 12px; }
#loading .bar { height: 8px; border: 1px solid var(--gold-lo); border-radius: 4px; background: rgba(0, 0, 0, 0.6); overflow: hidden; }
#loading-bar { height: 100%; width: 0; background: linear-gradient(90deg, #8a6a2a, var(--gold-hi)); box-shadow: 0 0 10px var(--gold); transition: width 0.25s; }
#loading-warn { margin-top: 12px; font-size: 13px; color: #c98a4b; text-align: left; max-height: 140px; overflow: auto; }

/* narrower screens drop the least needed words from the top bar first; the
   tide (a non-empty #tide) is ~150 px wider, so tide maps drop theirs sooner */
@media (max-width: 1860px) { #tide .long { display: none; } }
@media (max-width: 1700px) { #scen-name .map { display: none; } #topbar:has(#tide:not(:empty)) #track { display: none; } }
@media (max-width: 1700px) { #age.advancing > :not(#age-progress) { display: none; } #topbar:has(#age.advancing) #track { display: none; } }
@media (max-width: 1430px) { #track { display: none; } #age:has(#tide:not(:empty)) :is(#scen-name, .sep) { display: none; } }
@media (max-width: 1430px) { .res.goods .v { display: none; } .res.goods { padding-right: 4px; } }
@media (max-width: 1279px) { .res { min-width: 70px; font-size: 13px; } .res.goods { min-width: 0; } }
@media (max-width: 1279px) {
  #age-progress { width: 185px; font-size: 10px; }
  #topbar:has(#age.advancing) .res { min-width: 60px; gap: 3px; padding-right: 5px; font-size: 12px; }
  #topbar:has(#age.advancing) .res.goods { min-width: 0; padding-right: 4px; }
  #topbar:has(#age.advancing) #topbtns { gap: 4px; }
  #topbar:has(#age.advancing) #topbtns button { padding-left: 6px; padding-right: 6px; }
}
@media (max-width: 1100px) {
  #bottombar { grid-template-columns: 250px 1fr 240px; height: 160px; }
  #age { display: none; }
  #age.advancing { display: flex; }
  #topbar:has(#age.advancing) { column-gap: 6px; }
  #topbar:has(#age.advancing) .res { font-size: 11px; }
  #topbar:has(#age.advancing) .res img { width: 20px; height: 20px; }
}
