:root {
  color-scheme: light;
  --parchment-canvas: #f2efe6;
  --parchment-worktop: #f8f6ef;
  --parchment-raised: #fffdf7;
  --ink-primary: #1f2926;
  --ink-secondary: #4f5c57;
  --ink-tertiary: #75807b;
  --ink-muted: #9aa29e;
  --line-soft: rgba(31, 41, 38, .08);
  --line-standard: rgba(31, 41, 38, .14);
  --line-emphasis: rgba(31, 41, 38, .26);
  --compass: #176b63;
  --compass-hover: #10564f;
  --compass-quiet: #dceae5;
  --treasure: #9a6a12;
  --treasure-quiet: #f2e7c9;
  --danger: #a24436;
  --danger-quiet: #f3dfda;
  --control-inset: #efede5;
  --control-hover: #e9e6dc;
  --focus-ring: rgba(23, 107, 99, .28);
  --selection: rgba(23, 107, 99, .18);
  --radius-small: 6px;
  --radius-medium: 10px;
  --radius-large: 14px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --parchment-canvas: #111714;
  --parchment-worktop: #161e1a;
  --parchment-raised: #1b2520;
  --ink-primary: #edf2ee;
  --ink-secondary: #b6c1ba;
  --ink-tertiary: #89968e;
  --ink-muted: #69756e;
  --line-soft: rgba(233, 242, 236, .07);
  --line-standard: rgba(233, 242, 236, .13);
  --line-emphasis: rgba(233, 242, 236, .24);
  --compass: #65c5b5;
  --compass-hover: #82d4c6;
  --compass-quiet: #193b34;
  --treasure: #e0b65e;
  --treasure-quiet: #3b321e;
  --danger: #e08a79;
  --danger-quiet: #40251f;
  --control-inset: #101713;
  --control-hover: #202b25;
  --focus-ring: rgba(101, 197, 181, .3);
  --selection: rgba(101, 197, 181, .2);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--parchment-canvas);
  color: var(--ink-primary);
  font-size: 15px;
  line-height: 1.6;
  transition: background-color 160ms ease-out, color 160ms ease-out;
}

::selection { background: var(--selection); }

button,
input,
select { font: inherit; }

button,
select,
input { color: inherit; }

button,
select,
input[type="search"] {
  min-height: 40px;
  border: 1px solid var(--line-standard);
  border-radius: var(--radius-small);
  background: var(--control-inset);
}

button,
select {
  cursor: pointer;
}

button {
  padding: 8px 12px;
  font-weight: 650;
  letter-spacing: .01em;
  transition: border-color 120ms ease-out, background-color 120ms ease-out, color 120ms ease-out;
}

button:hover:not(:disabled),
select:hover:not(:disabled),
input[type="search"]:hover { border-color: var(--line-emphasis); }

button:hover:not(:disabled) { background: var(--control-hover); }

button:active:not(:disabled) { transform: translateY(1px); }

button:focus-visible,
select:focus-visible,
input:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  color: var(--ink-muted);
  opacity: .65;
}

a { color: var(--compass); text-underline-offset: 3px; }

h1,
h2,
p { margin-top: 0; }

h1,
h2 {
  line-height: 1.2;
  text-wrap: balance;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2.2rem, 5vw, 4.25rem);
  font-weight: 600;
  letter-spacing: -.055em;
}

h2 {
  margin-bottom: 0;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -.02em;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  width: 100%;
  min-height: 88px;
  margin: 0;
  padding: 10px max(24px, calc((100% - 1440px) / 2));
  align-items: center;
  gap: 20px;
  border-bottom: 1px solid var(--line-standard);
  background: var(--parchment-canvas);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-primary);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line-emphasis);
  border-radius: 50%;
  color: var(--compass);
  font-size: .82rem;
  font-weight: 700;
}

.brand strong,
.brand small { display: block; }

.brand strong {
  font-size: .98rem;
  line-height: 1.1;
}

.brand small {
  margin-top: 3px;
  color: var(--ink-tertiary);
  font-size: .61rem;
  font-weight: 700;
  letter-spacing: .13em;
}

.header-timer {
  display: grid;
  min-width: 0;
  flex: 1;
  grid-template-columns: minmax(160px, 1fr) auto minmax(140px, .7fr) auto;
  align-items: center;
  gap: 16px;
}

