/* Mistfall Helper interface.
   The palette, quality colours and panel textures are the game's own: colours
   come from ColorPalette/ItemRarity, textures from the UI export baked into
   /assets by tools/build_game_assets.py. */

:root {
  --ink:        #e6d9cc;
  --ink-dim:    #9a8f84;
  --ink-faint:  #6b625a;
  --void:       #080706;
  --pit:        #100e0c;
  --panel:      #17140f;
  --panel-high: #1f1b15;
  --edge:       #38301f;
  --edge-soft:  #262016;

  --gold:       #d7aa7e;
  --gold-warm:  #e5b043;
  --ember:      #e78a2e;
  --blood:      #d2461b;
  --moss:       #689c64;
  --frost:      #5a95b1;

  --q-none:    #a98964;
  --q-gray:    #7e7e7e;
  --q-white:   #9c9c9c;
  --q-green:   #689c64;
  --q-blue:    #5a95b1;
  --q-purple:  #9b5ab1;
  --q-yellow:  #e5b043;
  --q-orange:  #d2461b;
  --q-rainbow: #9b5ab1;
  --q-currency:#e5b043;

  --rail: 84px;
  --title: 'Trajan Pro', 'Bookman Old Style', 'Palatino Linotype', Georgia, serif;
  --body: 'Segoe UI', Roboto, -apple-system, 'Helvetica Neue', sans-serif;
  --numeric: 'Consolas', 'SF Mono', 'Roboto Mono', monospace;
}

*, *::before, *::after { box-sizing: border-box; }

/* The boot screen, the shell and the modal are toggled with the `hidden`
   attribute, and each of them sets `display` here. An author `display` beats
   the user agent's `[hidden] { display: none }`, so without this rule `hidden`
   would silently do nothing to them. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--void) url('/assets/ui/window-bg.webp') center / cover no-repeat fixed;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(120% 90% at 50% 0%, rgba(0,0,0,.15), rgba(0,0,0,.86) 78%);
  pointer-events: none;
  z-index: 0;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold); }

/* -- boot ------------------------------------------------------------- */

.boot {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-content: center; justify-items: center; gap: 18px;
  background: var(--void);
  color: var(--ink-dim);
  letter-spacing: .12em; text-transform: uppercase; font-size: 12px;
}
.boot-mark {
  width: 64px; height: 64px;
  background: url('/assets/nav/home.webp') center / contain no-repeat;
  opacity: .5;
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: .7; } }

/* -- shell ------------------------------------------------------------ */

#shell {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 16px 0;
  background: linear-gradient(180deg, rgba(12,10,8,.94), rgba(8,7,6,.97));
  border-right: 1px solid var(--edge-soft);
  position: sticky; top: 0; height: 100vh;
}

.rail-item {
  position: relative;
  width: 60px; height: 58px;
  display: grid; place-items: center; gap: 3px;
  border: 0; border-radius: 4px;
  background: transparent;
  cursor: pointer;
  color: var(--ink-faint);
  transition: color .15s, background .15s;
}
.rail-item img { width: 30px; height: 30px; opacity: .55; transition: opacity .15s, filter .15s; }
.rail-item span { font-size: 9.5px; letter-spacing: .06em; text-transform: uppercase; }
.rail-item:hover { color: var(--gold); background: rgba(215,170,126,.06); }
.rail-item:hover img { opacity: .9; }
.rail-item[aria-current='page'] { color: var(--gold-warm); background: rgba(215,170,126,.1); }
.rail-item[aria-current='page'] img { opacity: 1; filter: drop-shadow(0 0 6px rgba(229,176,67,.45)); }
.rail-item[aria-current='page']::before {
  content: ''; position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 2px; background: var(--gold-warm);
}
.rail-badge {
  position: absolute; top: 6px; right: 8px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--blood); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
}

.stage { display: flex; flex-direction: column; min-width: 0; }

/* -- top bar ---------------------------------------------------------- */

