:root {
  --gold: #d9b45a;
  --gold-d: #8a6a2a;
  --ink: #3a2410;
  --ink-soft: #6a4a26;
  --text: #f4e8cc;
  --muted: #c8b48c;
  --bad: #c0261c;
  --bad-l: #ff7a68;
  --panel-h: 176px;
  --top-h: 42px;
  --wood: url(assets/ui_wood.png);
  --parch: url(assets/ui_parchment.png);
  --head: "Cinzel", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #000; color: var(--text); font: 13px/1.35 Georgia, "Times New Roman", serif; user-select: none; }
canvas { image-rendering: pixelated; }
#view { position: fixed; inset: 0; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
img { image-rendering: pixelated; }

/* Ornate frame: dark outer line, gold inner bevel. */
.frame {
  border: 2px solid #120a04;
  box-shadow: inset 0 0 0 1px var(--gold), inset 0 0 0 3px #2a1a0c, 0 0 0 1px var(--gold-d);
}

/* ---------------- top bar */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--top-h); display: flex; align-items: center; gap: 10px; padding: 0 10px;
  background: var(--wood); border-bottom: 2px solid var(--gold); box-shadow: 0 2px 0 #120a04, 0 4px 12px rgba(0, 0, 0, 0.6); z-index: 5;
}
.res {
  display: flex; align-items: center; gap: 4px; min-width: 92px; height: 32px; padding: 0 8px 0 2px;
  font: 700 15px var(--head); font-variant-numeric: tabular-nums; color: #fff4d6; text-shadow: 1px 1px 0 #000;
  background: rgba(0, 0, 0, 0.42); border: 1px solid #120a04; box-shadow: inset 0 0 0 1px rgba(217, 180, 90, 0.5);
}
.res img { width: 32px; height: 32px; }
#topbar > button {
  display: flex; align-items: center; gap: 5px; height: 32px; padding: 0 10px 0 4px; position: relative;
  font: 700 13px var(--head); color: #fff4d6; text-shadow: 1px 1px 0 #000;
  background: linear-gradient(#5a3a1c, #2e1c0c); border: 1px solid #120a04; box-shadow: inset 0 0 0 1px var(--gold-d);
}
#topbar > button img { width: 32px; height: 32px; }
#topbar > button:hover { box-shadow: inset 0 0 0 1px var(--gold); }
#idle-btn.has-idle { box-shadow: inset 0 0 0 1px var(--gold), 0 0 6px var(--gold); }
#age-name { font: 700 16px var(--head); color: var(--gold); text-shadow: 1px 1px 0 #000; letter-spacing: 1px; padding: 0 12px; }
#home-btn.ready { animation: pulse 0.9s infinite alternate; }
@keyframes pulse { to { background: linear-gradient(#8a5a20, #4a2c10); box-shadow: inset 0 0 0 1px var(--gold), 0 0 8px var(--gold); } }
#xp-bar { position: absolute; left: 3px; right: 3px; bottom: 2px; height: 3px; background: #000; }
#xp-fill { height: 100%; background: linear-gradient(90deg, #b88a2a, #ffe08a); width: 0; }
.spacer { flex: 1; }
#clock { font: 700 15px var(--head); font-variant-numeric: tabular-nums; text-shadow: 1px 1px 0 #000; }
#speed { display: flex; gap: 2px; }
#speed button { height: 26px; padding: 0 7px; font: 700 12px var(--head); background: #2e1c0c; border: 1px solid #120a04; box-shadow: inset 0 0 0 1px var(--gold-d); color: var(--muted); }
#speed button.on { color: #fff4d6; background: #7a4e1e; box-shadow: inset 0 0 0 1px var(--gold); }
#help-btn { width: 32px; justify-content: center; padding: 0 !important; }

/* ---------------- messages */
#messages { position: fixed; left: 12px; bottom: calc(var(--panel-h) + 10px); z-index: 4; display: flex; flex-direction: column; gap: 3px; pointer-events: none; }
.msg { font: 600 13px var(--head); text-shadow: 1px 1px 0 #000, 0 0 4px #000; padding: 1px 4px; transition: opacity 1s; pointer-events: auto; cursor: default; color: #fff4d6; }
.msg.alert { color: #ff8a78; cursor: pointer; }
.msg.age { color: var(--gold); font-size: 15px; }
.msg.ship { color: #a8d0ff; }
.msg.err { color: #ffb0a0; }

/* ---------------- bottom panel */
#panel {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--panel-h); display: flex; gap: 8px; padding: 10px 10px 8px; z-index: 5;
  background: var(--wood); border-top: 2px solid var(--gold); box-shadow: 0 -2px 0 #120a04, 0 -4px 14px rgba(0, 0, 0, 0.6);
}
#commands {
  display: grid; grid-template-columns: repeat(5, 40px); grid-template-rows: repeat(3, 40px); gap: 4px; padding: 8px; flex: none;
  background: rgba(0, 0, 0, 0.45); align-content: center;
}
#info {
  flex: 1; min-width: 0; padding: 10px 12px; overflow: hidden; display: flex; gap: 12px; color: var(--ink);
  background: var(--parch); background-size: 128px;
}
#map-frame { flex: none; width: 260px; display: grid; place-items: center; background: #0a0603; }
#minimap { width: 232px; height: 116px; cursor: pointer; image-rendering: auto; }

.cmd {
  position: relative; width: 40px; height: 40px; padding: 0; display: grid; place-items: center;
  background: linear-gradient(#3a2614, #1e1208); border: 1px solid #000; box-shadow: inset 0 0 0 1px var(--gold-d), inset 0 0 0 3px #1a0f06;
}
.cmd:hover { box-shadow: inset 0 0 0 1px var(--gold), inset 0 0 0 3px #3a2410; }
.cmd.active { box-shadow: inset 0 0 0 2px #ffe08a, 0 0 6px #ffe08a; }
.cmd.disabled .icon { filter: grayscale(1) brightness(0.5); }
.cmd.poor .icon { filter: brightness(0.55) sepia(0.6) hue-rotate(-30deg); }
.cmd .key { position: absolute; top: 0; left: 2px; font: 700 9px var(--head); color: var(--gold); text-shadow: 1px 1px 0 #000; }
.cmd .badge { position: absolute; bottom: 0; right: 2px; font: 700 11px var(--head); color: #fff; text-shadow: 1px 1px 0 #000; }
.cmd.empty { background: rgba(0, 0, 0, 0.25); box-shadow: inset 0 0 0 1px rgba(138, 106, 42, 0.25); pointer-events: none; }
.icon { width: 32px; height: 32px; background-repeat: no-repeat; }

.portrait { width: 72px; height: 72px; flex: none; background-color: rgba(58, 36, 16, 0.85); border: 2px solid #120a04; box-shadow: inset 0 0 0 1px var(--gold); background-repeat: no-repeat; background-origin: content-box; padding: 2px; }
.info-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.info-main h3 { margin: 0; font: 700 17px var(--head); color: #5a1a0a; letter-spacing: 0.5px; }
.info-main .owner { font-size: 12px; color: var(--ink-soft); font-style: italic; }
.hpbar { height: 9px; background: #1a0f06; border: 1px solid #1a0f06; width: 220px; }
.hpbar > div { height: 100%; background: linear-gradient(#7aee6a, #2e9a2a); }
.stats { color: var(--ink); font-size: 12px; columns: 2; column-gap: 20px; }
.stats b { color: #5a1a0a; }
.stats i { color: var(--ink-soft); }
.queue { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.qitem { width: 36px; height: 36px; border: 1px solid #120a04; background-color: #2a1a0c; position: relative; cursor: pointer; background-repeat: no-repeat; box-shadow: inset 0 0 0 1px var(--gold-d); }
.qitem .prog { position: absolute; left: 0; bottom: 0; height: 4px; background: #4a9cff; }
.qitem:hover { box-shadow: inset 0 0 0 1px var(--bad-l); }
.warn { color: var(--bad); font-weight: bold; }
.multi { display: flex; flex-wrap: wrap; gap: 3px; align-content: flex-start; }
.mini { width: 36px; height: 40px; border: 1px solid #120a04; background-color: rgba(58, 36, 16, 0.85); position: relative; cursor: pointer; background-repeat: no-repeat; box-shadow: inset 0 0 0 1px var(--gold-d); }
.mini .hp { position: absolute; left: 2px; right: 2px; bottom: 2px; height: 3px; background: #000; }
.mini .hp > div { height: 100%; background: #4fd64f; }
.mini:hover { box-shadow: inset 0 0 0 1px var(--gold); }

#tooltip {
  position: fixed; z-index: 20; max-width: 320px; padding: 9px 12px; pointer-events: none; color: var(--ink);
  background: var(--parch); border: 2px solid #120a04; box-shadow: inset 0 0 0 1px var(--gold-d), 0 6px 18px rgba(0, 0, 0, 0.6);
}
#tooltip h4 { margin: 0 0 4px; font: 700 14px var(--head); color: #5a1a0a; }
#tooltip small { color: var(--ink-soft); }
#tooltip .cost { display: flex; gap: 10px; margin: 4px 0; font-weight: bold; }
#tooltip .cost span { display: flex; align-items: center; gap: 2px; }
#tooltip .cost img { width: 24px; height: 24px; image-rendering: auto; }
#tooltip .cost .short { color: var(--bad); }
#tooltip .lock { color: var(--bad); margin-top: 4px; font-weight: bold; }
#tooltip .desc { color: var(--ink); }

/* ---------------- modals */
.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(0, 0, 0, 0.62); }
.modal[hidden] { display: none; }
.card-panel {
  max-width: 760px; padding: 22px 30px; color: var(--ink); background: var(--parch);
  border: 10px solid transparent; border-image: var(--wood) 16 round;
  box-shadow: 0 0 0 2px var(--gold), 0 0 0 4px #120a04, 0 14px 50px #000;
}
.card-panel h1 { margin: 0; font: 700 46px var(--head); color: #5a1a0a; text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.4); letter-spacing: 2px; }
.card-panel h2 { margin: 0 0 10px; font: 700 24px var(--head); color: #5a1a0a; }
.card-panel h3 { margin: 14px 0 4px; font: 700 15px var(--head); color: #5a1a0a; }
.card-panel .sub { margin-top: 2px; color: var(--ink-soft); font-style: italic; }
.card-panel table { border-collapse: collapse; }
.card-panel td { padding: 2px 12px 2px 0; vertical-align: top; }
.card-panel td:first-child { color: #5a1a0a; font-weight: bold; white-space: nowrap; }
.card-panel.title { text-align: center; }
.card-panel label { display: block; margin: 14px 0; font: 700 14px var(--head); }
select { font: inherit; padding: 4px; margin-left: 8px; background: #f8ecd0; color: var(--ink); border: 1px solid var(--gold-d); }
button.big {
  padding: 8px 30px; margin-top: 10px; font: 700 17px var(--head); color: #fff4d6; text-shadow: 1px 1px 0 #000; letter-spacing: 1px;
  background: linear-gradient(#8a5a24, #4a2c10); border: 2px solid #120a04; box-shadow: inset 0 0 0 1px var(--gold);
}
button.big:disabled { opacity: 0.5; cursor: default; }
button.big:hover:not(:disabled) { background: linear-gradient(#a86e2c, #5a3614); }
.error { color: var(--bad); white-space: pre-wrap; text-align: left; }

.cards { display: grid; grid-template-columns: repeat(4, 156px); gap: 10px; margin: 12px 0; }
.hc-card {
  text-align: left; padding: 8px 10px; height: 88px; display: flex; flex-direction: column; justify-content: space-between;
  color: #fff4d6; text-shadow: 1px 1px 0 #000; background: linear-gradient(#5a3a1c, #2e1c0c);
  border: 2px solid #120a04; box-shadow: inset 0 0 0 1px var(--gold);
}
.hc-card b { font: 700 15px var(--head); }
.hc-card .age { font-size: 11px; color: var(--muted); }
.hc-card.locked { filter: grayscale(1); opacity: 0.55; cursor: default; }
.hc-card:not(.locked):hover { background: linear-gradient(#7a4e22, #3e2410); box-shadow: inset 0 0 0 2px #ffe08a; }
.stats-table td { padding: 2px 18px 2px 0; }
