*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Prevent CSS display rules from overriding the HTML hidden attribute */
[hidden] { display: none !important; }

:root {
  --bg:       #fff;
  --bg2:      #f9f9f9;
  --surface:  #f2f2f2;
  --border:   #e5e5e5;
  --text:     #0f0f0f;
  --text2:    #606060;
  --accent:   #065fd4;
  --accent-h: #0356c0;
  --red:      #cc0000;
  --radius:   12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:       #0f0f0f;
    --bg2:      #1f1f1f;
    --surface:  #272727;
    --border:   #3d3d3d;
    --text:     #f1f1f1;
    --text2:    #aaaaaa;
    --accent:   #3ea6ff;
    --accent-h: #65b8ff;
    --red:      #ff4444;
  }

  .btn-primary  { color: #0f0f0f; }
  .btn-regen    { background: var(--surface); border-color: var(--border); }
}

body {
  font-family: 'Roboto', Arial, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */

header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 56px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--red);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

/* ── Layout ─────────────────────────────────────────────────────────────────── */

#app {
  max-width: 860px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}

/* ── Player ─────────────────────────────────────────────────────────────────── */

.player-wrap {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}

.player-wrap > #yt-player,
.player-wrap > #yt-player iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* ── Progress bar (viewer) ──────────────────────────────────────────────────── */

.progress-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255,255,255,0.25);
  z-index: 10;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: #ff0000;
  transition: width 0.15s linear;
}

/* ── Player toolbar (below player, viewer mode) ──────────────────────────────── */

.player-toolbar {
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}

.toolbar-progress {
  height: 3px;
  background: rgba(128, 128, 128, 0.2);
}

.toolbar-progress-fill {
  height: 100%;
  width: 0%;
  background: #ff0000;
  transition: width 0.15s linear;
}

.toolbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg2);
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.toolbar-sep { opacity: 0.4; margin: 0 2px; }

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 18px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  transition: background 0.15s;
}

.toolbar-btn:hover { background: var(--surface); }

.toolbar-icon { padding: 6px 10px; }

@keyframes mute-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255, 80, 80, 0.6); }
  60%  { box-shadow: 0 0 0 7px rgba(255, 80, 80, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 80, 80, 0); }
}

.mute-pulse {
  animation: mute-pulse 0.65s ease-out 3;
  border-color: rgba(255, 80, 80, 0.5);
}

.toolbar-btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.toolbar-btn-primary:hover { background: var(--accent-h); border-color: var(--accent-h); }

@media (prefers-color-scheme: dark) {
  .toolbar-btn-primary { color: #0f0f0f; }
}

/* ── Viewer ─────────────────────────────────────────────────────────────────── */

.viewer-card {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #606060;
  color: #fff;
  font-size: 16px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.creator-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text2);
}

.clip-title {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
}

.viewer-meta {
  display: none;
}

.clip-meta {
  font-size: 13px;
  color: var(--text2);
  margin-top: 4px;
}

.viewer-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* ── Creator ─────────────────────────────────────────────────────────────────── */

.url-section {
  margin-bottom: 28px;
}

.url-section h2 {
  font-size: 26px;
  font-weight: 600;
  margin-bottom: 8px;
}

.subtitle {
  color: var(--text2);
  margin-bottom: 20px;
  font-size: 15px;
}

/* Landing state — no video loaded yet */
.creator-landing .url-section {
  max-width: 560px;
  margin: 80px auto 0;
  text-align: center;
}

.creator-landing .url-row {
  justify-content: center;
}

.url-row {
  display: flex;
  gap: 10px;
}

.url-row input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 22px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s;
}

.url-row input:focus { border-color: var(--accent); }

.error-msg {
  color: #c00;
  font-size: 13px;
  margin-top: 8px;
}

/* ── Clip editor ─────────────────────────────────────────────────────────────── */