.header-timer-copy,
.header-countdown { min-width: 0; }
.header-timer-copy > span,
.header-countdown > span,
.header-timer small {
  display: block;
  color: var(--ink-tertiary);
  font-size: .65rem;
  font-weight: 750;
  letter-spacing: .08em;
}
.header-timer-copy strong {
  display: block;
  overflow: hidden;
  color: var(--ink-primary);
  font-size: .9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.header-timer-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: 0; }
.header-countdown { padding-left: 16px; border-left: 1px solid var(--line-standard); }
.header-countdown strong { display: block; color: var(--compass); font-size: 1.35rem; font-variant-numeric: tabular-nums; line-height: 1.05; }
.header-actions { display: flex; gap: 6px; }
.header-actions .primary-button { width: auto; }

.theme-switcher {
  display: inline-flex;
  margin: 0;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--line-standard);
  border-radius: 8px;
  background: var(--control-inset);
}

.theme-switcher legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.theme-switcher label { cursor: pointer; }
.theme-switcher input { position: absolute; opacity: 0; pointer-events: none; }
.theme-switcher span {
  display: grid;
  min-width: 42px;
  min-height: 30px;
  padding: 4px 8px;
  place-items: center;
  border-radius: 5px;
  color: var(--ink-tertiary);
  font-size: .76rem;
  font-weight: 700;
  transition: color 120ms ease-out, background-color 120ms ease-out;
}

.theme-switcher label:hover span { color: var(--ink-primary); }
.theme-switcher input:checked + span { background: var(--parchment-raised); color: var(--compass); }
.theme-switcher input:focus-visible + span { outline: 3px solid var(--focus-ring); }

.shell {
  width: min(1440px, calc(100% - 48px));
  margin: 0 auto;
  padding: 24px 0 56px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr);
  gap: 64px;
  align-items: end;
  padding-bottom: 48px;
}

.hero > p {
  max-width: 580px;
  margin-bottom: 5px;
  color: var(--ink-secondary);
  font-size: 1rem;
}

.eyebrow,
.step-label {
  margin-bottom: 6px;
  color: var(--compass);
  font-size: .69rem;
  font-weight: 800;
  letter-spacing: .13em;
}

.workspace {
  display: grid;
  min-width: 0;
  grid-template-columns: 312px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.control-rail {
  display: grid;
  min-width: 0;
  gap: 12px;
}

.timer-stage {
  display: grid;
  min-width: 0;
  gap: 12px;
}

.hero > *,
.workspace > *,
.control-rail > *,
.timer-stage > *,
.reference-grid > * { min-width: 0; }

.panel,
.next-card {
  border: 1px solid var(--line-standard);
  border-radius: var(--radius-medium);
  background: var(--parchment-worktop);
}

.control-panel { padding: 20px; }

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.section-heading.compact { align-items: start; }
.section-heading p { margin-bottom: 0; }
.area-badge {
  flex: 0 0 auto;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--compass-quiet);
  color: var(--compass);
  font-size: .68rem;
  font-weight: 800;
}

.supporting,
.status {
  color: var(--ink-secondary);
  font-size: .8rem;
  line-height: 1.55;
}

.supporting { margin: 12px 0 16px; }
.status { margin: 12px 0 0; }
.status.error { color: var(--danger); }

.file-picker {
  position: relative;
  display: grid;
  min-height: 88px;
  padding: 16px;
  place-content: center;
  border: 1px dashed var(--line-emphasis);
  border-radius: var(--radius-small);
  background: var(--control-inset);
  text-align: center;
  cursor: pointer;
  transition: border-color 120ms ease-out, background-color 120ms ease-out;
}

.file-picker:hover { border-color: var(--compass); background: var(--compass-quiet); }
.file-picker-title { color: var(--ink-primary); font-size: .85rem; font-weight: 700; }
.file-picker-note { color: var(--ink-tertiary); font-size: .7rem; }
.file-picker input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-picker:focus-within { outline: 3px solid var(--focus-ring); outline-offset: 2px; }

.field-label {
  display: grid;
  margin-top: 14px;
  gap: 6px;
  color: var(--ink-secondary);
  font-size: .74rem;
  font-weight: 700;
}

.field-label select { width: 100%; padding: 7px 32px 7px 10px; }
.field-label select { min-width: 0; max-width: 100%; }
.field-label input[type="range"] { width: 100%; accent-color: var(--compass); }

