:root {
  --bg: #0a0a0b;
  --panel: #111113;
  --fg: #e9e9ec;
  --muted: #8a8a93;
  --line: #222227;
  --line-strong: #34343b;
  --ok: #5fd08a;
  --warn: #e0b85a;
  --off: #5a5a62;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

button, select, input {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px 12px;
  min-height: 36px;
}

button { cursor: pointer; }
button:hover:not(:disabled), select:hover { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
select { background: var(--panel); }
select option { background: var(--panel); }

.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.primary:hover:not(:disabled) { background: #fff; border-color: #fff; }

.word {
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: 15px;
}

.note { color: var(--muted); font-size: 13px; margin: 0; min-height: 1.4em; }

/* gate */

#gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.gate {
  width: min(320px, 100%);
  display: grid;
  gap: 12px;
}

.gate h1 { margin: 0 0 8px; font-size: 22px; }
.gate input { width: 100%; padding: 12px 14px; }

/* library */

#library {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 24px 48px;
}

.bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 20px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--off);
}

.status[data-state="online"] i { background: var(--ok); }
.status[data-state="connecting"] i { background: var(--warn); }

.actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.settings {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  padding: 14px 16px;
  margin-bottom: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.settings label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.settings #forget { margin-left: auto; }

input[type="range"] {
  width: 140px;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--fg);
}

.volume {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.volume output, .settings output {
  min-width: 3.2em;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

#lib-note { margin-bottom: 16px; }

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

.tile {
  all: unset;
  display: grid;
  gap: 8px;
  cursor: pointer;
  min-width: 0;
}

.tile .art {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  transition: transform .15s ease, border-color .15s ease;
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tile .fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.tile .name {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile:hover .art, .tile:focus-visible .art { transform: translateY(-2px); border-color: var(--muted); }
.tile:hover .name, .tile:focus-visible .name { color: var(--fg); }
.tile[data-ready="false"] .art { opacity: .55; }
.grid[data-offline="true"] .tile { opacity: .4; pointer-events: none; }

/* stage */

#stage {
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
  cursor: default;
  touch-action: none;
  user-select: none;
}

#stage video, #stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

#stage[data-captured="true"][data-local-cursor="false"],
#stage[data-captured="true"][data-local-cursor="false"] video,
#stage[data-captured="true"][data-local-cursor="false"] canvas { cursor: none; }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(6px);
}

.panel {
  width: min(560px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  border-radius: 14px;
  background: rgba(17, 17, 19, .92);
  border: 1px solid var(--line);
}

.now { font-weight: 600; font-size: 16px; }
.msg { color: var(--muted); min-height: 1.4em; }
.stats { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; min-height: 1.4em; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.row.keys button { font-size: 12px; padding: 6px 10px; min-height: 30px; color: var(--muted); }
.hint { margin: 0; color: var(--off); font-size: 12px; }

.pill {
  position: absolute;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(17, 17, 19, .85);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}

@media (max-width: 560px) {
  #library { padding: 16px 16px 40px; }
  .actions { margin-left: 0; width: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 16px 12px; }
  .settings #forget { margin-left: 0; }
}