.clip-editor {
  margin-top: 20px;
  flex-shrink: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.editor-field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.input-wrap {
  position: relative;
}

.input-wrap input[type="text"] {
  width: 100%;
  padding: 9px 52px 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s;
}

.input-wrap input[type="text"]:focus { border-color: var(--accent); }
.input-wrap input[type="text"].error { border-color: #c00; }

.char-count {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--text2);
  pointer-events: none;
}

.slug-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.slug-display {
  flex: 1;
  font-family: 'Roboto Mono', monospace;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-regen {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text2);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}

.btn-regen:hover {
  background: var(--surface);
  color: var(--text);
}

/* ── Time display ────────────────────────────────────────────────────────────── */

.time-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.time-val {
  font-family: inherit;
  font-size: 22px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  width: 100px;
  text-align: center;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--text);
  outline: none;
  cursor: text;
  transition: border-color 0.15s, background 0.15s;
}

.time-val:focus {
  border-color: var(--accent);
  background: var(--bg);
}

.time-dash { font-size: 20px; opacity: 0.35; }

/* ── Timeline ────────────────────────────────────────────────────────────────── */

.timeline-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ticks {
  position: relative;
  height: 18px;
}

.tick {
  position: absolute;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text2);
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}

.track {
  position: relative;
  height: 60px;
  background: var(--surface);
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}

.selection {
  position: absolute;
  top: 0;
  height: 100%;
  background: var(--accent);
  cursor: grab;
  border-radius: 3px;
  opacity: 0.85;
}

.selection:active { cursor: grabbing; }

.handle {
  position: absolute;
  top: 0;
  height: 100%;
  width: 14px;
  background: var(--accent);
  cursor: ew-resize;
  transform: translateX(-50%);
  z-index: 2;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.5);
}

.grip {
  width: 2px;
  height: 18px;
  background: rgba(255,255,255,0.9);
  border-radius: 2px;
  box-shadow: 4px 0 0 rgba(255,255,255,0.9);
}

.dur-label {
  text-align: center;
  font-size: 13px;
  color: var(--text2);
}

/* ── URL output ──────────────────────────────────────────────────────────────── */

.url-out-area {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--surface);
  border-radius: 8px;
  padding: 10px 12px;
}

#url-out {
  flex: 1;
  border: none;
  background: transparent;
  font-family: 'Roboto Mono', monospace;
  font-size: 12px;
  color: var(--text);
  outline: none;
  min-width: 0;
}

/* ── Buttons ─────────────────────────────────────────────────────────────────── */

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 9px 20px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.btn-primary:hover { background: var(--accent-h); }

.btn-secondary {
  background: none;
  color: var(--accent);
  border: none;
  border-radius: 20px;
  padding: 9px 20px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.btn-secondary:hover { background: rgba(6,95,212,0.08); }

.editor-footer {
  display: flex;
}

.btn-full {
  width: 100%;
  border-radius: 8px;
  padding: 10px;
}

/* ── Comments ────────────────────────────────────────────────────────────────── */

.comments-section {
  margin-top: 20px;
}

.comments-heading {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

.comments-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 14px;
}

.comments-empty {
  font-size: 13px;
  color: var(--text2);
}

.comment {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.comment-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.comment-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.comment-time {
  font-size: 11px;
  color: var(--text2);
}

.comment-body {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.comment-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.comment-form textarea {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
}

.comment-form textarea:focus { border-color: var(--accent); }

/* ── Desktop two-column layouts ──────────────────────────────────────────────── */

@media (min-width: 740px) {
  #app { max-width: 1100px; }

  /* Creator */
  #editor {
    display: flex;
    gap: 24px;
    align-items: flex-start;
  }

  #editor .player-wrap {
    flex: 1;
    min-width: 0;
  }

  #editor .clip-editor {
    width: 360px;
    margin-top: 0;
  }

  /* Viewer */
  .viewer {
    display: flex;
    gap: 24px;
    align-items: flex-start;
  }

  .viewer-left {
    flex: 1;
    min-width: 0;
  }

  .viewer-right {
    width: 320px;
    flex-shrink: 0;
  }

  .viewer-card {
    margin-top: 0;
  }
}