.selected-detail {
  display: block;
  min-height: 42px;
  margin: 8px 0 12px;
  color: var(--ink-secondary);
  font-size: .76rem;
  line-height: 1.45;
}

.primary-button {
  width: 100%;
  border-color: var(--compass);
  background: var(--compass);
  color: var(--parchment-raised);
}

:root[data-theme="dark"] .primary-button { color: #0d211d; }
.primary-button:hover:not(:disabled) { border-color: var(--compass-hover); background: var(--compass-hover); }

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.secondary-actions { margin-top: 10px; }
.secondary-actions button { flex: 1 1 auto; font-size: .76rem; }
.secondary-actions button { min-width: 0; }
.danger-button { width: 100%; margin-top: 14px; color: var(--danger); }
.danger-button:hover:not(:disabled) { border-color: var(--danger); background: var(--danger-quiet); }

.check-row {
  display: flex;
  min-height: 36px;
  align-items: center;
  gap: 8px;
  color: var(--ink-secondary);
  font-size: .78rem;
  cursor: pointer;
}

.check-row:first-of-type { margin-top: 10px; }
.check-row input { accent-color: var(--compass); }

.next-card {
  position: relative;
  display: grid;
  min-height: 190px;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 32px;
  overflow: hidden;
  padding: 28px 32px;
  background: var(--parchment-raised);
}

.next-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--compass);
}

.next-copy { min-width: 0; }
.next-copy h2 {
  overflow: hidden;
  margin: 4px 0 8px;
  font-size: clamp(1.35rem, 2.4vw, 2.2rem);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.next-copy > p:last-child {
  margin: 0;
  color: var(--ink-secondary);
  font-size: .82rem;
}

.countdown {
  min-width: 190px;
  padding-left: 28px;
  border-left: 1px solid var(--line-standard);
  text-align: right;
}

.countdown span {
  display: block;
  color: var(--ink-tertiary);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .12em;
}

.countdown strong,
.time {
  font-variant-numeric: tabular-nums;
}

.countdown strong {
  display: block;
  color: var(--compass);
  font-size: clamp(2.6rem, 6vw, 5rem);
  font-weight: 500;
  letter-spacing: -.07em;
  line-height: 1.05;
}

.respawn-progress {
  --progress: 0%;
  position: relative;
  width: min(100%, 280px);
  height: 12px;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line-emphasis);
  border-radius: 999px;
  background: var(--control-inset);
}

.respawn-progress span {
  position: absolute;
  inset: 2px auto 2px 2px;
  width: calc(var(--progress) - 4px);
  min-width: 0;
  border-radius: inherit;
  background: var(--compass);
  transition: width 500ms linear;
}

.respawn-progress i {
  position: absolute;
  z-index: 1;
  top: 2px;
  bottom: 2px;
  width: 1px;
  background: var(--parchment-raised);
  opacity: .72;
}

.respawn-progress i:nth-of-type(1) { left: 25%; }
.respawn-progress i:nth-of-type(2) { left: 50%; }
.respawn-progress i:nth-of-type(3) { left: 75%; }

.timer-panel { min-height: 520px; overflow: hidden; }
.timer-heading { padding: 24px 24px 16px; }
.timer-heading > p { color: var(--ink-tertiary); font-size: .75rem; }

.search-box {
  position: relative;
  display: block;
  padding: 0 24px 16px;
}

.search-box::before {
  content: "⌕";
  position: absolute;
  z-index: 1;
  top: 8px;
  left: 36px;
  color: var(--ink-tertiary);
  font-size: 1.1rem;
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 8px 12px 8px 36px;
}

.search-box input::placeholder { color: var(--ink-muted); }

.table-wrap {
  overflow-x: auto;
  border-top: 1px solid var(--line-soft);
}

.dragscroll { cursor: grab; }
.dragscroll:active { cursor: grabbing; }

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: top;
}

th:first-child,
td:first-child { padding-left: 24px; }
th:last-child,
td:last-child { padding-right: 24px; }

th {
  color: var(--ink-tertiary);
  font-size: .68rem;
  font-weight: 750;
  letter-spacing: .04em;
  white-space: nowrap;
}

td { color: var(--ink-secondary); font-size: .78rem; }
tbody tr { transition: background-color 100ms ease-out; }
tbody tr:hover { background: var(--line-soft); }

.candidate {
  display: flex;
  min-width: 250px;
  align-items: center;
  gap: 10px;
}

