/* Shares its look (tokens, top bar, buttons, forms, dialogs) with the clip library's style.css. */

/* ---------- theme tokens ---------- */
:root {
  color-scheme: light;
  --bg: #e8dcc9;
  --surface: #f0e6d6;
  --surface-2: #e0d1ba;
  --border: #d1bfa4;
  --text: #2d2118;
  --muted: #625140;
  --accent: #1f6b4a;
  --accent-hover: #1e7050;
  --accent-soft: rgba(31, 107, 74, 0.12);
  --on-accent: #f3fbf6;
  --danger: #b3261e;
  --danger-soft: rgba(179, 38, 30, 0.1);
  --progress: #b7791f;
  --done: #2f8f3a;
  --gold: #9a6f00;
  --shadow: 0 1px 2px rgba(60, 40, 20, 0.08), 0 8px 24px rgba(60, 40, 20, 0.1);
  --overlay: rgba(28, 22, 18, 0.55);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #16120f;
    --surface: #211b17;
    --surface-2: #2b2420;
    --border: #3a312b;
    --text: #ece5dc;
    --muted: #a89c90;
    --accent: #2f7d5b;
    --accent-hover: #3a9470;
    --accent-soft: rgba(63, 160, 118, 0.16);
    --on-accent: #eefaf3;
    --danger: #e0685f;
    --danger-soft: rgba(224, 104, 95, 0.14);
    --progress: #d4a03a;
    --done: #4fb35a;
    --gold: #e0b44c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.35);
    --overlay: rgba(8, 6, 5, 0.75);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16120f;
  --surface: #211b17;
  --surface-2: #2b2420;
  --border: #3a312b;
  --text: #ece5dc;
  --muted: #a89c90;
  --accent: #2f7d5b;
  --accent-hover: #3a9470;
  --accent-soft: rgba(63, 160, 118, 0.16);
  --on-accent: #eefaf3;
  --danger: #e0685f;
  --danger-soft: rgba(224, 104, 95, 0.14);
  --progress: #d4a03a;
  --done: #4fb35a;
  --gold: #e0b44c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.35);
  --overlay: rgba(8, 6, 5, 0.75);
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-hover); }
img { max-width: 100%; }
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.5rem; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; }
:focus-visible { outline: 2px solid var(--accent-hover); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-weight: 750;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  margin-right: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.brand-logo { width: 36px; height: 36px; flex: none; }
.nav { display: flex; gap: 4px; }
.nav a {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}
.nav a:hover { color: var(--accent-hover); border-color: var(--border); }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface); border-color: var(--border); }
.theme-toggle, .icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.theme-toggle:hover, .icon-btn:hover { border-color: var(--accent); color: var(--accent-hover); }
@media (max-width: 520px) {
  .topbar { gap: 6px; }
  .topbar .btn, .nav a { min-height: 34px; padding: 0 9px; font-size: 0.85rem; }
  .nav { gap: 2px; }
  .brand { font-size: 1rem; }
}
@media (max-width: 480px) {
  .brand span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent-hover); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger-soft); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 0.85rem; }

label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 14px; }
label .hint { font-weight: 400; color: var(--muted); }
.hint { display: block; font-size: 0.82rem; color: var(--muted); font-weight: 400; margin-top: 4px; }
input[type="text"], input[type="number"], input[type="password"], input[type="search"], select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 400;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.error {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0 0 14px;
}
.error:empty { display: none; }

