:root {
  --bg: #fafaf9;
  --cell: #ffffff;
  --cell-alt: #f4f4f2;
  --line: #dcdcd8;
  --text: #18181b;
  --muted: #71717a;
  --focus: #2563eb;
  --item: 72px;
  --label: 88px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111112;
    --cell: #19191b;
    --cell-alt: #1e1e21;
    --line: #2e2e33;
    --text: #e7e7e4;
    --muted: #8d8d94;
    --focus: #6b9cff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111112; --cell: #19191b; --cell-alt: #1e1e21; --line: #2e2e33;
  --text: #e7e7e4; --muted: #8d8d94; --focus: #6b9cff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.page { max-width: 1280px; margin: 0 auto; padding: 20px 20px 48px; }

/* top bar */
.bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 20px; margin-bottom: 14px; }
.title {
  flex: 1 1 280px; min-width: 0; margin-left: -6px; padding: 2px 6px;
  font-size: 20px; font-weight: 600; border: 1px solid transparent; border-radius: 4px; background: none;
}
.title:hover { border-color: var(--line); }
.title:focus { outline: none; border-color: var(--focus); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; }
.stat { color: var(--muted); white-space: nowrap; }
.stat.offline { color: #c2410c; }

.link {
  background: none; border: 0; padding: 0; cursor: pointer; color: var(--text); text-decoration: none; white-space: nowrap;
}
.link:hover { text-decoration: underline; text-underline-offset: 3px; }
.link[aria-pressed="true"] { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }

.btn {
  display: inline-flex; align-items: center; cursor: pointer; white-space: nowrap;
  height: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: 4px; background: var(--cell);
}
.btn:hover { border-color: var(--muted); }
.btn.solid { background: var(--text); color: var(--bg); border-color: var(--text); }

/* add items */
.adder { display: flex; gap: 6px; flex-wrap: wrap; }
.adder input {
  flex: 1 1 260px; min-width: 0; height: 34px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 4px; background: var(--cell);
}
.adder input:focus { outline: none; border-color: var(--focus); }
.note { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.note:not(.empty) { display: none; }
.table { margin-top: 14px; }

/* the shared table */
.table { border: 1px solid var(--line); background: var(--line); display: flex; flex-direction: column; gap: 1px; }
.row { display: grid; grid-template-columns: var(--label) minmax(0, 1fr) minmax(0, 1fr); gap: 1px; }
.row > * { background: var(--cell); }
#tierRows { display: flex; flex-direction: column; gap: 1px; }

.label {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: calc(var(--item) + 4px); padding: 4px; border: 0; color: #111;
  font-size: 22px; font-weight: 600; word-break: break-word; line-height: 1.1;
}
button.label { cursor: pointer; }
button.label:hover { filter: brightness(.95); }
.label.long { font-size: 15px; }
.corner { min-height: 0; }
.label.pool-label { color: var(--muted); font-size: 12px; font-weight: 500; background: var(--cell-alt); word-break: normal; }

.col-head { display: flex; align-items: center; gap: 8px; padding: 6px 8px; }
.name-input {
  flex: 1; min-width: 0; padding: 2px 4px; margin-left: -4px; font-weight: 600;
  border: 1px solid transparent; border-radius: 4px; background: none;
}
.name-input:hover { border-color: var(--line); }
.name-input:focus { outline: none; border-color: var(--focus); }
.head-meta { display: flex; gap: 12px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.head-meta .link { color: var(--muted); }

.zone { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 2px; padding: 2px; min-width: 0; min-height: calc(var(--item) + 4px); }
.zone.pool { background: var(--cell-alt); min-height: calc(var(--item) * 1.5); }

/* items */
.item {
  position: relative; flex: none; width: var(--item); height: var(--item); overflow: hidden;
  display: flex; align-items: center; justify-content: center; text-align: center; padding: 4px;
  background: #e9e7e1; color: #18181b; font-size: 12px; font-weight: 500; line-height: 1.15;
  container-type: size;
  cursor: grab; user-select: none; -webkit-user-select: none; touch-action: none;
}
.item .t { font-size: clamp(8px, calc(100cqw / (var(--w) * 0.68)), 13px); overflow-wrap: anywhere; }
.item.has-img { padding: 0; background: #000; }
.item img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 20%; pointer-events: none; -webkit-user-drag: none; }
.item .cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 1px 3px; font-size: 10px;
  background: rgb(0 0 0 / .7); color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item .del {
  position: absolute; top: 0; right: 0; width: 18px; height: 18px; padding: 0; border: 0;
  background: rgb(0 0 0 / .7); color: #fff; font-size: 12px; line-height: 18px; cursor: pointer; display: none;
}
.item:hover .del { display: block; }
@media (hover: none) { .pool .item .del { display: block; width: 16px; height: 16px; line-height: 16px; font-size: 11px; } }
.item.hl { outline: 2px solid var(--focus); outline-offset: -2px; }
.item.dragging { opacity: .3; }
.item .badge {
  position: absolute; top: 0; left: 0; padding: 0 4px; height: 16px; line-height: 16px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 11px; font-weight: 600; color: #111; box-shadow: 0 0 0 1px rgb(0 0 0 / .35);
}
.diff-mode .item.same { opacity: .3; }

.drag-ghost { position: fixed; z-index: 1000; margin: 0; pointer-events: none; box-shadow: 0 6px 18px rgb(0 0 0 / .35); }
.placeholder { flex: none; width: var(--item); height: var(--item); border: 1px dashed var(--muted); }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; }

/* overlays */
.drop-overlay {
  position: fixed; inset: 0; z-index: 900; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  background: rgb(0 0 0 / .35);
}
.drop-overlay span { background: var(--cell); padding: 12px 18px; border: 1px solid var(--line); }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 1100;
  max-width: calc(100vw - 32px); padding: 8px 14px; background: var(--text); color: var(--bg); font-size: 13px;
}

/* tier dialog */
.dialog {
  width: min(480px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 18px;
  border: 1px solid var(--line); background: var(--cell); color: var(--text);
}
.dialog::backdrop { background: rgb(0 0 0 / .4); }
.dialog h2 { margin: 0 0 4px; font-size: 16px; }
.dialog-note { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.templates { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 14px; }
.templates .btn { height: 28px; padding: 0 8px; font-size: 13px; }
.tier-editor { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.tier-editor li { display: flex; gap: 4px; align-items: center; }
.tier-editor input[type="color"] { flex: none; width: 34px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 4px; background: var(--cell); }
.tier-editor input[type="text"] { flex: 1; min-width: 0; height: 34px; padding: 0 8px; border: 1px solid var(--line); border-radius: 4px; background: var(--bg); }
.tier-editor .btn { width: 34px; padding: 0; justify-content: center; }
.tier-editor .btn:disabled { opacity: .35; cursor: default; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 16px; }

@media (max-width: 640px) {
  :root { --item: 56px; --label: 56px; }
  .page { padding: 16px 16px 40px; }
  .label { font-size: 17px; }
  .label.long { font-size: 10px; }
  .label.pool-label { font-size: 10px; }
  .head-meta { gap: 8px; font-size: 12px; }
  .head-meta .count { display: none; }
  .col-head { padding: 6px; gap: 4px; }
}
