:root {
  color-scheme: light;
  --paper: #f2f0ea;
  --panel: #faf9f5;
  --ink: #20201e;
  --muted: #716f68;
  --line: #d6d2c8;
  --accent: #b9422c;
  --green: #277257;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: var(--paper); color: var(--ink); }
button, input, select { font: inherit; color: inherit; }
button, select, input { border-radius: 3px; }

.gallery-topbar {
  min-height: 72px;
  padding: 12px clamp(16px, 3vw, 40px);
  border-bottom: 1px solid var(--line);
  background: rgb(242 240 234 / 96%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.gallery-nav { display: flex; align-items: center; gap: 22px; }
.gallery-nav a { color: var(--muted); font-size: 12px; font-weight: 700; text-decoration: none; }
.gallery-nav a.active, .gallery-nav a:hover { color: var(--accent); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink) !important; font-size: 13px !important; font-weight: 800 !important; }
.brand-mark { width: 32px; height: 32px; display: grid; place-items: center; background: var(--ink); color: white; font-family: Georgia, serif; font-size: 19px; }
.record-count { color: var(--muted); font-size: 12px; }

.gallery-shell, .replay-shell { width: min(1240px, 100%); margin: 0 auto; padding: 38px clamp(16px, 4vw, 48px) 64px; }
.gallery-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 24px; }
.kicker { color: var(--accent); font-size: 9px; font-weight: 800; }
h1 { margin: 4px 0 0; font-family: Georgia, serif; font-size: 38px; font-weight: 500; letter-spacing: 0; }

.gallery-controls {
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns:
    minmax(160px, 1fr) minmax(180px, 1fr) 140px 140px 40px;
  gap: 12px;
  align-items: end;
}
.gallery-controls label { display: grid; gap: 5px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.gallery-controls input, .gallery-controls select {
  width: 100%; height: 38px; padding: 0 10px; border: 1px solid var(--line); background: var(--panel); font-size: 13px; text-transform: none;
}
.direction-button, .pagination button, .replay-controls button, .back-button {
  min-height: 38px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 700;
}
.direction-button { font-size: 20px; }
button:disabled { cursor: default; opacity: .45; }

.gallery-grid { padding-top: 22px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 22px 16px; }
.gallery-card { position: relative; min-width: 0; }
.gallery-card-open { display: block; width: 100%; padding: 0; border: 0; background: transparent; text-align: left; cursor: pointer; }
.gallery-card img { display: block; width: 100%; aspect-ratio: var(--artwork-aspect); border: 1px solid #c7c3b9; background: #ddd9d0; object-fit: contain; }
.gallery-card-info { padding-top: 8px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px 10px; }
.gallery-card strong, .gallery-card span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gallery-card strong { font-family: Georgia, serif; font-size: 16px; font-weight: 500; }
.gallery-card .card-score { grid-row: span 2; color: var(--accent); font-family: Georgia, serif; font-size: 25px; }
.gallery-card span { color: var(--muted); font-size: 11px; }
.gallery-delete {
  position: absolute; top: 8px; right: 8px; width: 40px; height: 40px;
  padding: 9px; border: 1px solid #bdb8ad; background: rgb(250 249 245 / 94%);
  color: var(--accent); cursor: pointer; box-shadow: 0 1px 5px rgb(32 32 30 / 18%);
}
.gallery-delete:hover { background: white; border-color: var(--accent); }
.gallery-delete svg { display: block; width: 100%; height: 100%; }
.gallery-empty { padding: 54px 0; color: var(--muted); text-align: center; }
.pagination { margin-top: 30px; display: flex; align-items: center; justify-content: center; gap: 16px; }
.pagination button { padding: 0 14px; }
.pagination span { min-width: 100px; color: var(--muted); font-size: 12px; text-align: center; }

.replay-heading { display: grid; grid-template-columns: 130px minmax(0, 1fr) auto; align-items: center; gap: 22px; margin-bottom: 24px; }
.back-button { padding: 0 12px; }
.replay-heading h1 { font-size: 30px; }
.replay-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.replay-score { color: var(--accent); font-family: Georgia, serif; font-size: 42px; font-weight: 500; }
.replay-workspace { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.replay-workspace figure { min-width: 0; margin: 0; }
.replay-workspace figcaption { margin-bottom: 7px; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.replay-stage { width: 100%; aspect-ratio: var(--artwork-aspect); display: grid; place-items: center; background: #dedbd3; overflow: hidden; }
.replay-stage img, .replay-stage canvas { display: block; width: 100%; height: 100%; object-fit: contain; image-rendering: auto; }
.replay-controls { margin-bottom: 18px; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.replay-controls > button { padding: 0 15px; }
.speed-control { display: flex; margin-left: 10px; }
.speed-control button { min-width: 44px; border-right-width: 0; border-radius: 0; }
.speed-control button:first-child { border-radius: 3px 0 0 3px; }
.speed-control button:last-child { border-right-width: 1px; border-radius: 0 3px 3px 0; }
.speed-control button.selected { background: var(--ink); color: white; }
#replay-progress { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.gallery-toast { position: fixed; left: 50%; bottom: 24px; padding: 10px 14px; background: var(--ink); color: white; font-size: 12px; opacity: 0; pointer-events: none; transform: translate(-50%, 8px); transition: .16s; }
.gallery-toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 800px) {
  .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gallery-controls { grid-template-columns: 1fr 1fr 44px; }
  .gallery-controls label:first-child { grid-column: 1 / -1; }
  .gallery-controls .sort-filter { grid-column: 1 / 3; }
  .replay-heading { grid-template-columns: 1fr auto; }
  .replay-heading .back-button { grid-column: 1 / -1; justify-self: start; }
}

@media (max-width: 560px) {
  .gallery-topbar { gap: 12px; }
  .gallery-nav { gap: 13px; }
  .brand > span:last-child { display: none; }
  .record-count { display: none; }
  .gallery-shell, .replay-shell { padding-top: 26px; }
  .gallery-controls { grid-template-columns: minmax(0, 1fr) 44px; }
  .gallery-controls label { grid-column: 1 / -1; }
  .gallery-controls .sort-filter { grid-column: 1; }
  .direction-button { grid-column: 2; }
  .gallery-grid { gap: 18px 10px; }
  .replay-workspace { grid-template-columns: 1fr; }
  .replay-controls { flex-wrap: wrap; }
  #replay-progress { width: 100%; margin: 6px 0 0; text-align: right; }
}
