:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --ink: #16202b;
  --muted: #64707d;
  --line: #e1e5ea;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --accent-soft: #e8f0fe;
  --ok-bg: #e6f4ea;
  --ok: #1e6b3a;
  --err-bg: #fdecea;
  --err: #b42318;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #171e26;
    --surface-2: #1e2731;
    --ink: #e6ebf0;
    --muted: #93a0ad;
    --line: #29333e;
    --accent: #4c8dff;
    --accent-soft: #1b2a40;
    --ok-bg: #12301f;
    --ok: #7fd49a;
    --err-bg: #3a1714;
    --err: #ff9b8f;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.5rem; line-height: 1.2; margin: 0; font-weight: 650; }
h2 { font-size: 1rem; margin: 0; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

button, input, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Top bar */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.top-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  min-height: 56px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.brand:hover { text-decoration: none; }
.brand img { width: 24px; height: 24px; border-radius: 6px; }

.top nav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.top nav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

.top nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.top nav a.active { background: var(--accent-soft); color: var(--accent); }

.who {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.who-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  color: var(--ink);
}

.who-link:hover { background: var(--surface-2); text-decoration: none; }

.avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
}

/* Buttons */

.btn,
button[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
}

.btn:hover, button[type="submit"]:hover { filter: brightness(1.07); text-decoration: none; }

.btn.ghost,
button.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

.btn.ghost:hover, button.ghost:hover { color: var(--ink); background: var(--surface-2); filter: none; }

button.text-button {
  min-height: 0;
  font-weight: 500;
  background: none;
  border: 0;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}

button.text-button:hover { background: var(--surface-2); color: var(--ink); }
button.text-button.danger { color: var(--err); }
button.text-button.danger:hover { background: var(--err-bg); }

/* Layout */

main {
  width: min(1200px, calc(100% - 32px));
  margin: 28px auto 64px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.page-head .sub { margin-top: 2px; }

.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-width: 26px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  justify-content: center;
}

.sub, .lede { color: var(--muted); }

/* Archive day navigation */

.day-nav { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.disabled { opacity: 0.45; pointer-events: none; }

/* Sort switch */

.sort {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: -6px 0 16px;
  font-size: 0.875rem;
}
.sort-label { color: var(--muted); margin-right: 4px; }
.sort a {
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
}
.sort a:hover { color: var(--ink); background: var(--surface-2); }
.sort a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }

/* Chart grid */

.day {
  position: sticky;
  top: 56px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 28px 0 12px;
  padding: 10px 0;
  background: var(--bg);
}

.day:first-of-type { margin-top: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(333px, 1fr));
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0;
  overflow: hidden;
  text-align: left;
  cursor: zoom-in;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.15s;
}

.card:hover { border-color: var(--accent); transform: translateY(-1px); }

.card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.card-body {
  display: grid;
  gap: 2px;
  padding: 10px 12px 12px;
}

.card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.card .time {
  font-size: 1.05rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.card .center {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.card .name {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card .stamps {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}

.empty {
  padding: 56px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* Detail */

.back {
  display: inline-block;
  margin-bottom: 12px;
  font-weight: 500;
}

.detail-title { margin-bottom: 4px; word-break: break-all; }
.lede { margin-bottom: 18px; }

.full {
  width: 100%;
  height: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* Panels & forms */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 22px;
}

.stack-form {
  display: grid;
  gap: 6px;
  max-width: 420px;
}

.stack-form label { margin-top: 8px; }
.stack-form label:first-of-type { margin-top: 0; }
.stack-form button[type="submit"] { margin-top: 14px; justify-self: start; }

label { font-size: 0.88rem; font-weight: 500; }

input, select {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.hint { color: var(--muted); font-size: 0.85rem; }

/* Table */

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

table { width: 100%; border-collapse: collapse; }

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

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
th { font-size: 0.78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
td.actions { text-align: right; width: 1%; white-space: nowrap; }

.user-cell { display: flex; align-items: center; gap: 10px; font-weight: 500; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
}

.badge.admin { background: var(--accent-soft); color: var(--accent); }

/* Flash */

.flash {
  padding: 10px 14px;
  margin: 0 0 16px;
  border-radius: 8px;
  font-weight: 500;
}

.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.error { background: var(--err-bg); color: var(--err); }

/* Login */

.login-body {
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card {
  width: min(380px, 100%);
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  text-align: center;
}

.login-brand img { width: 44px; height: 44px; border-radius: 10px; }
.login-brand h1 { font-size: 1.3rem; letter-spacing: 0.04em; }

.login-card .panel { padding: 24px; margin: 0; }
.login-card .stack-form { max-width: none; }
.login-card button[type="submit"] { justify-self: stretch; }

/* Error */

.error-page {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 72px 16px;
  text-align: center;
}

.error-code { font-size: 3rem; font-weight: 700; color: var(--muted); line-height: 1; }

/* Dialogs */

dialog {
  padding: 0;
  border: 0;
  color: var(--ink);
  max-width: calc(100vw - 24px);
}

dialog::backdrop { background: rgba(10, 14, 20, 0.6); }

#user-form {
  width: min(400px, calc(100vw - 32px));
  padding: 22px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

#user-form h2 { margin-bottom: 14px; font-size: 1.1rem; }
#user-form .stack-form { max-width: none; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions button[type="submit"] { margin-top: 0; }

/* Viewer */

#viewer {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  margin: 0;
  background: rgba(10, 14, 20, 0.97);
  color: #e6ebf0;
}

#viewer[open] { display: flex; flex-direction: column; }
#viewer::backdrop { background: transparent; }

.viewer-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
}

.modal-caption {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.viewer-count { color: #93a0ad; font-variant-numeric: tabular-nums; font-size: 0.9rem; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #e6ebf0;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.18); text-decoration: none; }
.icon-btn[hidden] { display: none; }

.viewer-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 64px 16px;
}

.viewer-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #fff;
  border-radius: 6px;
}

.viewer-stage .nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 64px;
  font-size: 1.6rem;
}

.viewer-stage .prev { left: 10px; }
.viewer-stage .next { right: 10px; }

/* Mobile */

@media (max-width: 760px) {
  .top-inner { flex-wrap: wrap; gap: 0 12px; padding-top: 8px; }
  .who { order: 1; }
  .who-name { display: none; }
  .who-link { padding-right: 4px; }
  .top nav {
    order: 2;
    flex: 1 0 100%;
    overflow-x: auto;
    padding: 8px 0;
    scrollbar-width: none;
  }
  .day { position: static; }
  .page-head:has(.day-nav) { flex-direction: column; align-items: stretch; }
  .day-nav .btn { flex: 1; padding: 0 8px; font-size: 0.85rem; white-space: nowrap; }
  main { width: calc(100% - 24px); margin-top: 20px; }
  h1 { font-size: 1.3rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .card .name { display: none; }
  .card-top { flex-direction: column; gap: 0; }
  .viewer-stage { padding: 0 8px 8px; }
  .viewer-stage .nav { display: none; }
}