.topbar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 12px 24px;
  border-bottom: 1px solid var(--edge-soft);
  background: linear-gradient(180deg, rgba(16,14,12,.92), rgba(10,9,8,.72));
  backdrop-filter: blur(2px);
}

.identity { display: flex; align-items: center; gap: 12px; min-width: 0; }
.identity h1 {
  margin: 0; font-family: var(--title); font-size: 17px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase; white-space: nowrap;
}
.identity .sub { font-size: 12px; color: var(--ink-dim); }

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--edge);
  background: rgba(0,0,0,.35);
  font-size: 12px; letter-spacing: .04em;
}
.pill::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-faint); box-shadow: 0 0 8px currentColor;
}
.pill.is-running { color: var(--moss); border-color: rgba(104,156,100,.4); }
.pill.is-running::before { background: var(--moss); }
.pill.is-connecting { color: var(--gold-warm); border-color: rgba(229,176,67,.4); }
.pill.is-connecting::before { background: var(--gold-warm); animation: pulse 1.2s ease-in-out infinite; }
.pill.is-paused, .pill.is-role_selection { color: var(--ember); border-color: rgba(231,138,46,.4); }
.pill.is-paused::before, .pill.is-role_selection::before { background: var(--ember); }
.pill.is-error, .pill.is-credentials_rejected { color: var(--blood); border-color: rgba(210,70,27,.45); }
.pill.is-error::before, .pill.is-credentials_rejected::before { background: var(--blood); }

.purse { display: flex; align-items: center; gap: 14px; margin-left: auto; flex-wrap: wrap; }
.coin { display: inline-flex; align-items: center; gap: 6px; font-family: var(--numeric); font-size: 13px; }
.coin img { width: 22px; height: 22px; }
.coin b { font-weight: 600; color: var(--gold-warm); }

.account-switch {
  display: flex; align-items: center; gap: 6px;
  padding: 3px; border: 1px solid var(--edge-soft); border-radius: 4px;
  background: rgba(0,0,0,.3);
}
.account-switch button {
  border: 0; background: transparent; border-radius: 3px;
  padding: 4px 10px; font-size: 12.5px; color: var(--ink-dim); cursor: pointer;
}
.account-switch button[aria-pressed='true'] { background: rgba(215,170,126,.14); color: var(--gold-warm); }

/* -- view / panels ---------------------------------------------------- */

.view { padding: 24px; flex: 1; outline: none; }
.view:focus-visible { outline: none; }

.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(460px, 1fr)); }

.panel {
  position: relative;
  border: 1px solid var(--edge-soft);
  background:
    linear-gradient(180deg, rgba(31,27,21,.86), rgba(12,11,9,.93)),
    url('/assets/ui/window-panel.webp') center / cover;
  box-shadow: inset 0 1px 0 rgba(215,170,126,.06), 0 12px 30px rgba(0,0,0,.45);
}
.panel::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  border: 1px solid rgba(0,0,0,.6); margin: 1px;
}

.panel > header {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--edge-soft);
  background: linear-gradient(180deg, rgba(56,48,31,.28), transparent);
}
.panel > header img { width: 22px; height: 22px; opacity: .8; }
.panel > header h2 {
  margin: 0; flex: 1;
  font-family: var(--title); font-size: 13.5px; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase; color: var(--gold);
}
.panel > header .aside { font-size: 12px; color: var(--ink-dim); font-family: var(--numeric); }
.panel > .body { padding: 16px; }
.panel.is-ready { border-color: rgba(229,176,67,.45); }
.panel.is-ready > header h2 { color: var(--gold-warm); }

.section-title {
  margin: 0 0 12px;
  font-family: var(--title); font-size: 12px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--ink-dim);
}

.muted { color: var(--ink-dim); }
.faint { color: var(--ink-faint); }
.empty { padding: 22px 8px; text-align: center; color: var(--ink-faint); font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: grid; gap: 10px; }
.num { font-family: var(--numeric); }