.candidate strong { color: var(--ink-primary); font-size: .8rem; }
.item-icons { display: inline-flex; flex: 0 0 auto; flex-wrap: wrap; gap: 2px; max-width: 76px; }
.icon-sprite {
  display: inline-block;
  width: 24px;
  height: 24px;
  border-radius: 3px;
  background-image: url("itemIcons.png");
  background-image: -webkit-image-set(url("itemIcons.webp"), url("itemIcons.png"));
  background-image: image-set(url("itemIcons.webp") type("image/webp"), url("itemIcons.png") type("image/png"));
  background-repeat: no-repeat;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .45);
  image-rendering: pixelated;
  vertical-align: top;
}

.muted,
.subtle { color: var(--ink-tertiary); font-size: .7rem; }
.ready { color: var(--compass); font-weight: 700; }
.waiting { color: var(--treasure); font-weight: 700; }
.time { color: var(--ink-primary); font-weight: 650; white-space: nowrap; }
.column-help {
  cursor: help;
  text-decoration: underline dotted var(--line-emphasis);
  text-underline-offset: 3px;
}
.column-help:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 3px; }
.spawn-count { min-width: 72px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.spawn-count strong { display: block; color: var(--ink-primary); font-size: .82rem; }
.spawn-count span { display: block; margin-top: 2px; color: var(--ink-tertiary); font-size: .68rem; }
.small-button { min-height: 30px; margin-top: 6px; padding: 4px 8px; color: var(--ink-secondary); font-size: .68rem; }

.reference-grid {
  display: grid;
  min-width: 0;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 12px;
  margin-top: 20px;
}

.notes { padding: 0 20px; color: var(--ink-secondary); }
.notes summary {
  padding: 16px 0;
  color: var(--ink-primary);
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
}

.notes[open] summary { border-bottom: 1px solid var(--line-soft); }
.notes p,
.notes ul { font-size: .75rem; }
.notes ul { padding-left: 18px; }
.notes > :last-child { margin-bottom: 18px; }
.notes code { word-break: break-all; }

.notification {
  position: fixed;
  z-index: 20;
  right: 20px;
  bottom: 20px;
  width: min(380px, calc(100% - 40px));
  padding: 16px 18px;
  border: 1px solid var(--compass);
  border-radius: var(--radius-medium);
  background: var(--parchment-raised);
  color: var(--ink-primary);
}

.notification h2 { margin-bottom: 4px; color: var(--compass); font-size: .95rem; }
.notification p { margin-bottom: 0; color: var(--ink-secondary); font-size: .8rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 1040px) {
  .workspace { grid-template-columns: 280px minmax(0, 1fr); }
  .header-timer { grid-template-columns: minmax(140px, 1fr) auto minmax(100px, .5fr); }
  .header-actions { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .topbar,
  .shell { width: min(100% - 24px, 1440px); }
  .topbar { width: 100%; min-height: 64px; padding-inline: 12px; align-items: start; }
  .shell { padding: 16px 0 40px; }
  .workspace { grid-template-columns: 1fr; }
  .control-rail { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .control-panel:last-child { grid-column: 1 / -1; }
  .timer-stage { grid-row: 1; }
}

@media (max-width: 540px) {
  .topbar { gap: 8px; }
  .brand small { display: none; }
  .brand-mark { width: 30px; height: 30px; }
  .theme-switcher span { min-width: 36px; padding-inline: 6px; }
  .header-timer { grid-template-columns: 1fr auto; gap: 8px; }
  .header-timer-copy { grid-column: 1 / -1; }
  .header-countdown { padding-left: 8px; }
  .header-timer .respawn-progress { display: none; }
  .header-actions { grid-column: 1 / -1; }
  .header-actions button { flex: 1; padding-inline: 6px; font-size: .7rem; }
  .control-rail { grid-template-columns: 1fr; }
  .control-panel:last-child { grid-column: auto; }
  .next-card { min-height: 0; padding: 24px 22px; }
  .next-copy h2 { white-space: normal; }
  .countdown strong { font-size: 3.2rem; }
  .timer-heading,
  .search-box { padding-right: 16px; padding-left: 16px; }
  .search-box::before { left: 28px; }
}

@media (max-width: 400px) {
  .brand > span:last-child { display: none; }
  .theme-switcher span { min-width: 34px; }
  .button-row { align-items: stretch; flex-direction: column; }
  .button-row button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; }
}
