:root {
  --bg: #14110d;
  --bg-2: #1c1813;
  --surface: #221d17;
  --surface-2: #2b251d;
  --line: #3a3228;
  --text: #ece4d6;
  --muted: #a89c88;
  --gold: #d9a441;
  --gold-2: #f0c46a;
  --on-gold: #1b1509;
  --ok: #7fbf7a;
  --danger: #e0715f;
  --focus: #f0c46a;
  --radius: 10px;
  --serif: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f1e7;
    --bg-2: #efe7d8;
    --surface: #fffdf8;
    --surface-2: #f4ecdd;
    --line: #dccfb7;
    --text: #2a2218;
    --muted: #6f6450;
    --gold: #9a6b12;
    --gold-2: #7d560b;
    --on-gold: #fffaf0;
    --ok: #2f7a31;
    --danger: #b3402f;
    --focus: #9a6b12;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 500px at 50% -200px, var(--bg-2), var(--bg));
  background-color: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 16px 48px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: .2px; margin: 0; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.15rem; }
code, .mono { font-family: var(--mono); font-size: .88em; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

header.site {
  max-width: 1180px; width: 100%; margin: 0 auto; padding: 20px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 1.5rem; color: var(--gold-2); }
.brand p { margin: 0; color: var(--muted); font-size: .9rem; }
.privacy-pill {
  margin: 0; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px;
  color: var(--muted); font-size: .85rem; background: var(--surface);
}
footer.site { text-align: center; color: var(--muted); font-size: .85rem; padding: 24px 16px; border-top: 1px solid var(--line); }

/* Landing */
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center;
  padding: 56px 16px; border: 2px dashed var(--line); border-radius: 16px; background: var(--surface);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--gold); background: var(--surface-2); }
.drop-icon { color: var(--gold); }
.drop strong { font-family: var(--serif); font-size: 1.25rem; }
.drop span { color: var(--muted); }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-top: 20px; }
.path { display: grid; grid-template-columns: 90px 1fr auto; align-items: center; gap: 8px; margin-top: 10px; }
.path span { color: var(--muted); font-size: .9rem; }
.path code { background: var(--bg); padding: 6px 8px; border-radius: 6px; overflow-wrap: anywhere; }
.steps { margin: 8px 0 0; padding-left: 20px; }
.steps li { margin: 4px 0; }

/* Cards and forms */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card > h2 + .sub, .card > .sub { color: var(--muted); margin: 4px 0 16px; }
.stack { display: grid; gap: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px 20px; }
.field { display: grid; gap: 6px; align-content: start; }
.field .label { font-weight: 600; font-size: .92rem; }
.hint { color: var(--muted); font-size: .82rem; }
.muted { color: var(--muted); }
.note { background: var(--surface-2); border-left: 3px solid var(--gold); padding: 10px 12px; border-radius: 6px; margin: 0 0 16px; }
.error { color: var(--danger); }
.wrap { overflow-wrap: anywhere; }
input[type=text], input[type=number], input[type=search], input[type=password], select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; width: 100%;
}
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--gold); }
input.small { width: 110px; }
input:disabled { opacity: .45; }
button {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer;
  white-space: nowrap;
}
button:hover { border-color: var(--gold); }
button.primary { background: var(--gold); color: var(--on-gold); border-color: var(--gold); font-weight: 600; }
button.primary:hover { background: var(--gold-2); }
button.danger:hover { border-color: var(--danger); color: var(--danger); }
.actions { display: flex; gap: 10px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.inline { display: inline-flex; align-items: center; gap: 6px; }
.inline-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.inline-form select { width: auto; max-width: 260px; }
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 360px; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }

