:root {
  color-scheme: light;
  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #eeede9;
  --text: #1b1b1a;
  --text-2: #55544f;
  --border: #d9d8d2;
  --accent: #2a78d6;
  --accent-text: #ffffff;
  --danger: #c93a39;
  --radius: 10px;
  --shadow: 0 6px 24px rgb(0 0 0 / 0.12);
  /* single-hue sequential ramp for charts (light → dark) */
  --seq-0: #eeede9; --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5; --seq-5: #256abf; --seq-6: #104281;
  --series-1: #2a78d6;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #141517;
    --surface: #1d1e21;
    --surface-2: #26272b;
    --text: #f0efec;
    --text-2: #b9b8b0;
    --border: #36373c;
    --accent: #3987e5;
    --danger: #e66767;
    --shadow: 0 6px 24px rgb(0 0 0 / 0.5);
    --seq-0: #26272b; --seq-1: #0d366b; --seq-2: #184f95; --seq-3: #256abf; --seq-4: #3987e5; --seq-5: #6da7ec; --seq-6: #b7d3f6;
    --series-1: #3987e5;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent); }
h1 { font-size: 1.8rem; line-height: 1.2; margin: 0 0 0.6em; }
h2 { font-size: 1.2rem; margin: 1.6em 0 0.6em; }
code, kbd { background: var(--surface-2); padding: 0 0.3em; border-radius: 4px; }
.muted { color: var(--text-2); }
.error { color: var(--danger); }
.danger-text { color: var(--danger); }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

button, .button {
  font: inherit; font-size: 0.95rem; cursor: pointer; display: inline-flex; align-items: center; gap: 0.4em; justify-content: center;
  padding: 0.5em 1em; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; min-height: 40px;
}
button:hover, .button:hover { border-color: var(--text-2); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; min-height: 0; }
button.small, .button.small { padding: 0.25em 0.75em; min-height: 32px; font-size: 0.9rem; }
button.wide { width: 100%; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

input, select, textarea {
  font: inherit; padding: 0.5em 0.7em; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); min-height: 40px; max-width: 100%;
}
label { display: flex; flex-direction: column; gap: 0.3em; font-weight: 500; }
label small { font-weight: 400; color: var(--text-2); }
label.check { flex-direction: row; align-items: flex-start; gap: 0.6em; font-weight: 400; }
label.check input { min-height: 0; margin-top: 0.35em; }
.stack { display: flex; flex-direction: column; gap: 1em; }
.inline { display: flex; flex-wrap: wrap; gap: 0.6em; align-items: flex-end; }
.row { display: flex; gap: 0.5em; flex-wrap: wrap; }
.row input { flex: 1; min-width: 6em; }
.actions { display: flex; gap: 0.6em; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- page chrome ---------- */

.topnav {
  display: flex; align-items: center; justify-content: space-between; gap: 1em; flex-wrap: wrap;
  padding: 0.6em max(16px, env(safe-area-inset-left)); background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.5em; font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.1rem; }
.topnav nav { display: flex; gap: 1em; align-items: center; flex-wrap: wrap; }
.topnav nav a:not(.button) { color: var(--text); text-decoration: none; }
.announcement { background: #fff4d6; color: #4a3800; padding: 0.6em 16px; text-align: center; }
.page { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 24px 16px 48px; }
.footer { display: flex; gap: 1.2em; justify-content: center; flex-wrap: wrap; padding: 1.2em 16px; border-top: 1px solid var(--border); font-size: 0.9rem; }
.footer a { color: var(--text-2); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.card.narrow { max-width: 460px; margin: 4vh auto; }
.prose { max-width: 820px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1em; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }
.table { border-collapse: collapse; width: 100%; font-size: 0.93rem; }
.table th, .table td { text-align: left; padding: 0.55em 0.6em; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--text-2); font-weight: 600; }
.table td.url { word-break: break-all; max-width: 28em; }
.badge { display: inline-block; padding: 0.1em 0.6em; border-radius: 99px; background: var(--surface-2); font-size: 0.85rem; }
.badge.danger { color: var(--danger); }

#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100000; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: #222; color: #fff; padding: 0.6em 1em; border-radius: 8px; box-shadow: var(--shadow); animation: toast-in 0.2s ease-out; }
.toast.error { background: #8f1d1c; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- welcome ---------- */

.hero { display: grid; grid-template-columns: 1.2fr 1fr; gap: 32px; align-items: center; margin: 4vh 0 6vh; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.2rem); }
.lead { font-size: 1.15rem; color: var(--text-2); }
.hero .actions { justify-content: flex-start; margin: 1.5em 0 0.5em; }
.hero-art { position: relative; height: 320px; }
.polaroid { position: absolute; width: 52%; aspect-ratio: 4 / 3; border: 10px solid #fff; border-bottom-width: 30px; box-shadow: var(--shadow); border-radius: 4px; }
.p1 { left: 4%; top: 12%; transform: rotate(-8deg); background: linear-gradient(135deg, #f6a04d, #e45b6b); }
.p2 { left: 40%; top: 0; transform: rotate(6deg); background: linear-gradient(160deg, #5aa8ef, #3c4fb8); }
.p3 { left: 26%; top: 44%; transform: rotate(-2deg); background: linear-gradient(120deg, #4fc69a, #1f7b6a); }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.features article { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.features h3 { margin: 0 0 0.4em; }
.features p { margin: 0; color: var(--text-2); }
@media (max-width: 720px) {
  .hero { grid-template-columns: 1fr; }
  .hero-art { height: 220px; }
}

/* ---------- desktops list ---------- */

.desk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.desk-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.desk-thumb { display: flex; align-items: flex-end; height: 110px; text-decoration: none; background: linear-gradient(0deg, rgb(0 0 0 / 0.35), transparent), var(--desk-bg, #1e2430); }
.desk-thumb span { color: #fff; padding: 0.5em 0.8em; font-size: 0.9rem; }
.desk-meta { padding: 0.8em 1em 0; }
.desk-meta h3 { margin: 0; }
.desk-meta p { margin: 0.2em 0; font-size: 0.9rem; }
.desk-actions { display: flex; flex-wrap: wrap; gap: 0.4em; padding: 0.8em 1em 1em; margin-top: auto; }
.desk-actions button, .desk-actions .button { min-height: 34px; padding: 0.3em 0.8em; font-size: 0.9rem; }
.offer { background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius); padding: 0.8em 1em; margin: 0 0 0.6em; display: flex; flex-wrap: wrap; gap: 0.6em; align-items: center; }
.offer.muted { border-color: var(--border); }

/* ---------- desktop ---------- */

.desktop-body { overflow: hidden; overscroll-behavior: none; background: #1e2430; }
.desktop {
  position: fixed; inset: 0; background: #1e2430; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  outline: none;
}
#items { position: absolute; inset: 0; }
.grid-overlay {
  position: absolute; inset: 0; pointer-events: none; opacity: 0.35;
  background-image: linear-gradient(to right, rgb(255 255 255 / 0.18) 1px, transparent 1px),
    linear-gradient(to bottom, rgb(255 255 255 / 0.18) 1px, transparent 1px);
}
.item { position: absolute; touch-action: none; cursor: grab; outline: none; transform-origin: 50% 50%; }
.readonly .item { cursor: default; }
.item img { width: 100%; height: 100%; display: block; object-fit: fill; pointer-events: none; border-radius: 2px; box-shadow: 0 4px 18px rgb(0 0 0 / 0.35); background: rgb(255 255 255 / 0.04); }
.item.inverted img { filter: invert(1); }
.item.broken img { visibility: hidden; }
.item.broken { background: repeating-linear-gradient(45deg, #333 0 8px, #3a3a3a 8px 16px); }
.item.error::after { content: "!"; position: absolute; top: 6px; left: 6px; width: 20px; height: 20px; border-radius: 50%; background: #c93a39; color: #fff; font: 700 13px/20px system-ui; text-align: center; }
.item:focus-visible, .item.selected { outline: 2px solid #5aa8ef; outline-offset: 2px; }
.item.selected { cursor: move; }
.handle { position: absolute; display: none; width: 22px; height: 22px; background: #fff; border: 2px solid #2a78d6; border-radius: 50%; touch-action: none; }
.item.selected .handle { display: block; }
.handle.nw { left: -11px; top: -11px; cursor: nwse-resize; }
.handle.se { right: -11px; bottom: -11px; cursor: nwse-resize; }
.handle.ne { right: -11px; top: -11px; cursor: nesw-resize; }
.handle.sw { left: -11px; bottom: -11px; cursor: nesw-resize; }
.handle.rotate { left: 50%; top: -42px; margin-left: -11px; cursor: grab; background: #2a78d6; border-color: #fff; }
.handle.rotate::after { content: ""; position: absolute; left: 8px; top: 20px; width: 2px; height: 20px; background: #5aa8ef; }
@media (pointer: coarse) {
  .handle { width: 30px; height: 30px; }
  .handle.nw { left: -15px; top: -15px; } .handle.se { right: -15px; bottom: -15px; }
  .handle.ne { right: -15px; top: -15px; } .handle.sw { left: -15px; bottom: -15px; }
  .handle.rotate { margin-left: -15px; top: -54px; }
  .handle.rotate::after { left: 12px; top: 28px; height: 24px; }
}

.empty-hint { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: rgb(255 255 255 / 0.35); pointer-events: none; text-align: center; padding: 16px; }
.empty-hint p { font-size: 1.6rem; margin: 0; }
.readonly .empty-hint small { display: none; }
.drop-overlay { position: fixed; inset: 12px; border: 3px dashed rgb(255 255 255 / 0.6); border-radius: 18px; background: rgb(42 120 214 / 0.18); display: flex; align-items: center; justify-content: center; z-index: 99990; pointer-events: none; }
.drop-overlay p { color: #fff; font-size: 2rem; }

.toolbar {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); z-index: 99980;
  display: flex; gap: 6px; align-items: center; opacity: 0.55; transition: opacity 0.2s;
}
.toolbar:hover, .toolbar:focus-within { opacity: 1; }
@media (pointer: coarse) { .toolbar { opacity: 0.85; } }
.tb { background: rgb(20 22 28 / 0.75); color: #fff; border: 1px solid rgb(255 255 255 / 0.15); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); min-height: 38px; padding: 0.3em 0.8em; }
.tb:hover { border-color: rgb(255 255 255 / 0.5); }
.tb.active { background: #2a78d6; }
#desktop-name { max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.readonly .edit-only { display: none; }
.toolbar .badge { background: rgb(20 22 28 / 0.75); color: #fff; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: #1baf7a; }
.conn.offline { background: #e34948; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }

.clock {
  position: fixed; top: max(10px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right)); z-index: 99970;
  text-align: right; color: #fff; text-shadow: 0 1px 6px rgb(0 0 0 / 0.7); pointer-events: none; font-variant-numeric: tabular-nums;
}
.clock .time { font-size: clamp(1.4rem, 3vw, 2.2rem); font-weight: 300; line-height: 1.1; }
.clock .date { font-size: clamp(0.8rem, 1.4vw, 1rem); opacity: 0.85; }

.menu {
  position: fixed; top: calc(max(10px, env(safe-area-inset-top)) + 46px); left: max(10px, env(safe-area-inset-left)); z-index: 99985;
  background: rgb(24 26 32 / 0.95); color: #fff; border: 1px solid rgb(255 255 255 / 0.15); border-radius: 12px; box-shadow: var(--shadow);
  padding: 8px; width: min(340px, calc(100vw - 20px)); max-height: calc(100vh - 80px); overflow-y: auto; display: flex; flex-direction: column;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.menu > button, .menu > a { background: none; border: 0; color: #fff; text-align: left; justify-content: flex-start; padding: 0.5em 0.7em; border-radius: 8px; text-decoration: none; min-height: 38px; display: flex; align-items: center; }
.menu > button:hover, .menu > a:hover, .menu-desk:hover { background: rgb(255 255 255 / 0.08); }
.menu hr { border: 0; border-top: 1px solid rgb(255 255 255 / 0.12); margin: 6px 0; width: 100%; }
.menu-desk { display: flex; align-items: center; border-radius: 8px; }
.menu-desk a { flex: 1; color: #fff; text-decoration: none; padding: 0.5em 0.7em; overflow: hidden; text-overflow: ellipsis; }
.menu-desk small { opacity: 0.6; }
.menu-desk.current a { font-weight: 700; }
.menu-desk.current a::before { content: "● "; color: #5aa8ef; }
.menu-desk button.icon { background: none; border: 0; color: #fff; min-height: 34px; padding: 0 0.6em; opacity: 0.7; }
.menu .offer-note { color: #ffd479; padding: 0.5em 0.7em; text-decoration: none; }
.menu-legal { font-size: 0.8rem; padding: 0.5em 0.7em 0.2em; opacity: 0.6; }
.menu-legal a { color: #fff; }

.selection-bar {
  position: fixed; bottom: max(14px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 99980;
  display: flex; gap: 4px; padding: 6px; border-radius: 12px; background: rgb(24 26 32 / 0.9); border: 1px solid rgb(255 255 255 / 0.15);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); max-width: calc(100vw - 20px); overflow-x: auto;
}
.selection-bar button { background: none; border: 0; color: #fff; min-height: 40px; padding: 0.3em 0.7em; white-space: nowrap; }
.selection-bar button:hover { background: rgb(255 255 255 / 0.1); }
.selection-bar button.active { background: #2a78d6; }
.selection-bar button.danger { color: #ff8a8a; }

dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); padding: 22px; width: min(480px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(0 0 0 / 0.5); }
dialog h2 { margin-top: 0; }
.or { text-align: center; color: var(--text-2); font-size: 0.9rem; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: 0.3em 1em; margin: 0 0 1em; }
.details dt { color: var(--text-2); }
.details dd { margin: 0; word-break: break-all; }

/* ---------- admin ---------- */

.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin: 1em 0 1.5em; }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; }
.tabs button.active { border-bottom-color: var(--accent); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat-value { font-size: 1.9rem; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--text); font-weight: 500; }
.stat-sub { color: var(--text-2); font-size: 0.85rem; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-top: 16px; }
.chart { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.chart figcaption { font-weight: 600; margin-bottom: 0.8em; }
.hbar { display: grid; grid-template-columns: 7.5em 1fr auto; gap: 0.6em; align-items: center; margin: 6px 0; font-size: 0.9rem; }
.hbar-label { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 12px; }
.hbar-fill { display: block; height: 100%; min-width: 2px; background: var(--series-1); border-radius: 0 4px 4px 0; }
.hbar-value { color: var(--text-2); font-variant-numeric: tabular-nums; }
.hbar:hover .hbar-fill, .vbar:hover .vbar-fill { filter: brightness(1.15); }
.vbars { display: flex; align-items: flex-end; gap: 2px; height: 140px; }
.vbar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; min-width: 8px; }
.vbar-fill { width: 100%; max-width: 28px; min-height: 2px; background: var(--series-1); border-radius: 4px 4px 0 0; }
.vbar-label { font-size: 0.7rem; color: var(--text-2); margin-top: 4px; white-space: nowrap; }
.heatmap { display: grid; grid-template-columns: 2.8em repeat(24, 1fr); gap: 2px; font-size: 0.75rem; overflow-x: auto; min-width: 0; }
.hm-day { color: var(--text-2); align-self: center; }
.hm-hour { color: var(--text-2); text-align: left; }
.hm-cell { aspect-ratio: 1; min-width: 10px; border-radius: 3px; background: var(--seq-0); }
.hm-cell:hover { outline: 2px solid var(--text); }
.hm-cell.l1 { background: var(--seq-1); } .hm-cell.l2 { background: var(--seq-2); } .hm-cell.l3 { background: var(--seq-3); }
.hm-cell.l4 { background: var(--seq-4); } .hm-cell.l5 { background: var(--seq-5); } .hm-cell.l6 { background: var(--seq-6); }
.hm-legend { display: flex; gap: 3px; align-items: center; margin-top: 10px; font-size: 0.8rem; color: var(--text-2); flex-wrap: wrap; }
.hm-legend .hm-cell { width: 14px; min-width: 14px; }
.settings fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px 16px; margin: 0 0 16px; display: grid; gap: 14px; background: var(--surface); }
.settings legend { font-weight: 700; padding: 0 0.4em; }
.settings label.switch { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0.6em; }
.settings label.switch input { width: 20px; height: 20px; min-height: 0; }
.settings label.switch small { flex-basis: 100%; padding-left: calc(20px + 0.6em); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 560px) {
  #desktop-name { display: none; }
  .clock .date { max-width: 52vw; margin-left: auto; }
}
