:root {
  --bg: #1c1610;
  --panel: #2b2117;
  --panel2: #3a2c1d;
  --edge: #8a6a3a;
  --edge-dark: #4a3720;
  --text: #ece0c4;
  --muted: #b8a682;
  --gold: #e2bd62;
  --good: #8fdc7a;
  --bad: #ff8a7a;
  --link: #9fd3ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.4 Verdana, Geneva, sans-serif; overflow: hidden; }
button, input, select { font: inherit; }
[hidden] { display: none !important; }

.panel-bg {
  background-color: var(--panel);
  background-image: linear-gradient(rgba(20,14,8,.78), rgba(20,14,8,.78)), url(/assets/img/MiscFormTexture.png);
}
.screen { position: fixed; inset: 0; }

/* ---------- buttons ---------- */
button {
  background: linear-gradient(#5a442a, #3a2b1a); color: var(--text); border: 1px solid var(--edge);
  border-radius: 3px; padding: 6px 12px; cursor: pointer; min-height: 32px;
}
button:hover { border-color: var(--gold); color: #fff; }
button:active { background: #2a1f13; }
button.primary { background: linear-gradient(#8a6a32, #5c4420); color: #fff; }
button.small { padding: 3px 8px; min-height: 28px; font-size: 12px; }
button.toggle.on { border-color: var(--gold); color: var(--gold); }
button:disabled { opacity: .45; cursor: default; }
.icon-btn { width: 40px; height: 40px; padding: 0; display: inline-grid; place-items: center; }
.icon-btn img { width: 24px; height: 24px; image-rendering: pixelated; }
.icon-btn.active { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }

input, select {
  background: #120d08; color: var(--text); border: 1px solid var(--edge-dark); border-radius: 3px; padding: 6px 8px; min-height: 32px;
}
input:focus, select:focus { outline: 1px solid var(--gold); }

/* ---------- dialogs ---------- */
.dialog {
  width: min(420px, calc(100vw - 32px)); margin: auto; padding: 20px;
  background: var(--panel2); border: 2px solid var(--edge); border-radius: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.6);
  display: flex; flex-direction: column; gap: 10px;
}
.dialog h1 { margin: 0; font: bold 32px/1.1 Georgia, serif; color: var(--gold); letter-spacing: 1px; text-align: center; }
.dialog h3 { margin: 0 0 4px; color: var(--gold); }
.dialog label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.dialog .row { display: flex; gap: 8px; flex-wrap: wrap; }
.dialog .row > * { flex: 1; }
.logo { width: 120px; align-self: center; }
.sub { margin: 0; text-align: center; color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; margin: 0; }
#screen-login { display: grid; place-items: center; }

/* ---------- top bars ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 6px 10px; flex-wrap: wrap;
  background: rgba(30,22,14,.92); border-bottom: 1px solid var(--edge); color: var(--gold);
}
.topbar .brand { font: bold 20px Georgia, serif; }
.topbar .spacer { flex: 1; }
.game-top { position: absolute; left: 0; right: 0; top: 0; z-index: 5; padding-top: max(6px, env(safe-area-inset-top)); }
#hud-name { font-weight: bold; }
#hud-coords { color: var(--muted); font-size: 12px; }

/* ---------- game ---------- */
#map { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; image-rendering: pixelated; }
#minimap-wrap {
  position: absolute; right: 10px; top: 52px; z-index: 4; padding: 3px;
  background: var(--panel); border: 2px solid var(--edge); border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,.5);
}
#minimap { display: block; width: 300px; height: 150px; image-rendering: pixelated; touch-action: none; cursor: pointer; }
#panel {
  position: absolute; left: 10px; bottom: 10px; z-index: 4; width: 360px; max-height: calc(100% - 70px);
  overflow-y: auto; border: 2px solid var(--edge); border-radius: 5px; padding: 10px; box-shadow: 0 2px 10px rgba(0,0,0,.6);
}
#panel .hint { color: var(--muted); margin: 0; }
#chat {
  position: absolute; right: 10px; bottom: 10px; z-index: 4; width: 340px; height: 220px;
  border: 2px solid var(--edge); border-radius: 5px; padding: 8px;
}
#chat.collapsed { display: none; }
.sel-head { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.sel-head .glyph { width: 48px; height: 48px; image-rendering: pixelated; border: 1px solid var(--edge-dark); background: #000; object-fit: contain; }
.sel-head .title { font-weight: bold; color: var(--gold); font-size: 14px; }
.sel-head .owner { color: var(--muted); font-size: 12px; }
.stats { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 2px 8px; font-size: 12px; margin-bottom: 8px; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; }
.cmds { display: flex; flex-wrap: wrap; gap: 4px; }
.cmds .sep { flex-basis: 100%; height: 4px; }
.group-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; max-height: 140px; overflow: auto; }
.group-list .item { display: flex; gap: 8px; align-items: center; padding: 2px 4px; cursor: pointer; border-radius: 3px; }
.group-list .item:hover { background: rgba(255,255,255,.06); }
.group-list img { width: 24px; height: 24px; image-rendering: pixelated; }
.build-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 4px; }
.build-grid button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px; font-size: 11px; }
.build-grid canvas { width: 48px; height: 48px; image-rendering: pixelated; }
.build-grid .cost { color: var(--muted); font-size: 10px; }
.bar { height: 6px; background: #000; border: 1px solid var(--edge-dark); border-radius: 2px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--gold); }
.mode-banner { background: rgba(226,189,98,.15); border: 1px solid var(--gold); color: var(--gold); padding: 4px 8px; border-radius: 3px; margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#toast {
  position: absolute; left: 50%; top: 56px; transform: translateX(-50%); z-index: 9; pointer-events: none;
  background: rgba(20,14,8,.92); border: 1px solid var(--edge); color: var(--text); padding: 6px 12px; border-radius: 4px; opacity: 0; transition: opacity .2s;
}
#toast.show { opacity: 1; }
#toast.err { color: var(--bad); border-color: var(--bad); }
#modal { position: absolute; inset: 0; z-index: 20; background: rgba(0,0,0,.5); display: grid; place-items: center; overflow: auto; padding: 16px; }
#modal .dialog { max-height: calc(100vh - 32px); overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 12px; }
.table th, .table td { text-align: left; padding: 3px 4px; border-bottom: 1px solid var(--edge-dark); }
.table th { color: var(--muted); font-weight: normal; }
.table input { width: 70px; min-height: 26px; padding: 2px 4px; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  #minimap-wrap { right: 6px; top: 48px; }
  #minimap { width: 150px; height: 75px; }
  #panel { left: 0; right: 0; bottom: 0; width: auto; max-height: 45vh; border-radius: 10px 10px 0 0; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  #chat { left: 6px; right: 6px; width: auto; bottom: auto; top: 130px; height: 40vh; }
  #hud-coords { display: none; }
  .topbar { gap: 8px; }
}
.sel-head .deselect { margin-left: auto; align-self: flex-start; min-width: 32px; font-size: 16px; line-height: 1; }
.tile-list-head { display: flex; justify-content: space-between; align-items: center; color: var(--gold); font-size: 12px; margin: 4px 0; }
.group-list .item { min-height: 32px; }
.group-list .item.current { background: rgba(226,189,98,.18); outline: 1px solid var(--gold); }
.group-list .owner { color: var(--bad); font-size: 11px; }

/* settings dialog */
.dialog.wide { width: min(640px, calc(100vw - 32px)); }
.dialog h4 { margin: 10px 0 4px; color: var(--gold); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.dialog label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); padding: 3px 0; cursor: pointer; }
.dialog label.check input { min-height: 0; width: 16px; height: 16px; flex: none; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--edge); padding-bottom: 6px; }
.tabs .tab.on { border-color: var(--gold); color: var(--gold); background: linear-gradient(#6a5030, #4a3820); }
.tab-page { min-height: 260px; }

/* ---------- chat UI ---------- */
.chatui { display: flex; flex-direction: column; min-height: 0; flex: 1; height: 100%; }
.chat-tabs { display: flex; gap: 3px; overflow-x: auto; padding-bottom: 4px; flex: none; scrollbar-width: thin; }
.ctab { white-space: nowrap; padding: 3px 8px; min-height: 28px; font-size: 12px; display: inline-flex; align-items: center; gap: 4px; }
.ctab.on { border-color: var(--gold); color: var(--gold); background: linear-gradient(#6a5030, #4a3820); }
.ctab b { background: var(--bad); color: #000; border-radius: 8px; padding: 0 5px; font-size: 10px; }
.ctab .x { opacity: .6; padding: 0 2px; }
.ctab .x:hover { opacity: 1; color: var(--bad); }
.ctab.add { font-weight: bold; }
.chat-topic { font-size: 11px; color: var(--muted); padding: 2px 4px; border-bottom: 1px solid var(--edge-dark); }
.chat-log { flex: 1; overflow-y: auto; background: rgba(0,0,0,.4); border: 1px solid var(--edge-dark); padding: 6px; font-size: 12px; min-height: 60px; }
.chat-log .line { margin: 1px 0; overflow-wrap: anywhere; }
.chat-log .line.old { opacity: .6; }
.chat-log .from { color: var(--gold); font-weight: bold; cursor: pointer; }
.chat-log .sys { color: var(--muted); font-style: italic; }
.chat-log .alert { color: var(--bad); cursor: pointer; }
.chat-log .news, .chat-log .announce { color: #ffe070; font-weight: bold; }
.chat-form { display: flex; gap: 6px; margin-top: 6px; }
.chat-form input { flex: 1; min-width: 0; }
.chan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 4px; }
#player-menu { position: fixed; z-index: 30; min-width: 180px; background: var(--panel2); border: 1px solid var(--edge); border-radius: 4px; padding: 4px; display: flex; flex-direction: column; gap: 2px; box-shadow: 0 4px 16px rgba(0,0,0,.6); }
#player-menu[hidden] { display: none; }
#player-menu .pm-title { color: var(--gold); font-weight: bold; padding: 4px 6px; }
#player-menu button { text-align: left; min-height: 32px; }
#chat .chatui { height: 100%; }

.chatbox { display: flex; flex-direction: column; min-height: 0; }

/* ---------- awards ---------- */
i.award {
  display: inline-block; width: var(--s); height: var(--s); vertical-align: middle; margin-left: 2px; flex: none;
  background: url(/assets/img/MiscAwardIcons12.png) no-repeat; background-size: var(--s) calc(var(--s) * 40);
  background-position: 0 calc(var(--s) * var(--i) * -1); image-rendering: pixelated;
}
.award-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.award-row.big { font-size: 14px; }
#lobby-user { cursor: pointer; }
.special-awards { display: flex; flex-direction: column; }

/* ---------- player options: popover (desktop) / bottom sheet (phones) ---------- */
#player-menu { position: fixed; z-index: 60; min-width: 220px; background: var(--panel2); border: 1px solid var(--edge); border-radius: 10px; padding: 6px; display: flex; flex-direction: column; gap: 2px; box-shadow: 0 12px 32px rgba(0,0,0,.6); }
#player-menu[hidden], #player-scrim[hidden] { display: none; }
#player-menu .pm-title { display: flex; align-items: center; gap: 8px; padding: 6px 10px 8px; border-bottom: 1px solid rgba(226,189,98,.18); margin-bottom: 4px; color: var(--gold); flex-wrap: wrap; }
#player-menu .pm-title span { color: var(--muted); font-size: 12px; flex-basis: 100%; }
#player-menu .pm-title .flag { width: 20px; height: 12.5px; image-rendering: pixelated; }
#player-menu button { text-align: left; min-height: 34px; background: transparent; border: 0; border-radius: 6px; color: var(--text); padding: 6px 10px; }
#player-menu button:hover { background: rgba(226,189,98,.16); }
#player-scrim { position: fixed; inset: 0; z-index: 59; background: rgba(0,0,0,.45); }
#player-menu.sheet { left: 0; right: 0; bottom: 0; top: auto; border-radius: 16px 16px 0 0; padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); max-height: 80vh; overflow: auto; animation: sheet-up .18s ease-out; }
#player-menu.sheet::before { content: ""; width: 40px; height: 4px; border-radius: 4px; background: rgba(226,189,98,.4); align-self: center; margin: 2px 0 6px; }
#player-menu.sheet button { min-height: 48px; font-size: 15px; }
#player-menu.sheet .pm-cancel { margin-top: 6px; text-align: center; border: 1px solid rgba(226,189,98,.3); }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }

/* ---------- in game: phones in landscape (side panel instead of bottom sheet) ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  .game-top { padding: 3px 8px; padding-left: max(8px, env(safe-area-inset-left)); gap: 8px; }
  .game-top button.small { min-height: 26px; padding: 2px 8px; }
  #hud-coords { display: none; }
  #minimap-wrap { right: max(6px, env(safe-area-inset-right)); top: 40px; }
  #minimap { width: 140px; height: 70px; }
  #panel {
    left: max(6px, env(safe-area-inset-left)); right: auto; top: 40px; bottom: auto; width: min(320px, 42vw);
    max-height: calc(100% - 46px); border-radius: 10px; padding-bottom: 10px;
  }
  #chat { left: auto; right: max(6px, env(safe-area-inset-right)); top: 116px; bottom: 6px; width: min(320px, 40vw); height: auto; }
}

/* ---------- zoom buttons (pinch also zooms on touch screens) ---------- */
#zoom-ctl { position: absolute; z-index: 4; right: 10px; top: 214px; display: flex; flex-direction: column; border: 2px solid var(--edge); border-radius: 8px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
#zoom-ctl button { width: 40px; height: 40px; min-height: 0; padding: 0; border: 0; border-radius: 0; font: bold 22px/1 Verdana, sans-serif; background: linear-gradient(#5a442a, #3a2b1a); }
#zoom-ctl button + button { border-top: 1px solid var(--edge); }
#minimap-wrap[hidden] + #zoom-ctl { top: 52px; }
#panel[hidden] { display: none; }
@media (max-width: 760px) {
  #zoom-ctl { top: 136px; right: 6px; }
  #zoom-ctl button { width: 44px; height: 44px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  #zoom-ctl { top: auto; bottom: 10px; right: max(10px, env(safe-area-inset-right)); flex-direction: row; }
  #zoom-ctl button + button { border-top: 0; border-left: 1px solid var(--edge); }
}

/* city panel: clear all zoned (planned) facilities */
.clear-zones { display: block; width: 100%; margin-top: 8px; }

/* troops aboard a ship */
.group-list .tag { font-size: 10px; text-transform: uppercase; letter-spacing: .4px; color: #8fc6ff; border: 1px solid rgba(143,198,255,.4); border-radius: 4px; padding: 0 4px; margin-left: 4px; }

/* ---------- alliance dialog ---------- */
.alliance .al-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; max-height: 46vh; overflow: auto; }
.alliance .al-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 8px 10px; background: rgba(0,0,0,.25); border: 1px solid rgba(226,189,98,.18); border-radius: 8px; }
.alliance .al-join { display: flex; gap: 6px; align-items: center; }
.alliance .al-join input { width: 110px; }
.alliance .al-create { display: flex; gap: 6px; flex-wrap: wrap; }
.alliance .al-create input { flex: 1; min-width: 120px; }
.alliance .tag { font-size: 10px; text-transform: uppercase; letter-spacing: .4px; color: var(--gold); border: 1px solid rgba(226,189,98,.45); border-radius: 4px; padding: 0 4px; margin-left: 4px; }
.alliance .tag.pending { color: #8fc6ff; border-color: rgba(143,198,255,.45); }
.alliance .error:empty { display: none; }
button.danger { border-color: #a94a3a; color: #ffb4a6; }

/* About box wordmark (the original logo image spells the old name) */
.about-mark { align-self: center; font: 700 40px/1.1 Georgia, "Times New Roman", serif; letter-spacing: 2px; color: var(--gold, #e2bd62); text-shadow: 0 2px 0 #000; margin: 4px 0 8px; }

/* ---------- Revifact brand: Cinzel (SIL OFL, self-hosted in /fonts) ---------- */
@font-face { font-family: "Cinzel Decorative"; font-weight: 700; font-display: swap; src: url(/fonts/cinzel-decorative-latin-700-normal.woff2) format("woff2"); }
@font-face { font-family: "Cinzel Decorative"; font-weight: 900; font-display: swap; src: url(/fonts/cinzel-decorative-latin-900-normal.woff2) format("woff2"); }
@font-face { font-family: "Cinzel"; font-weight: 400; font-display: swap; src: url(/fonts/cinzel-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Cinzel"; font-weight: 700; font-display: swap; src: url(/fonts/cinzel-latin-700-normal.woff2) format("woff2"); }
.brand-lockup { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-bottom: 4px; }
.brand-emblem { width: 148px; height: 148px; filter: drop-shadow(0 6px 18px rgba(255, 140, 40, .28)) drop-shadow(0 2px 3px rgba(0, 0, 0, .7)); }
.dialog h1.brand-word {
  margin: 6px 0 0; font: 900 44px/1 "Cinzel Decorative", Georgia, serif; letter-spacing: 3px;
  background: linear-gradient(180deg, #fff3c4 0%, #ecc46c 38%, #b07c2c 72%, #f0cd78 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 2px 0 #000) drop-shadow(0 0 14px rgba(255, 160, 60, .18));
}
.brand-tag { margin: 6px 0 0; font: 700 11px/1.2 Cinzel, Georgia, serif; letter-spacing: 2px; white-space: nowrap; text-transform: uppercase; color: #c9a868; }
.brand-tag::before, .brand-tag::after { content: ""; display: inline-block; width: 16px; height: 1px; background: linear-gradient(90deg, transparent, #c9a868); vertical-align: middle; margin: 0 7px; }
.brand-tag::after { background: linear-gradient(270deg, transparent, #c9a868); }
.brand-sub { margin: 6px 0 0; font: italic 400 15px/1.2 Georgia, "Times New Roman", serif; letter-spacing: .5px; color: #e9d3a0; text-shadow: 0 1px 0 #000; }
.about-mark { font-family: "Cinzel Decorative", Georgia, serif; font-weight: 900; }
.wordmark-emblem { width: 30px; height: 30px; vertical-align: middle; margin: -4px 8px 0 0; }
@media (max-width: 760px), (max-height: 520px) {
  .brand-emblem { width: 112px; height: 112px; }
  .dialog h1.brand-word { font-size: 34px; }
  .brand-tag { letter-spacing: 1.2px; font-size: 10px; }
  .brand-tag::before, .brand-tag::after { display: none; }
  .brand-sub { font-size: 14px; }
  .wordmark-emblem { width: 24px; height: 24px; margin-right: 6px; }
}

/* ---------- login / sign-up ---------- */
#login-form[data-mode="login"] .signup-only, #login-form[data-mode="signup"] .login-only { display: none; }
#login-form .signup-only { display: flex; flex-direction: column; gap: 10px; }
#login-form p.switch.signup-only { display: block; }
#login-form[data-mode="login"] p.switch.signup-only { display: none; }
#login-form .fine { margin: 0; font-size: 12px; line-height: 1.45; color: var(--muted); }
#login-form .switch { margin: 0; text-align: center; font-size: 13px; color: var(--muted); }
#login-form .legal { margin: -4px 0 0; text-align: center; font-size: 11px; }
#login-form a { color: var(--gold); }
#login-form .error:empty { display: none; }
#login-submit { width: 100%; min-height: 40px; font-weight: 700; }

/* taps fire immediately (no double-tap-to-zoom wait) on every control */
button, [data-act], [data-sel], a { touch-action: manipulation; }

/* ---------- install the app ---------- */
#login-form .install-link { background: none; border: 1px dashed rgba(226,189,98,.45); color: var(--gold); border-radius: 8px; min-height: 36px; font-size: 13px; }
#login-form .install-link[hidden] { display: none; }
.icon-only { display: inline-flex; align-items: center; justify-content: center; padding: 4px 8px; }
#btn-fullscreen[hidden] { display: none; }
#install-bar { position: fixed; z-index: 70; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 10px;
  padding: 10px 10px 10px 12px; background: linear-gradient(#3a2c1c, #241a10); border: 1px solid rgba(226,189,98,.5); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.6); animation: sheet-up .2s ease-out; }
#install-bar[hidden] { display: none; }
#install-bar img { border-radius: 8px; flex: none; }
#install-bar .ib-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
#install-bar .ib-text b { color: var(--gold); }
#install-bar .ib-text span { font-size: 12px; color: var(--muted); }
#install-bar .ib-x { background: none; border: 0; color: var(--muted); font-size: 22px; min-height: 0; padding: 0 4px; }
#ios-install { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; padding: 12px; }
#ios-install[hidden] { display: none; }
#ios-install .ios-card { width: min(420px, 100%); background: var(--panel2, #2a2016); border: 1px solid rgba(226,189,98,.4); border-radius: 16px; padding: 18px 18px calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px; animation: sheet-up .2s ease-out; }
#ios-install img { border-radius: 12px; }
#ios-install h3 { margin: 0; font-family: "Cinzel", Georgia, serif; color: var(--gold); }
#ios-install ol { margin: 4px 0 8px; padding-left: 20px; line-height: 1.6; }
#ios-install .ios-share { width: 18px; height: 18px; vertical-align: -3px; color: #4ea3ff; }
#ios-install button { width: 100%; min-height: 42px; }
/* keep the install bar clear of the lobby's bottom tabs on phones, and out of the way in a game */
@media (max-width: 760px) { body:has(#screen-lobby:not([hidden])) #install-bar { bottom: calc(62px + env(safe-area-inset-bottom)); } }
body:has(#screen-game:not([hidden])) #install-bar { display: none; }
/* narrow phones: keep the game's top bar to two rows (buttons + full-screen icon on one line) */
@media (max-width: 480px) {
  .game-top { column-gap: 5px; }
  .game-top button.small { padding-left: 7px; padding-right: 7px; }
}
