/* Colours follow the game's art guide: river greens, lamp cream, clay red. */
:root {
  --ink: #0e1512;
  --panel: #16211c;
  --panel-2: #1d2b24;
  --line: #2e4238;
  --cream: #f4e6bc;
  --leaf: #8cbf6a;
  --clay: #d94f3a;
  --sky: #6fb3c9;
  --muted: #9fb3a4;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ink);
  color: var(--cream);
  font: 13px/1.5 "SF Mono", "JetBrains Mono", ui-monospace, monospace;
}

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 46px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { color: var(--leaf); letter-spacing: 0.12em; font-size: 12px; }
.map-title { color: var(--cream); font-weight: 700; }
.dirty { color: var(--clay); font-size: 12px; }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: 12px; }

button {
  font: inherit;
  color: var(--cream);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}
button:hover { border-color: var(--leaf); }
button.primary { background: var(--leaf); color: #10201a; border-color: var(--leaf); font-weight: 700; }
button.primary:hover { filter: brightness(1.1); }
button.wide { width: 100%; }
button.danger { border-color: var(--clay); color: var(--clay); }

.shell {
  display: grid;
  grid-template-columns: 236px 1fr 288px;
  height: calc(100% - 46px);
}

.panel {
  background: var(--panel);
  overflow-y: auto;
  padding: 12px;
}
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); }
.panel section { margin-bottom: 20px; }

h2 {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 8px;
}
h3 { font-size: 12px; margin: 16px 0 8px; color: var(--leaf); }

.map-list { list-style: none; margin: 0 0 8px; padding: 0; }
.map-list li {
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}
.map-list li:hover { background: var(--panel-2); }
.map-list li.active { background: var(--panel-2); border-color: var(--leaf); }
.map-list small { display: block; color: var(--muted); font-size: 11px; }

