/* Dark by default, in the game's own black-and-signal-yellow; a light scheme follows the system.
   The three stat types carry one colour each everywhere a stat is drawn. */
:root {
  color-scheme: dark;
  --ground: #0e0f11;
  --panel: #16181b;
  --raised: #1f2226;
  --line: #2d3136;
  --text: #e8e9eb;
  --muted: #8f959c;
  --accent: #f5d33c;
  --accent-ink: #1b1600;
  --danger: #ff7a7a;
  --ok: #6fdc8c;
  --warn: #ffab5c;
  --attribute: #7cbcff;
  --secondary: #ffc267;
  --skill: #cfa2ff;
  --radius: 6px;
  --font-ui: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: Bahnschrift, "DIN Alternate", "Roboto Condensed", "Arial Narrow", var(--font-ui);
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --ground: #f3f3f1;
    --panel: #ffffff;
    --raised: #f0f0ed;
    --line: #d8d8d3;
    --text: #1b1c1e;
    --muted: #62666b;
    --accent: #c9a400;
    --accent-ink: #ffffff;
    --danger: #c2332f;
    --ok: #1c8a3c;
    --warn: #b35a00;
    --attribute: #1f6fc4;
    --secondary: #a86400;
    --skill: #7c3fc4;
  }
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font: 14px/1.45 var(--font-ui);
}

[hidden] { display: none !important; }

button, input, select { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

h2, h3 { margin: 0; }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
  font-family: var(--font-display);
  font-size: 17px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.brand-mark { color: var(--accent); display: inline-flex; }

.topbar-group { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.field-inline { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.field-inline select { text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--text); max-width: 220px; }

select, input[type="text"], input[type="search"] {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 8px;
  min-width: 0;
}

.btn {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.icon { padding: 6px 10px; line-height: 1; }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.is-none[aria-pressed="true"] { background: var(--raised); color: var(--text); border-color: var(--muted); font-weight: 600; }

.storage-warning {
  padding: 8px 16px;
  background: #3a2a10;
  color: #ffd79a;
  border-bottom: 1px solid #5a4118;
}

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  overflow-x: auto;
}

.tab {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--muted);
  font-family: var(--font-display);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- workspace ---------- */

.work { padding: 16px; max-width: 1400px; margin: 0 auto; }

.work h2 {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.work h2.spaced { margin-top: 12px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }
.push { margin-left: auto; }
.empty { color: var(--muted); margin: 8px 0; padding: 16px; border: 1px dashed var(--line); border-radius: var(--radius); }
.summary { margin: 0 0 4px; font-size: 15px; }
.help { margin-top: 20px; max-width: 70ch; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.search { width: 260px; max-width: 100%; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  --c: var(--muted);
  display: inline-flex;
  align-items: center;
  padding: 1px 9px;
  border: 1px solid color-mix(in srgb, var(--c) 55%, transparent);
  background: color-mix(in srgb, var(--c) 14%, transparent);
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}

.chip.type-attribute { --c: var(--attribute); }
.chip.type-secondary { --c: var(--secondary); }
.chip.type-skill { --c: var(--skill); }
.chip.weapon { --c: var(--ok); }
.chip.unset { border-style: dashed; color: var(--muted); }
.chip.is-engrave { font-weight: 600; background: color-mix(in srgb, var(--c) 26%, transparent); }

.segmented { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; flex: none; }
.check.big input { width: 18px; height: 18px; }

/* ---------- farm plan ---------- */

.plan-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  margin-top: 14px;
}

.col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.prio-head, .status-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.prio h3, .status h3 { font-size: 15px; }

.rank {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-display);
  font-weight: 700;
}

.badge { color: var(--muted); font-size: 13px; }

.engrave { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 6px; border-top: 1px solid var(--line); }
.engrave .label { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

.status { border-left: 3px solid var(--line); }
.status.is-ready { border-left-color: var(--ok); }
.status.is-blocked { border-left-color: var(--warn); }
.pill { font-size: 12px; font-weight: 600; }
.is-ready .pill { color: var(--ok); }
.is-blocked .pill { color: var(--warn); }

.done-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.done-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line); }

/* ---------- my weapons ---------- */

.rows { display: flex; flex-direction: column; gap: 6px; }
.row { flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.row-text { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.row.state-none strong { color: var(--muted); font-weight: 500; }
.row.state-upgraded { opacity: 0.7; }

/* ---------- unlocked alluviums ---------- */

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.alluvium.is-on { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
.alluvium summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.alluvium details .chips { margin-top: 8px; }

/* ---------- catalog ---------- */

.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  justify-content: space-between;
  padding: 10px 14px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  background: var(--panel);
}

.notice p { margin: 0; max-width: 80ch; }

.catalog { display: flex; flex-direction: column; gap: 12px; }
.section > summary { display: flex; align-items: center; gap: 10px; cursor: pointer; list-style: none; }
.section > summary::-webkit-details-marker { display: none; }
.section > summary::before { content: "▸"; color: var(--muted); }
.section[open] > summary::before { content: "▾"; }

.add-form { display: flex; flex-wrap: wrap; gap: 8px; }
.add-form input[type="text"] { flex: 1 1 220px; }

.edit-list { display: flex; flex-direction: column; gap: 6px; }
.edit-row { display: flex; align-items: center; gap: 8px; }
.edit-row .name { flex: 1 1 auto; }
.weapon-row { display: grid; grid-template-columns: minmax(180px, 2fr) repeat(3, minmax(0, 1fr)) auto; }
.stat-row { display: grid; grid-template-columns: minmax(0, 1fr) 150px auto; }
.name-cell { display: flex; align-items: center; gap: 6px; min-width: 0; }
.name-cell .name { width: 100%; }
.dup { font-size: 11px; font-weight: 700; color: var(--warn); border: 1px solid var(--warn); border-radius: 4px; padding: 1px 5px; }

.edit-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.edit-card .edit-row .name { font-weight: 600; }
.pool { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.pool fieldset { margin: 0; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px 10px; display: flex; flex-direction: column; gap: 4px; }
.pool legend { font-size: 12px; padding: 0 4px; }
.pool fieldset:nth-child(1) legend { color: var(--attribute); }
.pool fieldset:nth-child(2) legend { color: var(--secondary); }
.pool fieldset:nth-child(3) legend { color: var(--skill); }

/* ---------- toast & dialog ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  margin: 0;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  background: var(--raised);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.toast.is-error { border-color: var(--danger); }

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  width: min(420px, calc(100% - 32px));
}

dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog p { margin: 0 0 14px; }
dialog .field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
dialog .field span { font-size: 12px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- narrow screens ---------- */

@media (max-width: 900px) {
  .plan-grid { grid-template-columns: minmax(0, 1fr); }
  .weapon-row { grid-template-columns: minmax(0, 1fr) auto; }
  .weapon-row .name-cell { grid-column: 1; grid-row: 1; }
  .weapon-row .btn.icon { grid-column: 2; grid-row: 1; }
  .weapon-row select { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
  .work { padding: 12px; }
  .row .segmented { width: 100%; }
  .segmented.four { width: 100%; }
  .search { width: 100%; }
  .stat-row { grid-template-columns: minmax(0, 1fr) auto; }
  .stat-row .name { grid-column: 1; grid-row: 1; }
  .stat-row .btn.icon { grid-column: 2; grid-row: 1; }
  .stat-row select { grid-column: 1 / -1; }
}