/* Editor chrome */
.filebar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 12px;
}
.file-info { display: grid; min-width: 0; }
.file-info strong { overflow-wrap: anywhere; }
.file-info span { color: var(--muted); font-size: .85rem; }
.dirty { color: var(--muted); font-size: .9rem; margin-left: auto; }
.dirty.has { color: var(--gold-2); }
.filebar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tab { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 10px 14px; color: var(--muted); }
.tab[aria-selected=true] { color: var(--text); border-bottom-color: var(--gold); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button[aria-pressed=true] { border-color: var(--gold); color: var(--gold-2); }

/* Master-detail */
.split { display: grid; grid-template-columns: minmax(220px, 320px) 1fr; gap: 16px; align-items: start; }
.inv-list { display: grid; gap: 6px; max-height: 70vh; overflow-y: auto; padding-right: 4px; }
.inv-list > p { margin: 0 0 4px; font-size: .85rem; }
.inv-item { display: grid; text-align: left; gap: 2px; white-space: normal; }
.inv-item span { color: var(--muted); font-size: .82rem; }
.inv-item.active { border-color: var(--gold); background: var(--bg); }
.inv-detail { min-width: 0; }
.empty { border: 1px dashed var(--line); border-radius: var(--radius); padding: 32px; text-align: center; color: var(--muted); }
.table-wrap { overflow-x: auto; margin-top: 10px; }
table.slots { border-collapse: collapse; width: 100%; font-size: .9rem; }
table.slots th, table.slots td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.slots th { color: var(--muted); font-weight: 600; font-size: .82rem; }
td.id { max-width: 240px; overflow-wrap: anywhere; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions button { padding: 4px 10px; font-size: .85rem; }

/* Difficulty */
.diff-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.diff-group { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px 12px; margin: 0; }
.diff-group legend { font-family: var(--serif); font-weight: 600; padding: 0 6px; color: var(--gold-2); }
.diff-row { display: grid; grid-template-columns: auto 1fr 96px; align-items: center; gap: 10px; padding: 4px 0; }
.diff-row input[type=number] { padding: 4px 8px; }
.diff-row input[type=checkbox]:last-child { justify-self: start; }
.diff-name { color: var(--muted); }
.diff-row.on .diff-name { color: var(--text); }

/* Advanced */
ul.props { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
ul.props ul.props { padding-left: 16px; border-left: 1px solid var(--line); }
ul.props li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.prop-name { font-family: var(--mono); font-size: .85rem; overflow-wrap: anywhere; }
.prop-type { font-size: .75rem; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }
.prop-value { margin-top: 6px; }
summary { cursor: pointer; }
textarea.code { font-family: var(--mono); font-size: .82rem; line-height: 1.45; resize: vertical; white-space: pre; }

/* Toasts */
#toasts { position: fixed; bottom: 16px; right: 16px; left: 16px; display: grid; justify-items: end; gap: 8px; z-index: 20; pointer-events: none; }
.toast {
  background: var(--surface-2); border: 1px solid var(--line); border-left: 4px solid var(--gold);
  padding: 10px 14px; border-radius: 8px; max-width: 420px; box-shadow: 0 6px 24px rgba(0,0,0,.25);
  transition: opacity .5s, transform .5s; pointer-events: auto;
}
.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--danger); }
.toast.out { opacity: 0; transform: translateY(8px); }

@media (max-width: 760px) {
  .split { grid-template-columns: 1fr; }
  .inv-list { max-height: 260px; }
  .path { grid-template-columns: 1fr auto; }
  .path span { grid-column: 1 / -1; }
  .dirty { margin-left: 0; width: 100%; }
  .filebar-actions { width: 100%; }
  .filebar-actions button { flex: 1; }
}

/* Let wide tables scroll inside their card instead of widening the page */
.stack > *, .card, .inv-editor, .split > * { min-width: 0; }
td.id { min-width: 140px; }
@media (max-width: 760px) {
  input.small { width: 84px; }
  .card { padding: 16px; }
}

/* Item names */
td.item { min-width: 180px; }
.item-name { font-weight: 600; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.item-sub { color: var(--muted); font-size: .8rem; overflow-wrap: anywhere; }
.tag { font-size: .7rem; font-weight: 500; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; }
.add-item { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.add-item h4 { margin: 0 0 10px; font-family: var(--serif); font-size: 1.05rem; }
.item-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; max-height: 280px; overflow-y: auto; }
.item-results > p { grid-column: 1 / -1; margin: 4px 0; }
.item-result { display: grid; text-align: left; gap: 2px; white-space: normal; }
.item-result span { color: var(--muted); font-size: .8rem; }
.item-result.active { border-color: var(--gold); background: var(--bg); }
.picked { margin-top: 10px; min-height: 1.5em; }
[hidden] { display: none !important; }

/* Support link: header, quiet but visible */
.header-links { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.coffee {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--gold); color: var(--gold-2); background: var(--surface); font-size: .85rem; text-decoration: none;
}
.coffee:hover { background: var(--gold); color: var(--on-gold); }

/* Character backpack, laid out like the game */
.bag-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.bag-layout > * { min-width: 0; }
.slot-panel { position: sticky; top: 96px; }
.slot-panel h3 { margin-bottom: 2px; }
.bag-label { margin: 0 0 6px; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; }
.slot-grid { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; }
.slot-grid.hotbar { padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.slot {
  position: relative; aspect-ratio: 1; min-width: 0; padding: 4px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--line); white-space: normal;
  display: flex; align-items: center; justify-content: center; text-align: center;
}
.slot.filled { background: var(--surface-2); }
.slot.selected { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.slot.equipped { border-color: var(--ok); }
.slot.drop { border-style: dashed; border-color: var(--gold); }
.slot-num { position: absolute; top: 2px; left: 5px; font-size: .72rem; color: var(--muted); }
.slot-name {
  font-size: .72rem; line-height: 1.15; overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow-wrap: anywhere;
}
.slot-count { position: absolute; bottom: 2px; right: 5px; font-size: .72rem; font-weight: 700; color: var(--gold-2); }
.slot-dur { position: absolute; bottom: 2px; left: 5px; font-size: .65rem; color: var(--muted); }
.slot-eq { position: absolute; top: 2px; right: 5px; font-size: .65rem; font-weight: 700; color: var(--ok); }
.bag-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.bag-tabs button[aria-selected=true] { border-color: var(--gold); color: var(--gold-2); }
.equip-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.equip-slot { display: grid; gap: 4px; }

@media (max-width: 900px) {
  .bag-layout { grid-template-columns: 1fr; }
  .slot-panel { position: static; }
}
@media (max-width: 600px) {
  .slot-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .slot { padding: 14px 4px; }
  .slot-name { font-size: .72rem; -webkit-line-clamp: 3; }
  .equip-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.equip-row .slot { max-width: 120px; }
@media (max-width: 760px) {
  .filebar { position: static; }
}

.slot.stray { border-color: var(--danger); border-style: dashed; }
.stray-box { margin-top: 16px; }
.stray-box .slot-grid { margin-top: 8px; }
.move-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; margin-top: 14px; }

/* Server settings */
.inline-form.tight { margin-top: 0; flex-wrap: nowrap; }
input[readonly] { opacity: .75; }
h4.sub-head { margin: 20px 0 4px; font-family: var(--serif); font-size: 1.05rem; }
.add-player { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) auto; gap: 8px; }
@media (max-width: 600px) { .add-player { grid-template-columns: 1fr; } }
@media (min-width: 960px) {
  .info-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .info-grid .card:first-child { grid-column: span 2; }
  .info-grid .card:first-child ~ .card:last-child { grid-column: 1 / -1; }
}
.hint-block { display: grid; }
.hint.ram { color: var(--text); font-weight: 600; }

/* Difficulty (game data) */
.diff-name small { display: block; color: var(--muted); font-size: .75rem; line-height: 1.3; }
.diff-row { grid-template-columns: auto 1fr 90px; align-items: start; }
.diff-row > input[type=checkbox]:first-child { margin-top: 3px; }
.diff-group.wide { margin-top: 16px; }
.preset-bar { margin: 0 0 16px; }
.ai-table { border-collapse: collapse; width: 100%; }
.ai-table th, .ai-table td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.ai-table thead th { color: var(--muted); font-size: .82rem; }
.ai-table input[type=number] { width: 80px; padding: 4px 8px; }
.ai-cell:not(.on) input[type=number] { opacity: .45; }
.privs { display: flex; flex-wrap: wrap; gap: 4px 12px; }
