:root {
  --bg: #0f1217;
  --surface: #181c24;
  --surface-2: #212733;
  --border: #2d3443;
  --text: #e8ebf2;
  --muted: #8b94a7;
  --accent: #6ea8fe;
  --accent-strong: #3d7bf0;
  --ok: #3ecf8e;
  --danger: #ff6b6b;
  --warn: #ffd43b;
  --radius: 12px;
  --shadow: 0 8px 24px rgb(0 0 0 / .35);
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh;
  font: 15px/1.5 Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* Header */
header {
  position: sticky; top: 0; z-index: 10;
  display: flex; gap: 1rem; align-items: center; padding: .75rem 1.5rem;
  background: rgb(24 28 36 / .85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
header strong { font-size: 1.05rem; letter-spacing: .01em; }
header strong::before { content: '●'; color: var(--accent); margin-right: .5rem; font-size: .8em; }
#who {
  padding: .15rem .65rem; border-radius: 999px; font-size: .85rem;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
#who:empty { display: none; }
#counter { margin-left: auto; color: var(--muted); font-size: .88rem; }

section { max-width: 1100px; margin: 1.5rem auto; padding: 0 1.5rem; }
#message {
  text-align: center; font-size: 1.15rem; padding: 3rem 1.5rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
#message[hidden], #workspace[hidden] { display: none; }

/* Workspace */
#workspace { display: flex; flex-direction: column; gap: 1rem; }
video {
  display: block; width: 100%; max-height: 60vh; background: #000; cursor: pointer;
  border-radius: var(--radius); box-shadow: var(--shadow);
}
#controls, #labels, #eyesides { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin: 0; }
#controls {
  gap: .675rem; padding: .54rem .81rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--muted); font-size: .81rem;
}
#controls button { padding: .4rem .9rem; }
/* Speed: one button-styled group "Speed − 1× +" matching the action row buttons */
#speed-control {
  display: inline-flex; align-items: center; overflow: hidden; padding-left: .9rem;
  font-weight: 500; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
}
#speed-control #speed {
  align-self: stretch; display: grid; place-items: center; min-width: 3.4em;
  border-left: 1px solid var(--border); font-variant-numeric: tabular-nums;
}
#speed-control button {
  align-self: stretch; padding: .4rem .675rem; border: 0; border-radius: 0;
  border-left: 1px solid var(--border); background: transparent;
}
#speed-control button:hover:not(:disabled) { background: #2b3243; }
#speed-control button:focus-visible { outline-offset: -2px; }

#stage { position: relative; }
#time {
  position: absolute; right: .75rem; bottom: .75rem; pointer-events: none;
  padding: .15rem .55rem; border-radius: 6px; background: rgb(0 0 0 / .6); color: #fff;
  font-size: .85rem; font-variant-numeric: tabular-nums;
}