/* -- buttons ---------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 18px; min-height: 34px;
  border: 1px solid var(--edge);
  background: linear-gradient(180deg, rgba(56,48,31,.5), rgba(20,17,13,.8));
  color: var(--ink);
  font-size: 13px; letter-spacing: .06em;
  cursor: pointer;
  transition: border-color .15s, color .15s, transform .05s;
}
.btn:hover:not(:disabled) { border-color: var(--gold); color: var(--gold-warm); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary {
  border-color: rgba(229,176,67,.55);
  background: linear-gradient(180deg, rgba(120,86,32,.55), rgba(40,28,12,.85));
  color: var(--gold-warm);
}
.btn.danger { border-color: rgba(210,70,27,.55); color: #f0a58c; }
.btn.danger:hover:not(:disabled) { border-color: var(--blood); color: #ffbba3; }
.btn.ghost { background: transparent; border-color: var(--edge-soft); color: var(--ink-dim); }
.btn.small { padding: 4px 10px; min-height: 26px; font-size: 12px; }

/* -- fields ------------------------------------------------------------ */

.field { display: grid; gap: 5px; }
.field > label { font-size: 11.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-dim); }
.field input, .field select {
  padding: 8px 11px;
  border: 1px solid var(--edge-soft);
  background: rgba(0,0,0,.45) url('/assets/ui/input-bg.webp') center / 100% 100% no-repeat;
  color: var(--ink);
  font-family: var(--numeric);
}
.field input:focus, .field select:focus { outline: 1px solid var(--gold); border-color: var(--gold); }
.field .hint { font-size: 11.5px; color: var(--ink-faint); }
.field.bad input { border-color: var(--blood); }

/* -- item cells -------------------------------------------------------- */

.cells { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }

.cell {
  position: relative;
  /* A fixed size by default: outside the .cells grid a cell sits in a flex row,
     where `width: 100%` would blow it up to the width of the whole panel. */
  aspect-ratio: 1; width: 52px; flex: 0 0 auto;
  border: 1px solid var(--edge-soft);
  background: rgba(0,0,0,.5) url('/assets/ui/cell-bg.webp') center / 100% 100% no-repeat;
  cursor: default;
  display: grid; place-items: center;
  padding: 0;
}
.cell::before {
  content: ''; position: absolute; inset: 0;
  border: 2px solid var(--cell-color, transparent);
  box-shadow: inset 0 0 16px -6px var(--cell-color, transparent);
  pointer-events: none;
}
/* A thin strip of the rarity colour along the bottom, as the game's bag cells
   mark quality. */
.cell::after {
  content: ''; position: absolute; left: 2px; right: 2px; bottom: 2px; height: 2px;
  background: var(--cell-color, transparent);
  opacity: .85; pointer-events: none;
}
.cell img { width: 84%; height: 84%; object-fit: contain; }
.cell .count {
  position: absolute; right: 3px; bottom: 1px;
  font-family: var(--numeric); font-size: 11px; font-weight: 700;
  color: var(--ink); text-shadow: 0 1px 2px #000, 0 0 4px #000;
}
/* Inside the grid the track decides the size. */
.cells > .cell { width: 100%; }

.cell.button { cursor: pointer; }
.cell.button:hover { border-color: var(--gold); }
.cell.is-selected { border-color: var(--gold-warm); box-shadow: 0 0 0 1px var(--gold-warm); }
.cell.empty-slot { background-image: none; opacity: .35; }