/* ---------- page layout ---------- */
main { flex: 1 0 auto; width: 100%; max-width: 1400px; margin: 0 auto; padding: 20px 16px 40px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.panel { padding: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty p { margin: 0 0 4px; }

/* ---------- project grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; } }
.project-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: inherit;
  text-decoration: none;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.project-card:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: var(--shadow); }
.project-card:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-hover); }
.project-card .thumb { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: contain; padding: 8px; background: var(--surface-2); }
.project-card .body { padding: 10px 12px 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.project-card h3 { font-size: 1rem; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.row > * { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-card .row { font-size: 0.8rem; }

.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--progress); border-radius: inherit; }
.bar-done > span { background: var(--done); }

/* ---------- dialogs ---------- */
dialog {
  width: min(480px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: var(--overlay); backdrop-filter: blur(3px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px 8px; }
.dialog-body { padding: 8px 18px 18px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding-top: 6px; }

.dropzone {
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 26px 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  font-weight: 400;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone strong { color: var(--text); word-break: break-all; }
.dropzone .hint { margin: 0; }
.dropzone input { display: none; }

.amount-row { display: flex; gap: 6px; margin-top: 6px; }
.amount-row input { flex: 1; min-width: 0; margin: 0; }
.head-preview { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.head-preview input { margin: 0; }

/* ---------- project page ---------- */
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; margin-bottom: 16px; }
.tab {
  flex: 1;
  padding: 8px 16px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.page-tabs { width: fit-content; min-width: min(100%, 460px); }

.viewer { position: relative; aspect-ratio: 16 / 9; max-height: 75vh; width: 100%; overflow: hidden; background: var(--surface-2); }
.highlight-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 10px; padding: 8px 8px 8px 14px; border-radius: 12px; background: var(--accent-soft); }
.contrib-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }

.materials-tab { max-width: 760px; margin: 0 auto; }
.material-tools { display: grid; gap: 8px; margin-bottom: 12px; }
.search { position: relative; }
.search input {
  margin: 0;
  padding: 8px 36px 8px 12px;
  border-radius: 999px;
  background: var(--surface);
  appearance: none;
}
.search input::-webkit-search-cancel-button { display: none; }
.search-clear {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.search-clear:hover { color: var(--text); background: var(--surface-2); }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; max-width: 100%; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip {
  flex: none;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}
.chip .count { color: var(--muted); margin-left: 4px; }
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip.active .count { color: inherit; opacity: 0.8; }
.mod-tag {
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-size: 0.72rem;
  font-weight: 600;
  vertical-align: 1px;
}
.materials-tab .hint { margin: 10px 0 0; text-align: center; }
.viewer canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.viewer img { width: 100%; height: 100%; object-fit: contain; }
.viewer-hint { position: absolute; left: 12px; bottom: 10px; font-size: 0.78rem; color: var(--muted); pointer-events: none; }
.viewer-reset { position: absolute; right: 10px; top: 10px; background: var(--surface); }
.meta { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--muted); font-size: 0.85rem; margin-top: 6px; }

.banner {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  background: var(--surface);
  font-weight: 600;
}

.materials { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.material {
  display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 4px 10px; align-items: center;
  padding: 9px 6px; border-top: 1px solid var(--border); cursor: pointer; border-radius: 8px;
}
.material:first-child { border-top: none; }
.material:hover { background: var(--surface-2); }
.material.selected { background: var(--accent-soft); }
.material .swatch { width: 20px; height: 20px; border-radius: 4px; border: 1px solid rgb(0 0 0 / 0.15); grid-row: span 2; }
.material .swatch.icon { border: none; border-radius: 2px; background-size: 100% 100%; image-rendering: pixelated; }
.material .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.material .count { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.material .bar { grid-column: 2; }
.material .sub { grid-column: 3; text-align: right; font-size: 0.8rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.material .count { color: var(--muted); font-size: 0.85rem; }
.material.complete .name::after { content: " ✓"; }
.material.complete .name, .material.complete .count, .material.complete .sub { color: var(--done); font-weight: 600; }

.people { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.person { display: flex; align-items: center; gap: 10px; padding: 6px 4px; }
.person .who { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.person .amt { flex: 1 1 0; min-width: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.head { image-rendering: pixelated; border-radius: 6px; background: var(--surface-2); flex: none; }
.head-missing { visibility: hidden; }

/* Hover / tap tooltip for item counts */
.tip { position: relative; cursor: help; border-bottom: 1px dotted var(--muted); }
.tip:hover::after, .tip:focus::after {
  content: attr(data-tip); position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 5;
  background: var(--text); color: var(--bg); padding: 5px 9px; border-radius: 8px;
  font-size: 0.8rem; font-weight: 600; white-space: nowrap; box-shadow: var(--shadow);
}
.tip:focus { outline: none; }

/* ---------- leaderboard ---------- */
.leaderboard { list-style: none; padding: 0; margin: 0; overflow: hidden; }
.leader { display: grid; grid-template-columns: 44px 40px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--border); }
.leader:first-child { border-top: none; }
.rank { font-weight: 750; font-size: 1.1rem; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.leader:nth-child(1) .rank { color: var(--gold); }
.leader:nth-child(2) .rank { color: #8f969c; }
.leader:nth-child(3) .rank { color: #b0703a; }
.leader .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; }
.leader .total { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; }
.leader .total small { display: block; font-weight: 400; color: var(--muted); }

/* ---------- gate / login ---------- */
.gate { max-width: 420px; margin: 12vh auto; padding: 0 16px; text-align: center; }
.gate .panel { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 28px 22px; box-shadow: var(--shadow); text-align: left; }
.gate h1 { font-size: 1.4rem; margin-bottom: 8px; }
.gate p { color: var(--muted); margin: 0; }

/* ---------- admin page ---------- */
.manage { max-width: 860px; }
.manage .panel { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 20px 18px; margin-bottom: 16px; }
.manage h2 { margin-bottom: 6px; }
.manage h3 { font-size: 1rem; margin: 20px 0 10px; }
.meter { display: flex; height: 10px; margin: 4px 0 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter span { min-width: 3px; }
.meter-site { background: var(--accent); }
.meter-other { background: var(--muted); opacity: 0.5; }
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 14px 0 4px; }
.stat-tile { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.stat-tile strong { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.stat-tile span { color: var(--muted); font-size: 0.82rem; }
.stat-projects td:first-child { width: 45%; }
.log { list-style: none; margin: 0 0 12px; padding: 0; font-size: 0.9rem; }
.log li { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.log time { flex: none; width: 8.5em; color: var(--muted); font-size: 0.82rem; padding-top: 1px; }
.log span { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 520px) { .log li { flex-direction: column; gap: 2px; } }
.manage .hint { font-size: 0.85rem; margin: 0 0 10px; }
.inline-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.inline-form input { margin: 0; flex: 1 1 260px; min-width: 0; padding: 6px 10px; height: 38px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9rem; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table td, .table th { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.table img.mini { width: 64px; height: 48px; object-fit: contain; display: block; border-radius: 8px; background: var(--surface-2); }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table .act { text-align: right; white-space: nowrap; }
.table .act > * + * { margin-left: 6px; }
.sub-table > td { background: var(--surface-2); padding: 0 !important; }
.sub-table table { width: 100%; border-collapse: collapse; }
.sub-table table td, .sub-table table th { padding: 7px 12px; }

@media (max-width: 560px) {
  main { padding: 16px 16px 40px; }
  .leader { grid-template-columns: 30px 32px minmax(0, 1fr) auto; padding: 10px 12px; gap: 10px; }
  .table .hide-sm { display: none; }
  .table .act { white-space: normal; }
  .table .act > * { margin: 2px 0 2px 6px; }
  .viewer-hint { display: none; }
  .viewer { aspect-ratio: 1; }
  .page-tabs { width: 100%; min-width: 0; }
  .tab { padding: 8px 6px; }
}

/* ---------- toast & footer ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 100;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  box-shadow: var(--shadow);
}
.site-footer { padding: 24px 16px calc(24px + env(safe-area-inset-bottom, 0px)); text-align: center; font-size: 0.8rem; color: var(--muted); }
.site-footer p { margin: 0 0 4px; }
