:root {
  --bg: #0d0f14;
  --panel: #161a22;
  --panel2: #1e232e;
  --border: #2b3240;
  --text: #cdd3de;
  --dim: #8a93a5;
  --accent: #ffd166;
  --accent2: #6ec1e4;
  --good: #7bd88f;
  --bad: #ff6b6b;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Cascadia Code", "Consolas", ui-monospace, monospace;
  height: 100%;
  overflow-x: hidden; /* never let stray-wide content (e.g. the map) clip the UI sideways */
  max-width: 100%;
}
.screen { max-width: 1100px; margin: 0 auto; padding: 16px; }
.hidden { display: none !important; }

h1 { text-align: center; color: var(--accent); letter-spacing: 3px; margin: 8px 0; }
.tagline { text-align: center; color: var(--dim); margin-top: 0; }
h3 { color: var(--accent2); margin: 6px 0; font-size: 15px; }

.field { margin: 12px 0; }
label { display: block; color: var(--dim); font-size: 13px; margin-bottom: 4px; }
input {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  padding: 8px 10px; border-radius: 6px; font-family: inherit; width: 100%; font-size: 14px;
}
input:focus { outline: 1px solid var(--accent2); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin: 10px 0; }

.pick-list { display: flex; flex-direction: column; gap: 4px; max-height: 280px; overflow-y: auto; }
.pick {
  text-align: left; background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  padding: 7px 9px; border-radius: 6px; cursor: pointer; font-family: inherit; font-size: 13px;
}
.pick:hover { border-color: var(--accent2); }
.pick.sel { border-color: var(--accent); background: #2a2410; }
.pick .pname { color: var(--accent); font-weight: bold; }
.pick .pdesc { color: var(--dim); font-size: 12px; }
.pick.mon .pname { color: #d98ce8; }

.pick-list.locked { opacity: 0.35; pointer-events: none; filter: grayscale(0.6); }
.lock-note {
  background: #241a2e; border: 1px solid #6d4a8a; color: #d9b8ea;
  border-radius: 6px; padding: 7px 9px; margin-bottom: 8px; font-size: 12px;
}

.stat-alloc { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat-row { background: var(--panel2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; }
.stat-row .sk { color: var(--accent2); font-weight: bold; }
.stat-row .sv { float: right; }
.stat-row .base { color: var(--dim); font-size: 11px; }
.stepper { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.stepper button { width: 26px; height: 26px; }

button {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; cursor: pointer; font-family: inherit; padding: 5px 8px;
}
button:hover { border-color: var(--accent2); }
button:active { transform: translateY(1px); }

/* touch: kill the grey tap flash, stop double-tap zoom, don't select control text */
button, .dpad button, .quickbar button, .hotslot, .map, .target-row, .world-map span.town {
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.dpad, .quickbar, .hotbar, .hud { -webkit-user-select: none; user-select: none; }
.map { cursor: pointer; } /* tap/click a tile to step that way */

.mobile-only { display: none; }   /* shown only in the phone media query */
.side-close { display: none; }    /* the overlay's close bar, phone-only */
.menu-group { display: contents; }/* reference/social buttons flow inline on desktop */
#menuToggle { display: none; }     /* the phone-only "☰ More" drawer toggle */

.big-btn { display: block; width: 100%; padding: 12px; font-size: 16px; margin-top: 10px;
  background: #2a2410; border-color: var(--accent); color: var(--accent); font-weight: bold; }
.big-btn:hover { background: #3a3216; }

/* ===== accounts UI (create screen) ===== */
.account-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 8px 12px; margin: 4px 0 12px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--panel); font-size: 14px; }
.acct-status { margin-right: auto; }
.link-btn { background: transparent; border: none; color: var(--accent2); cursor: pointer;
  text-decoration: underline; padding: 4px 6px; font-size: 14px; }
.link-btn:hover { color: var(--accent); }
.auth-form .auth-actions { display: flex; align-items: center; gap: 10px; }
.auth-form .big-btn { flex: 1; margin-top: 0; }
#authBlurb { margin: 2px 0 10px; font-size: 13px; }
.char-list { display: flex; flex-direction: column; gap: 6px; }
.char-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 6px; background: rgba(255,255,255,0.02); }
.char-info { margin-right: auto; }
.char-row button { border-color: var(--accent); color: var(--accent); padding: 7px 14px; }
.char-row button:disabled { opacity: 0.5; border-color: var(--border); color: var(--dim); cursor: default; }
.char-row .del-btn { border-color: var(--bad); color: var(--bad); padding: 7px 10px; }
.char-row .del-btn:hover:not(:disabled) { background: rgba(255,80,80,0.12); }
#claimRow { margin-top: 8px; }

/* ===== store ===== */
.store-list { display: flex; flex-direction: column; gap: 8px; }
.store-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 6px; background: rgba(255,255,255,0.02); }
.store-info { margin-right: auto; }
.store-actions button { border-color: var(--accent); color: var(--accent); padding: 8px 16px; font-weight: bold; }
.store-actions button:disabled { opacity: 0.5; border-color: var(--border); color: var(--dim); }
.color-picker { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; padding: 0; cursor: pointer; }
.swatch.sel { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }

.preview { min-height: 40px; color: var(--dim); font-size: 13px; white-space: pre-wrap; }
.error { color: var(--bad); text-align: center; margin-top: 8px; min-height: 18px; }

/* ===== Game ===== */
#game { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 1200px; }
.hud {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; font-size: 13px;
}
.hud .hp-bar { width: 140px; height: 12px; background: #3a1414; border-radius: 6px; overflow: hidden; display: inline-block; vertical-align: middle; }
.hud .hp-fill { height: 100%; background: linear-gradient(90deg,#c0392b,#e74c3c); }
.hud .xp-bar { width: 120px; height: 8px; background: #14213a; border-radius: 6px; overflow: hidden; display: inline-block; vertical-align: middle; }
.hud .xp-fill { height: 100%; background: linear-gradient(90deg,#2980b9,#6ec1e4); }
.hud .mp-bar { width: 110px; height: 12px; background: #16203a; border-radius: 6px; overflow: hidden; display: inline-block; vertical-align: middle; }
.hud .mp-fill { height: 100%; background: linear-gradient(90deg,#3b5bdb,#748ffc); }
.hud .sp-bar { width: 110px; height: 12px; background: #1a2e18; border-radius: 6px; overflow: hidden; display: inline-block; vertical-align: middle; }
.hud .sp-fill { height: 100%; background: linear-gradient(90deg,#2f9e44,#94d82d); }
.hud b { color: var(--accent); }

.main { display: flex; gap: 12px; flex: 1; min-height: 0; min-width: 0; margin: 10px 0; }
.map-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
/* min-width:0 + overflow-x:hidden stop these flex boxes from growing to the map's
   glyph width (which would push the whole UI sideways on narrow screens) */
.map-row { display: flex; gap: 10px; flex: 1; min-height: 0; min-width: 0; overflow-x: hidden; }
.map {
  background: #06080c; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px; margin: 0; line-height: 1.02; font-size: 15px; letter-spacing: 1px;
  overflow: auto; flex: 1; white-space: pre;
}
.map span { display: inline; }

/* ===== Targets-in-range panel (beside the map) ===== */
.targets-panel {
  width: 196px; flex: none; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 8px 6px; overflow-y: auto;
}
.targets-panel h4 { color: var(--accent); margin: 0 0 6px; font-size: 13px; }
.target-list { display: flex; flex-direction: column; gap: 5px; }
.target-row {
  border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px;
  cursor: pointer; background: var(--panel2); font-size: 12px;
}
.target-row:hover { border-color: var(--accent2); }
.target-row.adjacent { border-color: var(--bad); }
.target-row .trow-top { display: flex; align-items: baseline; gap: 5px; }
.target-row .tglyph { font-weight: bold; }
.target-row .tname { flex: 1; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.target-row .tdir { color: var(--dim); font-size: 10px; white-space: nowrap; }
.target-row .thp-bar {
  height: 4px; margin-top: 4px; border-radius: 2px; background: #2a1414; overflow: hidden;
}
.target-row .thp-fill { height: 100%; background: var(--bad); }
.target-row .thealth { color: var(--dim); font-size: 10px; margin-top: 2px; }
.target-row .tbadge { color: #ff3b3b; font-size: 10px; font-weight: bold; }
.target-empty { color: var(--dim); font-size: 12px; font-style: italic; padding: 4px 2px; }

.dpad { display: grid; grid-template-columns: repeat(3, 44px); gap: 4px; margin-top: 8px; justify-content: center; }
.dpad button { height: 40px; font-size: 18px; }
.quickbar { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; justify-content: center; }
.quickbar button { font-size: 13px; }
/* situational buttons are hidden until the server says they apply */
.quickbar button[data-act] { display: none; }

/* ===== Hotbar ===== */
.hotbar { display: flex; gap: 8px; margin-top: 10px; justify-content: center; }
.hotslot {
  position: relative; width: 96px; height: 50px; padding: 4px 6px;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; text-align: left; overflow: hidden; font-family: inherit;
  display: flex; flex-direction: column; justify-content: center;
}
.hotslot:hover { border-color: var(--accent2); }
.hotslot .key { position: absolute; top: 2px; right: 4px; font-size: 10px; color: var(--dim); }
.hotslot .hname { font-size: 11px; line-height: 1.15; color: var(--text); white-space: normal; }
.hotslot .hcost { font-size: 10px; margin-top: 2px; }
.hotslot.spell { border-left: 3px solid #748ffc; }
.hotslot.ability { border-left: 3px solid #94d82d; }
.hotslot.spell .hcost { color: #748ffc; }
.hotslot.ability .hcost { color: #94d82d; }
.hotslot.empty { color: var(--dim); align-items: center; justify-content: center; font-size: 20px; }
.hotslot .clear {
  position: absolute; bottom: 1px; right: 3px; font-size: 10px; color: var(--dim);
  opacity: 0; transition: opacity 0.1s;
}
.hotslot:hover .clear { opacity: 1; }
.hotslot .clear:hover { color: var(--bad); }

/* assignment picker */
#hotPicker {
  position: fixed; z-index: 60; background: var(--panel); border: 1px solid var(--accent);
  border-radius: 8px; padding: 6px; max-height: 320px; overflow-y: auto; width: 240px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.6);
}
#hotPicker .pick-head { color: var(--accent2); font-size: 11px; margin: 4px 4px 2px; }
#hotPicker .pick-opt {
  display: flex; justify-content: space-between; padding: 5px 7px; border-radius: 5px;
  cursor: pointer; font-size: 12px;
}
#hotPicker .pick-opt:hover { background: var(--panel2); }
#hotPicker .pick-opt .c { color: var(--dim); }

.side { width: 300px; }
.sheet {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; font-size: 13px; height: 100%; overflow-y: auto;
}
.sheet h4 { color: var(--accent); margin: 8px 0 4px; }
.sheet .stat-line { display: flex; justify-content: space-between; }
.sheet .eq { color: var(--good); }
.sheet .muted { color: var(--dim); }

.log {
  height: 170px; overflow-y: auto; background: #06080c; border: 1px solid var(--border);
  border-radius: 8px; padding: 8px; font-size: 13px; line-height: 1.4;
}
.log div { margin: 1px 0; }
.log .chat { color: var(--accent2); }
.log .world { color: #7fd0ff; font-weight: bold; }
.log .sys { color: var(--dim); }
.log .hit { color: #ffb86c; }
.log .lvl { color: var(--good); font-weight: bold; }
.log .dead { color: var(--bad); font-weight: bold; }

.cmdline { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.cmdline .prompt { color: var(--accent); }
.cmdline input { flex: 1; }

/* ===== Inventory modal ===== */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-box {
  background: var(--panel); border: 1px solid var(--accent); border-radius: 10px;
  width: min(860px, 94vw); max-height: 88vh; overflow: hidden; display: flex; flex-direction: column;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
.x-btn { border: none; background: none; color: var(--dim); font-size: 18px; }
.x-btn:hover { color: var(--bad); }
.modal-body { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 14px; overflow-y: auto; }
.modal-body h4 { color: var(--accent2); margin: 4px 0 6px; }
.inv-col { min-width: 0; }

.eq-slot { display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; margin-bottom: 5px; }
.eq-slot .slot-label { color: var(--dim); font-size: 12px; width: 62px; flex: none; }
.eq-slot .slot-item { flex: 1; color: var(--good); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eq-slot .slot-item.empty { color: var(--dim); font-style: italic; }

.inv-items { display: flex; flex-direction: column; gap: 5px; max-height: 48vh; overflow-y: auto; }
.inv-row { background: var(--panel2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; }
.inv-row .iname { font-size: 13px; }
.inv-row .idesc { color: var(--dim); font-size: 11px; }
.inv-row .iactions { display: flex; gap: 5px; margin-top: 4px; flex-wrap: wrap; }
.inv-row .iactions button { font-size: 11px; padding: 2px 8px; }
.wpn { color: #ffb86c; } .arm { color: #8be0e0; } .con { color: #8be08b; } .foc { color: #d98ce8; }

.shop-greeting {
  padding: 8px 14px; color: var(--accent2); font-style: italic; font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.world-map {
  margin: 0; line-height: 0.62; letter-spacing: -1px; font-size: 11px;
  font-family: "Cascadia Code", "Consolas", monospace; white-space: pre; cursor: default;
}
#lbTabs button { font-size: 12px; padding: 5px 10px; }
#lbTabs button.lb-on { border-color: var(--accent); background: #2a2410; color: var(--accent); }
.world-map span.town { cursor: pointer; }
.world-map span.town:hover { outline: 1px solid #fff; }

.craft-body { padding: 14px; }
.craft-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.craft-row label { width: 60px; color: var(--dim); font-size: 13px; flex: none; }
.craft-row select {
  flex: 1; background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  padding: 7px 9px; border-radius: 6px; font-family: inherit; font-size: 13px;
}
.inv-row .price { float: right; color: var(--accent); font-weight: bold; }
.inv-row .reward { float: right; color: var(--good); font-size: 11px; }
.job-prog { height: 6px; background: #222833; border-radius: 4px; overflow: hidden; margin-top: 4px; }
.job-prog > span { display: block; height: 100%; background: linear-gradient(90deg,#c98a2b,#ffd166); }
.inv-row.done { border-color: var(--good); }
.inv-row.done .iname { color: var(--good); }
.inv-row.afford .iactions button { border-color: var(--accent); }
.inv-row.cantafford { opacity: 0.55; }

textarea {
  width: 100%; background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 8px; font-family: inherit; font-size: 13px; resize: vertical;
}
.desc-actions { display: flex; gap: 6px; margin-top: 6px; }

/* ===== Tablet / small screens: the character sheet becomes a slide-over ===== */
@media (max-width: 860px) {
  .side { display: none; }
  .side.show {
    display: block; position: fixed; inset: 0; z-index: 45; width: auto;
    background: var(--bg); overflow-y: auto;
    padding: 10px 12px calc(env(safe-area-inset-bottom) + 24px);
  }
  .side.show .side-close {
    display: block; position: sticky; top: 0; width: 100%; margin-bottom: 8px;
    background: var(--panel); border-color: var(--accent); color: var(--accent);
    padding: 11px; font-size: 15px; font-weight: bold;
  }
  .side.show .sheet { height: auto; border: none; padding: 0; }
  .mobile-only { display: inline-block; }
  .targets-panel { width: 140px; }
}

/* ===== Phones: fit the map, enlarge tap targets, compact the chrome ===== */
@media (max-width: 640px) {
  .screen { padding: 8px; }
  .targets-panel { display: none; }
  .two-col { grid-template-columns: 1fr; }
  .modal-body { grid-template-columns: 1fr; }
  .main { gap: 0; margin: 8px 0; }

  /* shrink the glyphs so all 41 map columns fit the screen width (no h-scroll) */
  .map { font-size: calc((100vw - 30px) / 25); letter-spacing: 0; line-height: 1.08; padding: 6px; }

  /* compact HUD with slimmer bars */
  .hud { gap: 6px 10px; padding: 6px 8px; font-size: 11px; }
  .hud .hp-bar { width: 78px; height: 10px; }
  .hud .mp-bar, .hud .sp-bar { width: 60px; height: 10px; }
  .hud .xp-bar { width: 64px; height: 7px; }

  /* fat-finger controls — d-pad is a compact secondary aid (tap-the-map is primary) */
  .dpad { grid-template-columns: repeat(3, 1fr); gap: 5px; width: 100%; max-width: 258px; margin-top: 6px; }
  .dpad button { height: 38px; font-size: 18px; }
  .quickbar { gap: 8px; }
  .quickbar button { font-size: 14px; padding: 9px 13px; min-height: 44px; }
  /* collapse the reference/social buttons behind "☰ More" to reclaim vertical space */
  #menuToggle { display: inline-block; background: var(--panel); border-color: var(--accent); color: var(--accent); font-weight: bold; }
  .menu-group { display: none; }
  .menu-group.show { display: contents; }
  .hotbar { gap: 6px; flex-wrap: wrap; }
  .hotslot { width: 60px; height: 44px; }

  .log { height: 132px; font-size: 12px; }
  /* 16px input stops iOS Safari from zooming the page when the keyboard opens */
  .cmdline input { font-size: 16px; padding: 9px 10px; }
  .modal-box { width: 96vw; max-height: 90vh; }
  .modal-body { padding: 10px; }
}