.item-line { display: flex; align-items: center; gap: 10px; min-width: 0; }
.item-line .cell { width: 44px; }
.item-line .text { flex: 1; min-width: 0; }
.item-line .name,
.item-line .meta {
  display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.item-line .name { font-size: 13.5px; color: var(--item-color, var(--ink)); }
.item-line .meta { font-size: 11.5px; color: var(--ink-faint); }

/* A long forged-item name and the large countdown share one row.  A generic
   flex spread let the text keep its intrinsic width and slide under the timer. */
.forge-queue-head {
  display: grid; grid-template-columns: minmax(0, 1fr) max-content;
  align-items: center; gap: 12px; min-width: 0;
}
.forge-queue-head > .item-line { min-width: 0; overflow: hidden; }
.forge-queue-head > .timer { white-space: nowrap; }

/* -- timers / progress -------------------------------------------------- */

.timer {
  font-family: var(--numeric); font-size: 22px; letter-spacing: .04em;
  color: var(--gold); font-variant-numeric: tabular-nums;
}
.timer.is-ready { color: var(--gold-warm); text-shadow: 0 0 12px rgba(229,176,67,.4); }

.bar {
  position: relative; height: 8px;
  border: 1px solid var(--edge-soft);
  background: rgba(0,0,0,.55) url('/assets/ui/progress-bg.webp') center / 100% 100% no-repeat;
  overflow: hidden;
}
.bar > i {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--ember), var(--gold-warm));
  box-shadow: 0 0 10px rgba(229,176,67,.5);
  transition: width .8s linear;
}

/* -- lists / tables ------------------------------------------------------ */

.list { display: grid; gap: 1px; background: var(--edge-soft); border: 1px solid var(--edge-soft); }
.list > * {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; background: rgba(12,11,9,.88);
  min-width: 0;
}
.list > * > * { min-width: 0; }
.list > * > .btn, .list > * > .pill, .list > * > .num { flex: 0 0 auto; white-space: nowrap; }
.list > *.is-active { background: rgba(56,48,31,.32); }
.list > button { text-align: left; border: 0; cursor: pointer; width: 100%; }
.list > button:hover { background: rgba(56,48,31,.24); }

.market-row { align-items: stretch; }
.market-main { flex: 1 1 auto; min-width: 0; display: grid; gap: 7px; }
.market-facts {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px;
  padding-left: 54px; color: var(--ink-dim); font-size: 11.5px;
}
.market-facts .price { color: var(--gold-warm); }
.market-facts .expiry.expired { color: var(--blood); }
.market-row > .btn { align-self: center; width: auto; flex: 0 0 auto; }