/* Timeline */
#timeline {
  position: relative; height: 72px; background: var(--surface-2); cursor: pointer; user-select: none;
  border: 1px solid var(--border); border-radius: 10px; touch-action: none;
}
#segments { position: absolute; inset: 0; border-radius: 9px; overflow: hidden; }
/* A segment has two lanes: .seg-structure on top, .seg-eyeside below. */
.segment {
  position: absolute; top: 0; bottom: 0; overflow: hidden; display: flex; flex-direction: column;
  border-right: 2px solid var(--bg); color: #fff; font-size: 12px; font-weight: 600;
  text-shadow: 0 1px 2px rgb(0 0 0 / .6); transition: filter .15s;
}
.segment:hover { filter: brightness(1.12); }
.segment:last-child { border-right: none; }
/* Both lanes are 35px tall (the timeline's 70px inner height) */
.seg-structure, .seg-eyeside {
  flex: none; height: 35px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  padding: 0 8px; line-height: 35px;
}
.unlabeled {
  background: repeating-linear-gradient(45deg, #3a4254 0 8px, #2f3646 8px 16px);
  color: var(--muted); text-shadow: none;
}
.eye-OD { background: #2b6cb0; }
.eye-OS { background: #d69e2e; color: #1a1a1a; text-shadow: none; }
.swatch.eye-OS { background: #d69e2e; }
.eye-unclear { background: #718096; }
.segment.current::after { content: ''; position: absolute; inset: 0; box-shadow: inset 0 0 0 3px var(--warn); pointer-events: none; }

.seg-eyeside { border-top: 2px solid var(--bg); line-height: 33px; }
.swatch.eye-OD, .swatch.eye-OS, .swatch.eye-unclear { border-radius: 3px; }
#cuts { position: absolute; inset: 0; pointer-events: none; }
.cut {
  position: absolute; top: -4px; bottom: -4px; width: 18px; margin-left: -9px;
  cursor: ew-resize; pointer-events: auto; touch-action: none;
}
.cut::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: 6px; width: 6px; border-radius: 3px;
  background: #fff; border: 1px solid var(--bg); box-shadow: 0 0 0 1px rgb(0 0 0 / .4);
  transition: background .15s, box-shadow .15s;
}
.cut:hover::before { background: var(--accent); }
.cut.selected::before { background: var(--warn); box-shadow: 0 0 0 2px var(--warn), 0 0 10px rgb(255 212 59 / .8); }
#playhead {
  position: absolute; top: -6px; bottom: -6px; width: 3px; margin-left: -1px; border-radius: 2px;
  background: var(--danger); box-shadow: 0 0 8px rgb(255 107 107 / .8); pointer-events: none;
}
#playhead::before {
  content: ''; position: absolute; top: 0; left: -4px; width: 11px; height: 11px;
  border-radius: 50%; background: var(--danger);
}

/* Buttons */
button {
  font: inherit; font-weight: 500; padding: .45rem 1rem; cursor: pointer; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  transition: background .15s, border-color .15s, transform .05s;
}
button:hover:not(:disabled) { background: #2b3243; border-color: #3f485c; }
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .45; cursor: not-allowed; }
#play { min-width: 5rem; background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
#play:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
#loop[aria-pressed="true"] { background: rgb(110 168 254 / .18); border-color: var(--accent); color: var(--accent); }
#submit {
  margin-left: auto; padding: .5rem 1.45rem; font-weight: 700;
  background: var(--ok); border-color: var(--ok); color: #06281a;
}
#submit:hover:not(:disabled) { background: #5ee0a5; border-color: #5ee0a5; }

#labels, #eyesides { gap: .35rem; }
.label-btn.eyeside-btn { border-radius: 6px; }
.label-btn {
  display: inline-flex; align-items: center; gap: .3rem; border-width: 1px; border-radius: 999px;
  padding: .15rem .55rem; font-size: .8rem;
}
.label-gap { margin-left: 1.25rem; }
.label-btn.active { border-color: var(--text); box-shadow: 0 0 0 1px var(--text); background: #2f3748; font-weight: 700; }
.label-btn kbd { font-size: .75em; padding: 0 .3em; }
.swatch { display: inline-block; width: .7em; height: .7em; border-radius: 50%; }
kbd {
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 0 .4em;
  background: var(--bg); color: var(--text); font: .85em ui-monospace, Consolas, monospace;
}

/* Help */
#help { padding: 0; width: 2rem; height: 2rem; border-radius: 50%; font-size: 1.1rem; line-height: 1; color: var(--muted); }
#help:hover { color: var(--text); }
dialog {
  width: min(560px, calc(100vw - 2rem)); padding: 1.25rem 1.5rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(0 0 0 / .6); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 .5rem; font-size: 1.15rem; }
dialog ol { padding-left: 1.3rem; line-height: 1.6; color: var(--muted); }
dialog li { margin-bottom: .45rem; }
dialog strong { color: var(--text); }
dialog h3 { margin: 1.1rem 0 .4rem; font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
dialog p { color: var(--muted); }
.shortcuts { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; font-size: .88rem; margin: 0 0 1rem; }
dialog form { text-align: right; }

@media (max-width: 600px) {
  header, section { padding-left: .75rem; padding-right: .75rem; }
  #counter { display: none; }
  #help { margin-left: auto; }
}

/* Admin page */
body.admin section { max-width: 800px; }
body.admin h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }
#bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
#bar-finished { background: var(--ok); }
#bar-progress { background: var(--warn); }
#add-form { display: flex; gap: .5rem; margin-bottom: .75rem; }
#link-box input { width: 100%; }
#users { width: 100%; border-collapse: collapse; margin-top: .75rem; }
#users th, #users td { text-align: left; padding: .4rem .6rem; border-bottom: 1px solid var(--border); }
#users td:last-child { text-align: right; white-space: nowrap; }
#error { color: var(--danger); }