.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.tools button { text-align: left; padding: 6px 8px; }
.tools button.active { background: var(--leaf); color: #10201a; border-color: var(--leaf); }

.row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.row span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.row input[type="range"] { flex: 1; }
.check { display: block; color: var(--muted); font-size: 12px; margin: 5px 0; cursor: pointer; }

.field { margin-bottom: 10px; }
.field label { display: block; color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.field input, .field select, .field textarea {
  width: 100%;
  font: inherit;
  color: var(--cream);
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 5px 7px;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 1px solid var(--leaf); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.stage { position: relative; background: #0a100d; overflow: hidden; }
canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }

.status {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 4px 9px;
  background: rgba(14, 21, 18, 0.85);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}

.issues { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.issues li { padding: 4px 0; border-bottom: 1px dashed var(--line); color: var(--clay); }
.issues li.ok { color: var(--muted); border: 0; }

.materials { display: grid; gap: 5px; margin-bottom: 8px; }
.materials button { display: grid; grid-template-columns: 18px 1fr auto; align-items: center; gap: 8px; text-align: left; }
.materials button.active { border-color: var(--leaf); background: var(--panel-2); }
.materials i { width: 18px; height: 18px; border-radius: 4px; border: 1px solid var(--line); }
.materials small { color: var(--muted); font-size: 10px; }

.gallery { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.gallery button { padding: 4px; display: grid; gap: 3px; justify-items: center; }
.gallery img { width: 100%; height: 42px; object-fit: contain; image-rendering: pixelated; }
.gallery span { font-size: 9px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 10, 8, 0.82);
  display: grid;
  place-items: center;
  z-index: 40;
}
/* `hidden` alone loses to the rule above, so spell the closed state out. */
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  min-width: 340px;
  max-width: min(94vw, 1100px);
  max-height: 92vh;
  overflow: auto;
}
.modal-card h2 { color: var(--leaf); font-size: 13px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.pick-canvas { display: block; max-width: 100%; border: 1px solid var(--line); cursor: crosshair; image-rendering: pixelated; }
.note { color: var(--muted); font-size: 11px; margin: 6px 0 0; }

/* Sub-headings inside a form section (the interaction panel). */
.panel h4 { margin: 12px 0 6px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* The four stacking-order buttons on a prop or overlay. */
.order-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.order-buttons button { width: 100%; }

/* The right panel's folds: one per heading, click to open or close. */
.fold-bar { display: flex; gap: 6px; justify-content: flex-end; margin-bottom: 8px; }
.fold-bar button { font-size: 11px; padding: 3px 8px; }
details.fold { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 8px; background: rgba(0, 0, 0, 0.12); }
details.fold > summary {
  cursor: pointer; list-style: none; padding: 7px 10px; font-size: 12px; color: var(--leaf);
  display: flex; align-items: center; gap: 6px; user-select: none;
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::before { content: "▸"; color: var(--muted); font-size: 10px; transition: transform 0.12s; }
details.fold[open] > summary::before { transform: rotate(90deg); }
details.fold.major > summary { letter-spacing: 0.08em; text-transform: uppercase; font-size: 11px; color: var(--muted); }
details.fold.major[open] > summary { color: var(--text, #f4e6bc); }
details.fold > .fold-body { padding: 4px 10px 10px; }
details.fold > .fold-body > :first-child { margin-top: 0; }

/* ---------------------------------------------------------- game data page */
.link-button { display: inline-flex; align-items: center; text-decoration: none; color: var(--cream); }
.tabs { display: flex; gap: 4px; margin-left: 16px; }
.tabs button { font-size: 12px; }
.tabs button.active { background: var(--panel-2); border-color: var(--leaf); color: var(--cream); }
.data-shell { grid-template-columns: 260px 1fr 300px; }
.data-form { padding: 16px 20px; }
.data-form h2 { margin-top: 0; }
.data-form .field input, .data-form .field select, .data-form .field textarea { width: 100%; }
.data-list li { display: flex; flex-direction: column; gap: 2px; }
.data-list li .bad { color: var(--clay); font-size: 11px; }
#search { width: 100%; margin-bottom: 8px; }
table.rows { width: 100%; border-collapse: collapse; margin: 6px 0 8px; font-size: 12px; }
table.rows th { text-align: left; color: var(--muted); font-weight: normal; font-size: 11px; padding: 2px 4px; }
table.rows td { padding: 2px 4px; vertical-align: middle; }
table.rows input, table.rows select { width: 100%; }
table.rows td.narrow { width: 64px; }
table.rows td.tiny { width: 32px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.checklist { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
.checklist label { font-size: 12px; }
.readonly { opacity: 0.8; }

/* Item icons in the game-data forms. */
img.thumb { image-rendering: pixelated; border: 1px solid var(--line); border-radius: 4px; background: var(--panel-2); vertical-align: middle; width: 32px; height: 32px; object-fit: contain; }
img.thumb[data-blank="1"] { opacity: 0.25; }
.with-thumb { display: flex; align-items: center; gap: 8px; }
.with-thumb select { flex: 1; }

/* Live co-editing: the strip of who else is on this map. */
.peers { position: fixed; top: 52px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; z-index: 50; pointer-events: none; }
.peer-chip { display: inline-flex; align-items: center; gap: 5px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 2px 10px; font-size: 12px; color: var(--cream); box-shadow: 0 1px 4px rgba(0,0,0,0.3); }
.peer-chip i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* ---- Item catalog: a grid of icon cards with a filter bar (data.js item tab) ---- */
.data-shell.items-mode { grid-template-columns: 460px 1fr 300px; }
.item-filters { margin: 4px 0 12px; }
.item-filters .pair { margin-bottom: 6px; }
.map-list.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; align-content: start; }
.item-grid .item-card {
  display: flex; flex-direction: column; gap: 6px;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px;
  background: var(--panel); cursor: pointer;
}
.item-grid .item-card:hover { background: var(--panel-2); }
.item-grid .item-card.active { border-color: var(--leaf); background: var(--panel-2); }
.item-grid .item-card .card-top { display: flex; gap: 8px; align-items: center; }
.item-grid .item-card img.thumb { width: 44px; height: 44px; flex: none; }
.item-grid .item-card .card-name { display: flex; flex-direction: column; min-width: 0; }
.item-grid .item-card .card-name strong { font-size: 12px; color: var(--cream); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-grid .item-card .card-name small { color: var(--muted); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-grid .card-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.item-grid .card-badges .chip { font-size: 10px; padding: 1px 7px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.item-grid .card-badges .chip.rarity-fine { color: #6db8e6; border-color: #315a72; }
.item-grid .card-badges .chip.rarity-rare { color: #d8a24a; border-color: #6b5220; }
.item-grid .item-card .card-classes { color: var(--muted); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-grid .item-card .bad { color: var(--clay); font-size: 10px; }

/* ---- Item form: colour pickers and section sub-headings ---- */
.colour-row { display: flex; gap: 6px; align-items: center; }
.colour-row input[type="color"] { width: 34px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: var(--panel-2); cursor: pointer; }
.colour-row input.hex { flex: 1; font-family: ui-monospace, monospace; }
.colour-row button { padding: 2px 8px; }
.data-form h4 { margin: 12px 0 6px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* ---- Skill catalog: class sections, category colours, and the skill form's hero ---- */
.item-grid li.grid-section { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 8px; padding: 10px 2px 2px; border: 0; background: none; cursor: default; border-bottom: 1px solid var(--line); border-radius: 0; }
.item-grid li.grid-section:hover { background: none; }
.item-grid li.grid-section span { color: var(--leaf); font-weight: 700; font-size: 13px; }
.item-grid li.grid-section small { color: var(--muted); font-size: 11px; }
.item-grid .card-badges .chip.cat-basic { color: #c9c4b4; border-color: #5a5a5a; }
.item-grid .card-badges .chip.cat-core { color: #e39a8a; border-color: #8a3f3f; }
.item-grid .card-badges .chip.cat-cooperative { color: #8ec2e0; border-color: #3f6a8a; }
.item-grid .card-badges .chip.cat-survival { color: #9ed89e; border-color: #4a7a4a; }
.skill-hero { display: flex; gap: 14px; align-items: center; margin-bottom: 8px; }
.skill-hero img.thumb.hero { width: 64px; height: 64px; }
.skill-hero h2 { margin: 0 0 2px; }
.skill-hero .note { margin: 0 0 4px; }
.skill-summary { margin: 0; font-size: 12px; color: var(--cream); background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }

/* ---- Catalog layout on narrow windows: the check panel moves under the form so the form keeps its width ---- */
@media (max-width: 1100px) {
  .data-shell.items-mode { grid-template-columns: minmax(250px, 38%) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .data-shell.items-mode .panel.left { grid-row: 1 / span 2; }
  .data-shell.items-mode .panel.right { grid-column: 2; border-left: 0; border-top: 1px solid var(--line); max-height: 30vh; overflow: auto; }
  .data-shell.items-mode .map-list.item-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}

/* ---- Class catalog: portraits, radar charts, and the class form ---- */
.portrait { image-rendering: pixelated; background-repeat: no-repeat; flex: none; }
.portrait.blank { display: flex; align-items: center; justify-content: center; font-size: 10px; color: var(--muted); border: 1px dashed var(--line); border-radius: 6px; }
.map-list.item-grid.class-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.item-grid .class-card .class-card-top { display: flex; gap: 8px; align-items: flex-end; }
.item-grid .class-card .class-role { color: var(--cream); font-size: 10px; white-space: normal; }
.item-grid .class-card .class-swatch { display: inline-block; width: 22px; height: 4px; border-radius: 2px; margin-top: 4px; }
.item-grid .class-card svg.radar { align-self: center; }
svg.radar .radar-ring { fill: none; stroke: var(--line); stroke-width: 1; }
svg.radar .radar-rim { fill: none; stroke: #3f5a4c; stroke-width: 1; }
svg.radar .radar-spoke { stroke: var(--line); stroke-width: 1; }
svg.radar .radar-label { fill: var(--muted); font-size: 11px; }
svg.radar .radar-shape { stroke-width: 2; stroke-linejoin: round; fill-opacity: 0.22; }
svg.radar .radar-dot { stroke: var(--panel); stroke-width: 2; }
svg.radar .radar-hit { stroke: transparent; stroke-width: 26; stroke-linecap: round; pointer-events: stroke; cursor: help; }
.radar-tip { position: fixed; z-index: 50; max-width: 320px; pointer-events: none; background: var(--ink); color: var(--cream); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,0.4); }
.radar-tip[hidden] { display: none; }
.radar-wrap { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.radar-side { flex: 1; min-width: 240px; }
.radar-legend { display: flex; gap: 14px; margin-bottom: 6px; font-size: 12px; color: var(--cream); }
.radar-legend span { display: inline-flex; align-items: center; gap: 6px; }
.radar-legend i { display: inline-block; width: 16px; height: 10px; border-radius: 2px; }
.radar-legend i.dashed { background: none; border-top: 2px dashed var(--muted); height: 0; }
table.radar-table td { font-variant-numeric: tabular-nums; color: var(--cream); }
table.radar-table td.top { color: var(--leaf); font-weight: 700; }
table.radar-table td.hint, table.stat-table td.hint { color: var(--muted); font-size: 11px; }
table.stat-table th { text-align: left; }
.class-hero { display: flex; gap: 16px; align-items: flex-end; margin-bottom: 6px; }
.class-hero-art { border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 8px; background: radial-gradient(circle at 50% 70%, #24362c, var(--panel) 70%); padding: 6px 10px 0; }
.class-hero h2 { margin: 0 0 4px; }
.class-hero .note, .class-hero .bad { margin: 0 0 3px; }
.level-slider { width: 100%; accent-color: var(--leaf); }
.level-quick { display: flex; gap: 4px; margin-top: 4px; }
.level-quick button { padding: 1px 8px; font-size: 11px; }
.look-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.look-tile { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); cursor: pointer; color: var(--muted); }
.look-tile.on { border-color: var(--leaf); background: var(--panel-2); color: var(--cream); }
.look-tile small { font-size: 9px; }
.skill-checklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 12px; }
.skill-checklist .check { display: flex; align-items: center; gap: 6px; }
/* The hero name is the page's title, not a small panel heading. */
.class-hero h2, .skill-hero h2 { font-size: 20px; color: var(--cream); text-transform: none; letter-spacing: 0; }
.radar-side table.radar-table td.hint { white-space: nowrap; }

/* ---- Accounts: the sign-in page, the header chip, read-only pages, and user management ---- */
body.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; background: radial-gradient(circle at 50% 30%, #1d2f25, var(--ink) 70%); }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px 24px 18px; box-shadow: 0 12px 40px rgba(0,0,0,0.45); }
.login-card .brand { margin: 0 0 6px; font-size: 11px; letter-spacing: 0.12em; color: var(--leaf); font-weight: 700; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card .field input { width: 100%; font-size: 15px; padding: 8px 10px; }
.login-card form button { margin-top: 6px; padding: 9px; font-size: 14px; }
.login-setup pre { white-space: pre-wrap; background: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; color: var(--cream); font-size: 12px; }
.login-message { margin: 12px 0 0; font-size: 13px; }
.login-message.bad { color: var(--clay); }
.login-message.ok { color: var(--leaf); }

.user-box { position: relative; margin-left: 6px; }
.user-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; }
.user-chip .user-name { color: var(--cream); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 10px; padding: 1px 7px; border-radius: 10px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.user-role.role-admin { color: #f0c878; border-color: #6b5220; }
.user-role.role-mapper { color: var(--leaf); border-color: #3f6a3a; }
.user-role.role-data { color: var(--sky); border-color: #2f5a6a; }
.user-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 180px; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px; box-shadow: 0 8px 24px rgba(0,0,0,0.45); }
.user-menu[hidden] { display: none; }
.user-menu a, .user-menu button { text-align: left; padding: 7px 10px; border: 0; border-radius: 6px; background: none; color: var(--cream); text-decoration: none; font-size: 13px; }
.user-menu a:hover, .user-menu button:hover { background: var(--panel-2); }

.read-only-banner { background: #2d2a17; color: #f0c878; border-bottom: 1px solid #6b5220; padding: 6px 14px; font-size: 12px; }
body.read-only #save, body.read-only #new, body.read-only #delete, body.read-only #new-map { opacity: 0.4; cursor: not-allowed; }

.users-shell { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; padding: 16px; align-items: start; }
.users-main, .panel-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.users-side { display: flex; flex-direction: column; gap: 16px; }
.users-main h2, .panel-card h2 { margin-top: 0; }
table.users-table td { padding: 6px 4px; }
table.users-table input { width: 100%; }
table.users-table tr.is-disabled td { opacity: 0.55; }
.users-table .ok-toggle { color: var(--leaf); border-color: #3f6a3a; }
.user-actions { white-space: nowrap; }
.user-actions button { margin-left: 4px; }
table.role-table td, table.role-table th { font-size: 12px; }
.one-time-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
code.one-time { flex: 1; font-size: 18px; letter-spacing: 0.08em; background: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; color: var(--cream); user-select: all; }
@media (max-width: 900px) { .users-shell { grid-template-columns: 1fr; } }
table.users-table input, table.users-table select { background: var(--ink); color: var(--cream); border: 1px solid var(--line); border-radius: 4px; padding: 4px 6px; font: inherit; }
table.users-table input:focus, table.users-table select:focus { outline: 1px solid var(--leaf); }