.requirement-list { display: grid; gap: 6px; }
.requirement {
  display: grid; grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center; gap: 9px; min-width: 0;
  padding: 6px 8px; border: 1px solid var(--edge-soft);
  background: rgba(0,0,0,.24);
}
.requirement .cell { width: 34px; }
.requirement .label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.requirement .amount { color: var(--moss); font-size: 11.5px; white-space: nowrap; }
.requirement.is-missing { border-color: rgba(210,70,27,.42); }
.requirement.is-missing .amount { color: #f0a58c; }
.scav-route { display: grid; gap: 8px; padding: 8px 0; border-top: 1px solid var(--edge-soft); }
.scav-route:first-child { border-top: 0; }

.tabs { display: flex; gap: 2px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button {
  padding: 6px 14px; border: 1px solid var(--edge-soft); border-bottom: 0;
  background: rgba(0,0,0,.35); color: var(--ink-dim);
  font-size: 12.5px; letter-spacing: .05em; cursor: pointer;
}
.tabs button[aria-pressed='true'] {
  color: var(--gold-warm);
  background: rgba(56,48,31,.35);
  border-color: var(--edge);
}

/* -- modal --------------------------------------------------------------- */

.modal {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center; padding: 20px;
  background: rgba(4,3,3,.78);
  backdrop-filter: blur(3px);
}
.modal-card {
  width: min(560px, 100%); max-height: 88vh; overflow: auto;
  border: 1px solid var(--edge);
  background: linear-gradient(180deg, rgba(31,27,21,.98), rgba(10,9,8,.99));
  box-shadow: 0 30px 80px rgba(0,0,0,.7);
}
.modal-card > header {
  padding: 14px 20px; border-bottom: 1px solid var(--edge-soft);
  background: url('/assets/ui/window-title.webp') center / cover;
}
.modal-card > header h2 {
  margin: 0; font-family: var(--title); font-size: 15px;
  letter-spacing: .12em; text-transform: uppercase; color: var(--gold-warm);
}
.modal-card > .body { padding: 20px; display: grid; gap: 16px; }
.modal-card > footer {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 14px 20px; border-top: 1px solid var(--edge-soft);
}
.modal-card.severity-market > header { box-shadow: inset 0 -2px 0 var(--gold-warm); }
.modal-card.severity-spend > header { box-shadow: inset 0 -2px 0 var(--ember); }

.ledger { display: grid; gap: 8px; }
.ledger h3 {
  margin: 0; font-size: 11px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink-dim);
}
.ledger.costs h3 { color: var(--blood); }
.ledger.gains h3 { color: var(--moss); }

/* -- toasts -------------------------------------------------------------- */

.toasts {
  position: fixed; right: 18px; bottom: 18px; z-index: 60;
  display: grid; gap: 8px; width: min(360px, calc(100vw - 36px));
}
.toast {
  padding: 11px 14px;
  border: 1px solid var(--edge);
  border-left-width: 3px;
  background: rgba(16,14,12,.97);
  box-shadow: 0 12px 30px rgba(0,0,0,.55);
  animation: rise .22s ease-out;
}
.toast b { display: block; font-size: 13px; }
.toast span { font-size: 12px; color: var(--ink-dim); }
.toast.success { border-left-color: var(--moss); }
.toast.warning { border-left-color: var(--ember); }
.toast.error   { border-left-color: var(--blood); }
.toast.info    { border-left-color: var(--gold); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* -- gate (login / pairing) ---------------------------------------------- */

.gate {
  min-height: 100vh; display: grid; place-items: center; padding: 28px;
}
.gate-card {
  width: min(520px, 100%); text-align: center;
  border: 1px solid var(--edge);
  background: linear-gradient(180deg, rgba(31,27,21,.9), rgba(8,7,6,.97));
  padding: 40px 32px;
}
.gate-card img.mark { width: 72px; height: 72px; opacity: .75; }
.gate-card h1 {
  font-family: var(--title); font-size: 21px; letter-spacing: .16em;
  text-transform: uppercase; margin: 18px 0 8px; color: var(--gold);
}
.gate-card p { color: var(--ink-dim); font-size: 14px; }
.qr {
  width: 260px; height: 260px; margin: 18px auto;
  border: 1px solid var(--edge); padding: 10px; background: rgba(0,0,0,.5);
}
.qr img { width: 100%; height: 100%; image-rendering: pixelated; }

/* -- responsive ----------------------------------------------------------- */

@media (max-width: 820px) {
  :root { --rail: 100%; }
  #shell { grid-template-columns: 1fr; }
  .rail {
    position: sticky; top: 0; z-index: 20; height: auto;
    flex-direction: row; overflow-x: auto; padding: 6px 8px;
    border-right: 0; border-bottom: 1px solid var(--edge-soft);
  }
  .rail-item { flex: 0 0 auto; width: 62px; height: 52px; }
  .view { padding: 16px; }
  .topbar { padding: 10px 16px; gap: 12px; }
  .purse { width: 100%; margin-left: 0; }
}

@media (max-width: 560px) {
  .panel > header { flex-wrap: wrap; }
  .panel > header h2 { min-width: 0; }
  .panel > header .aside { order: 3; width: 100%; }
  .spread { align-items: flex-start; flex-wrap: wrap; }
  .forge-queue-head { grid-template-columns: minmax(0, 1fr); }
  .market-row { flex-wrap: wrap; }
  .market-row > .btn { margin-left: 54px; }
  .market-facts { padding-left: 54px; }
  .requirement { grid-template-columns: 38px minmax(0, 1fr); }
  .requirement .amount {
    grid-column: 2; white-space: normal; overflow-wrap: anywhere;
  }
  .modal-card > footer { flex-wrap: wrap; }
}
