:root {
  --ink: #2a1a12;
  --text: #3b2a20;
  --muted: #7a5f45;
  --cream: #fbf3dc;
  --gold: #f2c14e;
  --sol: #9945ff;
  --teal: #14f195;
  --font: 'Pixelify Sans', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1a1420;
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: none;
  user-select: none;
}
button { font: inherit; color: inherit; }
#game {
  position: fixed;
  inset: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}
.hidden { display: none !important; }

/* pixel frames (9-slice sources generated in sprites.js) */
.panel {
  border-style: solid;
  border-width: 18px;
  border-image: var(--frame-panel) 6 fill / 18px / 0 stretch;
  image-rendering: pixelated;
}
.panel.dark, .chip-dark {
  border-width: 9px;
  border-image: var(--frame-dark) 3 fill / 9px / 0 stretch;
  color: var(--cream);
}

kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 1px 5px 2px;
  margin: 0 3px;
  font: 600 13px var(--font);
  color: var(--cream);
  background: #3a2418;
  border: 2px solid #120c10;
  box-shadow: inset 0 -2px 0 #1e120c;
  text-align: center;
}

.btn {
  cursor: pointer;
  padding: 7px 14px 9px;
  font-size: 18px;
  font-weight: 600;
  color: #fff6e0;
  background: #93633a;
  border: 3px solid var(--ink);
  box-shadow: inset 0 3px 0 #c99357, inset 0 -4px 0 #5a3822;
  text-shadow: 2px 2px 0 #3a2418;
  image-rendering: pixelated;
}
.btn:hover:not(:disabled) { background: #a8723f; }
.btn:active:not(:disabled) { box-shadow: inset 0 4px 0 #5a3822; padding: 9px 14px 7px; }
.btn.primary { background: #4b8b44; box-shadow: inset 0 3px 0 #86c254, inset 0 -4px 0 #2b5e3a; text-shadow: 2px 2px 0 #1e4a34; }
.btn.primary:hover:not(:disabled) { background: #579a4c; }
.btn:disabled { cursor: default; background: #8a7a6a; box-shadow: inset 0 3px 0 #a89a8a, inset 0 -4px 0 #6a5a4a; color: #e8dcc8; text-shadow: none; }
.btn kbd { font-size: 11px; padding: 0 4px; margin: 0 0 0 6px; vertical-align: 2px; }

/* ---------------------------------------------------------------- title */
#title {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity .6s;
}
.ready #title { opacity: 1; }
.title-col { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-top: -4vh; }
#logo canvas { display: block; image-rendering: pixelated; }
.tagline {
  margin: -4px 0 6px;
  font-size: 22px;
  font-weight: 600;
  color: #fff6e0;
  text-shadow: 2px 2px 0 #2a160c, -2px 2px 0 #2a160c, 2px -2px 0 #2a160c, -2px -2px 0 #2a160c, 0 4px 0 #1a0e08;
}
.menu { display: flex; flex-direction: column; gap: 10px; min-width: 300px; padding: 4px; }
.menu .btn { width: 100%; font-size: 20px; }
#title-msg { margin: 2px 0 0; min-height: 1em; font-size: 15px; color: #a03a2a; text-align: center; max-width: 280px; }
#title-msg:empty { display: none; }
.menu .back { text-align: center; font-size: 15px; color: var(--muted); }
.menu .back:hover { color: var(--text); }
.controls {
  position: fixed;
  bottom: 14px;
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-size: 15px;
  color: #fff6e0;
  text-shadow: 2px 2px 0 #1a0e08;
  padding: 0 16px;
}

/* ---------------------------------------------------------------- HUD */
#clock {
  position: fixed;
  top: 12px;
  left: 12px;
  min-width: 168px;
  font-weight: 600;
}
#clock .row1 { display: flex; justify-content: space-between; align-items: center; font-size: 17px; color: var(--muted); }
#h-time { font-size: 30px; line-height: 1.05; color: var(--text); margin: 2px 0 4px; }
#clock .gold { display: flex; align-items: center; gap: 6px; font-size: 20px; padding-top: 6px; border-top: 2px solid #d9c69c; }
#clock .gold img { width: 24px; height: 24px; image-rendering: pixelated; }
#clock .gold em { font-style: normal; color: var(--muted); }
.wx { display: inline-block; width: 24px; height: 24px; background-size: 24px; image-rendering: pixelated; vertical-align: middle; }
.wx.sun { background-image: var(--ic-sun); }
.wx.rain { background-image: var(--ic-rain); }

#ledger-chip {
  position: fixed;
  top: 12px;
  right: 12px;
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  column-gap: 8px;
  cursor: pointer;
  background: none;
  text-align: left;
}
#ledger-chip img { grid-row: span 2; width: 32px; height: 32px; image-rendering: pixelated; }
#ledger-chip .amt { font-size: 18px; font-weight: 600; }
#ledger-chip .amt b { font-size: 22px; color: #5b2fa8; }
#ledger-chip small { font-size: 14px; color: var(--muted); }
#ledger-chip:hover { filter: brightness(1.05); }

#energy {
  position: fixed;
  right: 12px;
  bottom: 12px;
  width: 40px;
  height: 170px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
#energy .bar { flex: 1; width: 12px; background: #120c10; position: relative; }
#energy .bar i { position: absolute; left: 0; right: 0; bottom: 0; background: #73b452; box-shadow: inset 3px 0 0 #9fd067, inset -3px 0 0 #3d7a3f; transition: height .2s; }
#energy .bar i.low { background: #d94a3a; box-shadow: inset 3px 0 0 #f0806a, inset -3px 0 0 #7a1f24; }
#energy b { font-size: 14px; color: #f2c14e; }

#dock {
  position: fixed;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
#hotbar { display: flex; gap: 2px; padding: 0; }
.slot {
  position: relative;
  width: 50px;
  height: 50px;
  padding: 0;
  cursor: pointer;
  background: none;
  border-style: solid;
  border-width: 6px;
  border-image: var(--frame-slot) 3 fill / 6px / 0 stretch;
  image-rendering: pixelated;
}
.slot.sel { border-image: var(--frame-slot-sel) 3 fill / 6px / 0 stretch; transform: translateY(-3px); }
.slot img { width: 32px; height: 32px; display: block; margin: auto; image-rendering: pixelated; }
.slot b { position: absolute; right: -2px; bottom: -4px; font-size: 15px; color: #fff6e0; text-shadow: 2px 0 0 #2a1a12, -2px 0 0 #2a1a12, 0 2px 0 #2a1a12, 0 -2px 0 #2a1a12; }
.slot .k { position: absolute; left: -2px; top: -5px; font-style: normal; font-size: 11px; color: #8a6a48; }
.slot .water { position: absolute; left: 2px; right: 2px; bottom: -2px; height: 4px; background: #25485e; text-decoration: none; }
.slot .water u { display: block; height: 100%; background: #7fb8cc; }
#held { font-size: 16px; font-weight: 600; color: #fff6e0; text-shadow: 2px 2px 0 #1a0e08; min-height: 1.2em; }
#prompt {
  padding: 4px 12px 6px 6px;
  font-size: 17px;
  color: var(--cream);
  background: #2a1d22;
  border: 3px solid #120c10;
  box-shadow: inset 0 0 0 2px #553420;
}
#prompt kbd { margin-right: 8px; background: #b5814d; color: #2a1a12; border-color: #120c10; box-shadow: inset 0 -2px 0 #734a2c; }

#toasts { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast {
  padding: 5px 14px 7px;
  font-size: 17px;
  color: var(--cream);
  background: #2a1d22;
  border: 3px solid #120c10;
  box-shadow: inset 0 0 0 2px #553420;
  animation: pop .18s steps(3);
  transition: opacity .4s;
  white-space: nowrap;
}
.toast.gold { box-shadow: inset 0 0 0 2px #b5832a; }
.toast.stead { box-shadow: inset 0 0 0 2px var(--sol); color: #e6d6ff; }
.toast.warn { box-shadow: inset 0 0 0 2px #b2302e; }
.toast.out { opacity: 0; }
@keyframes pop { from { transform: translateY(-6px); opacity: 0; } }

.icon-btn {
  position: fixed;
  right: 12px;
  bottom: 196px;
  width: 40px;
  height: 40px;
  font-size: 20px;
  cursor: pointer;
  color: var(--cream);
  background: #2a1d22;
  border: 3px solid #120c10;
  box-shadow: inset 0 0 0 2px #553420;
}
.icon-btn.off { color: #7a6a6a; text-decoration: line-through; }

/* ---------------------------------------------------------------- dialog */
#dialog {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  width: min(700px, calc(100vw - 32px));
  min-height: 132px;
  padding: 6px 8px 4px;
  cursor: pointer;
}
#dialog .name {
  position: absolute;
  top: -40px;
  left: -4px;
  padding: 3px 12px 5px;
  font-size: 19px;
  font-weight: 700;
  color: #fff2b8;
  background: #3a2418;
  border: 3px solid #120c10;
  box-shadow: inset 0 0 0 2px #93633a;
}
#dialog .text { font-size: 22px; line-height: 1.38; white-space: pre-wrap; min-height: 3.6em; }
#dialog .more { position: absolute; right: 2px; bottom: -6px; font-size: 14px; color: var(--muted); animation: bob .6s steps(2) infinite; }
#dialog .choices { display: flex; gap: 10px; justify-content: flex-end; }
#dialog .choices:empty { display: none; }
@keyframes bob { 50% { transform: translateY(3px); } }

/* ---------------------------------------------------------------- modals */
#modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(20, 12, 24, .45); }
.sheet { width: min(600px, calc(100vw - 24px)); max-height: calc(100vh - 40px); overflow: auto; }
.sheet header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.sheet h2 { margin: 0; font-size: 28px; color: #5a2f14; }
.sheet h3 { margin: 14px 0 6px; font-size: 18px; color: var(--muted); }
.purse, .who { display: flex; align-items: center; gap: 6px; font-size: 20px; font-weight: 600; }
.purse img { width: 24px; height: 24px; image-rendering: pixelated; }
.addr { padding: 2px 10px 4px; color: var(--cream); background: #3a2418; border: 2px solid #120c10; font-size: 16px; }
.list { display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; background: #ead9b0; border: 2px solid #c9b48a; }
.row img { width: 32px; height: 32px; image-rendering: pixelated; flex: none; }
.row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row b { font-size: 18px; }
.row small { font-size: 14px; color: var(--muted); }
.row .price { font-size: 18px; font-weight: 600; color: #8a5a14; min-width: 54px; text-align: right; }
.row .btn { font-size: 15px; padding: 4px 9px 6px; }
.row .btn:active:not(:disabled) { padding: 6px 9px 4px; }
.row.order.done { opacity: .6; }
.tier { display: inline-block; margin-right: 8px; padding: 0 6px 2px; font-size: 13px; color: #fff6e0; border: 2px solid #120c10; vertical-align: 2px; }
.t-easy { background: #4b8b44; }
.t-medium { background: #b5832a; }
.t-hard { background: #b2302e; }
.reset { font-size: 14px; font-weight: 400; margin-left: 6px; }
.bloomline { display: flex; align-items: center; gap: 6px; margin: 10px 0 0; font-size: 16px; }
.bloomline img { width: 24px; height: 24px; image-rendering: pixelated; }
.meter { height: 8px; background: #c9b48a; border: 2px solid #8a7050; margin: 2px 0; }
.meter i { display: block; height: 100%; background: #4b8b44; }
.row.order.done .meter i { background: var(--sol); }
.reward { display: flex; align-items: center; gap: 4px; font-size: 18px; font-weight: 700; color: #5b2fa8; }
.reward img { width: 22px; height: 22px; }
.bank { display: flex; align-items: center; gap: 14px; padding: 10px 12px; background: #2a1d22; color: var(--cream); border: 3px solid #120c10; box-shadow: inset 0 0 0 2px #5b2fa8; }
.bank img { width: 48px; height: 48px; image-rendering: pixelated; }
.bank div { flex: 1; display: flex; flex-direction: column; }
.bank small { font-size: 14px; color: #c8b8e8; }
.bank b { font-size: 34px; line-height: 1; }
.sheet footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 14px; }
.note { font-size: 14px; color: var(--muted); line-height: 1.3; }
.empty { margin: 8px 0; font-size: 16px; color: var(--muted); }
.total { display: flex; justify-content: space-between; margin-top: 10px; padding-top: 8px; border-top: 2px solid #c9b48a; font-size: 22px; }
.total b { color: #8a5a14; }
.forecast { display: flex; align-items: center; gap: 8px; font-size: 17px; margin: 10px 0 0; }
.warnline { margin: 0 0 8px; color: #a03a2a; font-size: 17px; }

@media (max-width: 760px) {
  .slot { width: 40px; height: 40px; }
  .slot img { width: 24px; height: 24px; }
  #clock { min-width: 130px; }
  #h-time { font-size: 22px; }
}

.ledger-status { margin: 10px 0 0; padding: 6px 10px; font-size: 15px; background: #ead9b0; border: 2px solid #c9b48a; }
.ledger-status.warn { color: #8a2a1e; border-color: #c98a7a; background: #f3d9c8; }
.ledger-status b { color: #5b2fa8; }

/* leaderboard + names */
#board-btn.board { top: 104px; right: 12px; bottom: auto; width: auto; height: auto; display: flex; align-items: center; gap: 6px; padding: 4px 10px 6px 6px; font: 600 15px var(--font); }
#board-btn img { width: 24px; height: 24px; image-rendering: pixelated; }
.tabs { display: flex; gap: 4px; }
.tab { cursor: pointer; padding: 3px 10px 5px; font: 600 15px var(--font); color: var(--text); background: #e2cf9f; border: 2px solid #8a7050; }
.tab.on { color: #fff6e0; background: #5a2f14; border-color: #120c10; }
.board-sub { margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 52vh; overflow: auto; }
.brow { display: flex; align-items: center; gap: 10px; padding: 5px 8px; background: #ead9b0; border: 2px solid #c9b48a; }
.brow.you { border-color: #5b2fa8; box-shadow: inset 4px 0 0 #9945ff; }
.rk { min-width: 30px; text-align: center; font-size: 16px; font-weight: 700; color: var(--muted); }
.rk.r1, .rk.r2, .rk.r3 { color: #fff6e0; border: 2px solid #120c10; padding: 0 4px 2px; }
.rk.r1 { background: #c98b2a; }
.rk.r2 { background: #8b93a3; }
.rk.r3 { background: #9a5a3a; }
.who { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.who b { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { font-size: 12px; color: var(--muted); }
.val { display: flex; align-items: center; gap: 4px; font-size: 17px; font-weight: 700; color: #5b2fa8; }
.val img { width: 20px; height: 20px; image-rendering: pixelated; }
.board-empty { margin: 10px 0; font-size: 16px; color: var(--muted); }
.board-actions { display: flex; gap: 8px; }
.name-help { margin: 0 0 10px; font-size: 16px; line-height: 1.35; }
.name-form { display: flex; gap: 8px; }
.name-form input { flex: 1; min-width: 0; padding: 8px 10px; font: 600 20px var(--font); color: var(--text); background: #fbf3dc; border: 3px solid #5a3822; outline: none; }
.name-form input:focus { border-color: #9945ff; }
.name-err { min-height: 1.2em; margin: 8px 0 0; font-size: 15px; color: #a03a2a; }

/* game menu */
#menu-btn.menu-toggle { top: 136px; left: 12px; right: auto; bottom: auto; width: auto; height: auto; display: flex; align-items: center; gap: 8px; padding: 5px 12px 7px 9px; font: 600 15px var(--font); }
#menu-btn .bars { display: flex; flex-direction: column; gap: 3px; }
#menu-btn .bars i { display: block; width: 14px; height: 2px; background: #fff2b8; }
.menusheet { width: min(380px, calc(100vw - 24px)); }
.menu-who { font-size: 14px; color: var(--muted); text-align: right; }
.menu-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.menu-list .btn { width: 100%; text-align: left; display: flex; justify-content: space-between; align-items: center; }
.menu-note { margin: 12px 0 0; font-size: 14px; color: var(--muted); }
