:root {
  --bg: #121110;
  --surface: #1b1a18;
  --surface-2: #24221f;
  --line: #34312c;
  --text: #ece8e1;
  --muted: #9a948a;
  --accent: #e8b64c;
  --accent-ink: #1a1408;
  --danger: #e2735a;
  --radius: 10px;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --sans: 'Inter Tight', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--sans); }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.brand em { font-style: normal; color: var(--muted); font-weight: 400; }
.brand-mark { width: 12px; height: 12px; border-radius: 3px; background: var(--accent); box-shadow: 0 0 0 3px rgba(232, 182, 76, .18); }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 14px; cursor: pointer; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--surface-2); border-color: #4a463f; }
.btn:focus-visible, input:focus-visible, select:focus-visible, .card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: #f0c566; border-color: #f0c566; }
.btn-ghost { background: transparent; }
select { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.login-card .brand { margin-bottom: 8px; font-size: 18px; }
.login-card label { color: var(--muted); font-size: 13px; }
.login-card input { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.login-error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 13px; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; padding: 14px 24px; background: rgba(18, 17, 16, .92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.search { flex: 1 1 360px; display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; }
.search:focus-within { border-color: var(--accent); }
.search svg { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; flex: none; }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; padding: 11px 0; font-size: 16px; }
.search kbd { font: 12px var(--mono); color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; }

.tags { display: flex; gap: 6px; padding: 14px 24px 0; overflow-x: auto; scrollbar-width: none; }
.tag { flex: none; border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--muted); cursor: pointer; }
.tag:hover { color: var(--text); border-color: #4a463f; }
.tag.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tag b { font: 11px var(--mono); opacity: .7; margin-left: 4px; font-weight: 400; }

.summary { padding: 12px 24px; color: var(--muted); font-size: 13px; font-family: var(--mono); }

/* Grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; padding: 0 24px 24px; }
.card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; text-align: left; padding: 0; transition: border-color .15s, transform .15s; }
.card:hover { border-color: #57524a; transform: translateY(-2px); }
.thumb { position: relative; aspect-ratio: 9 / 16; background: #0b0a0a; overflow: hidden; }
.thumb video, .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .3s; }
.thumb .ready { opacity: 1; }
.thumb .badge { position: absolute; right: 8px; bottom: 8px; font: 11px var(--mono); background: rgba(0, 0, 0, .7); padding: 2px 6px; border-radius: 4px; }
.thumb .play { position: absolute; inset: 0; margin: auto; width: 38px; height: 38px; border-radius: 50%; background: rgba(0, 0, 0, .55); display: grid; place-items: center; opacity: 0; transition: opacity .15s; }
.thumb .play::after { content: ''; border-left: 12px solid #fff; border-top: 7px solid transparent; border-bottom: 7px solid transparent; margin-left: 3px; }
.card:hover .play { opacity: 1; }
.card-body { padding: 10px 12px 12px; display: grid; gap: 6px; }
.card-title { font-weight: 500; font-size: 14px; line-height: 1.3; overflow-wrap: anywhere; }
.card-title mark { background: rgba(232, 182, 76, .25); color: var(--text); border-radius: 2px; }
.card-meta { font: 12px var(--mono); color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }

.sentinel { height: 1px; }
.empty { text-align: center; color: var(--muted); padding: 60px 16px; }

/* Player */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(6, 6, 5, .82); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 24px; }
.player { position: relative; width: min(1400px, 100%); max-height: 100%; display: grid; grid-template-columns: 1fr 320px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.player-media { background: #000; display: grid; place-items: center; min-height: 300px; }
.player-media video, .player-media img { width: 100%; max-height: calc(100vh - 48px); display: block; object-fit: contain; }
.player-info { padding: 22px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.player-info h2 { margin: 0; padding-right: 28px; font-size: 17px; line-height: 1.3; overflow-wrap: anywhere; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 13px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.warning { margin: 0; font-size: 13px; color: var(--danger); }
.player-actions, .player-nav { display: flex; gap: 8px; }
.player-actions .btn, .player-nav .btn { flex: 1; }
.player-nav { margin-top: auto; }
.close { position: absolute; top: 10px; right: 12px; width: 32px; height: 32px; border: 0; border-radius: 50%; background: var(--surface-2); font-size: 20px; line-height: 1; cursor: pointer; }
.close:hover { background: var(--line); }

/* Themed modal */
.modal { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 22px; }
.modal h3 { margin: 0 0 8px; font-size: 17px; }
.modal p { margin: 0 0 18px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 860px) {
  .player { grid-template-columns: 1fr; overflow-y: auto; }
  .player-media video, .player-media img { max-height: 60vh; }
}
@media (max-width: 600px) {
  .topbar, .tags, .summary { padding-left: 16px; padding-right: 16px; }
  .grid { padding: 0 16px 16px; grid-template-columns: 1fr 1fr; gap: 10px; }
  .search kbd { display: none; }
  .overlay { padding: 0; }
  .player { border-radius: 0; height: 100%; }
}
