/*
 * LabelTool frontend styles. Colors are custom properties with a dark variant;
 * html[data-theme] forces light/dark, no attribute = follow the system.
 * [AI CODE - Claude Code claude-opus-5-5]
 */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #dfe2e7;
  --border-strong: #c3c8d0;
  --text: #1d2025;
  --muted: #646b77;
  --accent: #2f6fde;
  --accent-hover: #255fc4;
  --accent-text: #ffffff;
  --accent-soft: #e5eefc;
  --track: #e2e5ea;
  --warn-bg: #fdf6dc;
  --warn-border: #ecdca0;
  --warn-text: #7d5b00;
  --ok-bg: #eaf6ee;
  --ok-border: #bfe2cb;
  --ok-text: #23784a;
  --err: #c0392b;
  --err-bg: #fdeceb;
  --err-border: #f0b9b3;
  --info-bg: #eef3fc;
  --info-border: #c8d8f4;
  --kbd-bg: #f1f3f5;
  --backdrop: rgba(20, 24, 31, 0.32);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-lg: -8px 0 24px rgba(16, 24, 40, 0.14);
  --focus: 0 0 0 3px rgba(47, 111, 222, 0.38);
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171c;
    --surface: #1f2228;
    --surface-2: #252931;
    --border: #343944;
    --border-strong: #4a505d;
    --text: #e6e8ec;
    --muted: #9aa1ad;
    --accent: #6d9ef2;
    --accent-hover: #86b0f6;
    --accent-text: #0e1522;
    --accent-soft: #233552;
    --track: #383e4a;
    --warn-bg: #2c2716;
    --warn-border: #5a4b1d;
    --warn-text: #e8c76a;
    --ok-bg: #18301f;
    --ok-border: #2f5b3c;
    --ok-text: #79d29a;
    --err: #f08a80;
    --err-bg: #3a1f1d;
    --err-border: #6d3530;
    --info-bg: #1d2a40;
    --info-border: #2f4466;
    --kbd-bg: #2a2e37;
    --backdrop: rgba(0, 0, 0, 0.5);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-lg: -8px 0 24px rgba(0, 0, 0, 0.45);
    --focus: 0 0 0 3px rgba(109, 158, 242, 0.5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #15171c;
  --surface: #1f2228;
  --surface-2: #252931;
  --border: #343944;
  --border-strong: #4a505d;
  --text: #e6e8ec;
  --muted: #9aa1ad;
  --accent: #6d9ef2;
  --accent-hover: #86b0f6;
  --accent-text: #0e1522;
  --accent-soft: #233552;
  --track: #383e4a;
  --warn-bg: #2c2716;
  --warn-border: #5a4b1d;
  --warn-text: #e8c76a;
  --ok-bg: #18301f;
  --ok-border: #2f5b3c;
  --ok-text: #79d29a;
  --err: #f08a80;
  --err-bg: #3a1f1d;
  --err-border: #6d3530;
  --info-bg: #1d2a40;
  --info-border: #2f4466;
  --kbd-bg: #2a2e37;
  --backdrop: rgba(0, 0, 0, 0.5);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: -8px 0 24px rgba(0, 0, 0, 0.45);
  --focus: 0 0 0 3px rgba(109, 158, 242, 0.5);
  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus); }

h1, h2, h3 { line-height: 1.25; margin: 0; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  min-height: 40px;
  padding: 0.45em 1.1em;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--border-strong); color: var(--text); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-text); }
.btn-block { width: 100%; }
.btn-small { min-height: 32px; padding: 0.25em 0.8em; font-size: 0.9em; }

.link-btn {
  background: none; border: 0; padding: 0;
  color: var(--accent); font: inherit; font-weight: 650;
  cursor: pointer; text-decoration: none;
}
.link-btn:hover { color: var(--accent-hover); }

/* ---------- switchers ---------- */

.switchers { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  padding: 2px;
  gap: 2px;
}
.seg button {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  min-width: 30px;
  height: 26px;
  padding: 0 6px;
  border-radius: 4px;
  cursor: pointer;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

/* ---------- page shells ---------- */

.floating-bar { display: flex; justify-content: flex-end; padding: 10px 16px 0; }

.card-page { padding: 24px 16px 48px; display: flex; justify-content: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.narrow-card { width: 100%; max-width: 480px; padding: 28px 32px 24px; }
.wide-card { width: 100%; max-width: 560px; padding: 28px 32px 32px; }

.brand { color: var(--accent); font-weight: 700; font-size: 13px; margin-bottom: 14px; }
.card h1 { font-size: 21px; margin-bottom: 10px; }
.lead { color: var(--muted); margin: 0 0 20px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px 16px;
  flex-wrap: wrap;
  padding: 8px 24px;
  min-height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .brand-link { font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none; margin-right: auto; }
.topbar .who { color: var(--muted); font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.topbar .who::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }

.page { max-width: 868px; margin: 0 auto; padding: 24px 24px 48px; }
.page > h1 { font-size: 22px; margin: 4px 0 16px; }

.loading { padding: 48px 16px; text-align: center; color: var(--muted); }

/* ---------- forms ---------- */

.field-label { display: block; font-weight: 700; font-size: 14px; margin-bottom: 6px; }

.input, .textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}
.input { min-height: 40px; }
.input:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus-visible, .textarea:focus-visible, .input:focus, .textarea:focus { border-color: var(--accent); box-shadow: var(--focus); }
.textarea { resize: vertical; display: block; line-height: 1.45; }
.textarea.autogrow { resize: none; overflow: hidden; min-height: 40px; }
.textarea.mono { font-family: var(--mono); font-size: 14px; }
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: 0.8; }
[aria-invalid="true"].input, [aria-invalid="true"].textarea { border-color: var(--err); }

.small-note { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.error-text { color: var(--err); font-weight: 700; font-size: 13px; margin: 6px 0 0; }
.join-form .btn-block { margin-top: 18px; }
.join-foot { font-size: 13px; color: var(--muted); margin: 20px 0 0; }

/* ---------- personal link ---------- */

.link-box {
  display: flex; gap: 8px; align-items: center;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 7px;
  padding: 5px 5px 5px 12px;
  margin: 4px 0 14px;
}
.link-box input {
  flex: 1; min-width: 0;
  border: 0; background: transparent; color: var(--text);
  font-family: var(--mono); font-weight: 700; font-size: 14px;
  padding: 6px 0;
  text-overflow: ellipsis;
}
.link-box input:focus-visible { box-shadow: none; outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.warn-line { color: var(--warn-text); font-weight: 700; font-size: 14px; margin: 0 0 24px; }
.copy-status { font-size: 13px; color: var(--muted); min-height: 1.3em; margin: -8px 0 10px; }

/* ---------- task list ---------- */

.task-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.task-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 200px auto;
  align-items: center;
  gap: 12px 32px;
  padding: 18px 20px;
}
.task-item h2 { font-size: 16px; margin-bottom: 4px; }
.task-item h2 a { color: var(--text); text-decoration: none; }
.task-item h2 a:hover { text-decoration: underline; }
.task-sub { color: var(--muted); font-size: 14px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-sub p, .task-sub ul { display: inline; margin: 0; }
.task-item .btn { min-width: 110px; }
.list-foot { color: var(--muted); font-size: 13px; margin-top: 16px; }

.progress { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.bar { height: 8px; background: var(--track); border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.finished { color: var(--ok-text); font-weight: 700; }

/* ---------- instructions page ---------- */

.back-link { font-weight: 700; text-decoration: none; display: inline-block; margin-bottom: 8px; }
.inline-progress { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.inline-progress .bar { width: 200px; }
.instr-card { padding: 18px 24px 22px; }
.instr-card h2 { font-size: 17px; margin-bottom: 12px; }
.start-row { display: flex; align-items: center; gap: 16px 20px; flex-wrap: wrap; margin-top: 20px; }
.start-row .btn { min-width: 220px; }
.start-row p { margin: 0; color: var(--muted); font-size: 13px; }

/* ---------- markdown ---------- */

.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 0.9em; }
.md ul, .md ol { margin: 0 0 0.9em; padding-left: 1.4em; }
.md li { margin: 0.1em 0; }
.md code { font-family: var(--mono); font-size: 0.92em; background: var(--kbd-bg); border-radius: 4px; padding: 0.05em 0.3em; }
.md h3 { font-size: 1em; margin: 0 0 0.4em; }

/* ---------- label view ---------- */

.label-bar { padding: 8px 20px; position: sticky; top: 0; z-index: 25; }
.label-bar .left { display: flex; align-items: center; gap: 8px 24px; min-width: 0; flex: 1 1 260px; }
.label-bar .back-link { white-space: nowrap; flex: 0 0 auto; }
.label-bar .task-title { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.label-bar .counter { display: grid; gap: 4px; font-size: 13px; color: var(--muted); flex: 0 0 auto; min-width: 140px; }
.label-bar .counter .bar { height: 6px; width: 130px; }
.label-bar .right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin-left: auto; }
.label-bar .btn { min-height: 32px; padding: 0.25em 0.75em; font-size: 14px; }
.label-bar .btn[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.label-main { max-width: 868px; margin: 0 auto; padding: 18px 24px 40px; transition: margin 0.15s ease; }
@media (min-width: 1240px) {
  .with-sidebar .label-main { margin-right: 400px; margin-left: max(0px, calc((100vw - 400px - 868px) / 2)); }
}

.banner {
  border-radius: 7px; padding: 9px 14px; margin-bottom: 14px;
  font-weight: 700; font-size: 14px;
}
.banner-ok { background: var(--ok-bg); border: 1px solid var(--ok-border); color: var(--ok-text); }
.banner-warn { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-text); }
.banner-err { background: var(--err-bg); border: 1px solid var(--err-border); color: var(--err); }
.banner-err ul { margin: 4px 0 0; padding-left: 1.2em; font-weight: 400; }

.player { display: flex; align-items: center; gap: 18px; padding: 18px 16px 18px 20px; margin-bottom: 14px; }
.play-btn {
  flex: 0 0 auto;
  width: 46px; height: 46px; border-radius: 50%;
  border: 0; background: var(--accent); color: var(--accent-text);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.play-btn:hover { background: var(--accent-hover); }
.play-btn svg { width: 20px; height: 20px; fill: currentColor; }
.player .track { flex: 1; min-width: 0; display: grid; gap: 6px; }
.player .time { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.player .skip-btns { display: flex; gap: 6px; flex: 0 0 auto; }
.player .skip-btns .btn { min-height: 32px; padding: 0.2em 0.65em; font-size: 14px; }
.player .audio-error { color: var(--err); font-size: 13px; font-weight: 700; }

.seek {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 20px; background: transparent; margin: 0; cursor: pointer;
  --pct: 0%;
}
.seek::-webkit-slider-runnable-track {
  height: 8px; border-radius: 4px;
  background: linear-gradient(to right, var(--accent) var(--pct), var(--track) var(--pct));
}
.seek::-moz-range-track { height: 8px; border-radius: 4px; background: var(--track); }
.seek::-moz-range-progress { height: 8px; border-radius: 4px; background: var(--accent); }
.seek::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%; margin-top: -4px;
  background: var(--surface); border: 2px solid var(--accent);
}
.seek::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.seek:focus-visible { box-shadow: none; }
.seek:focus-visible::-webkit-slider-thumb { box-shadow: var(--focus); }
.seek:focus-visible::-moz-range-thumb { box-shadow: var(--focus); }

.orig-box {
  background: var(--warn-bg); border: 1px solid var(--warn-border);
  border-radius: 7px; padding: 8px 14px 10px; margin-bottom: 14px;
}
.orig-box .cap { font-size: 12px; font-weight: 700; color: var(--warn-text); margin-bottom: 2px; }
.orig-box .txt { white-space: pre-wrap; overflow-wrap: anywhere; }

.hint-box {
  background: var(--info-bg); border: 1px solid var(--info-border);
  border-radius: 7px; padding: 8px 14px 10px; margin-bottom: 14px;
}
.hint-box .cap { font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }

.lfield { margin: 0 0 18px; padding: 0; border: 0; min-width: 0; }
.lfield > legend, .lfield > .lhead { padding: 0; margin-bottom: 8px; font-weight: 700; display: block; width: 100%; }
.lhead label { font-weight: 700; }
.req { color: var(--err); margin-left: 4px; }
.help-inline { font-weight: 400; font-size: 13px; color: var(--muted); margin-left: 10px; }
.help-block { font-weight: 400; font-size: 13px; color: var(--muted); margin: -2px 0 8px; }
.help-inline p, .help-inline ul { display: inline; margin: 0; }

.options { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 28px; }
.options.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px 24px; }
.opt { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; min-height: 30px; }
.opt input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: pointer; flex: 0 0 auto; }
.opt input:focus-visible { box-shadow: var(--focus); border-radius: 3px; }
.opt-keys { display: inline-flex; gap: 4px; }

kbd, .kbd {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 4px 6px;
  min-width: 20px;
  text-align: center;
  color: var(--muted);
  background: var(--kbd-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.field-error { color: var(--err); font-size: 13px; font-weight: 700; margin: 6px 0 0; }

.actions {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  border-top: 1px solid var(--border);
  padding-top: 16px; margin-top: 6px;
}
.actions .spacer { flex: 1; }
.actions .btn { min-width: 84px; }
.actions .btn-primary { min-width: 160px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

/* ---------- sidebar ---------- */

.sidebar {
  position: fixed; top: var(--bar-h, 0px); right: 0; bottom: 0;
  width: min(400px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 20;
  display: flex; flex-direction: column;
}
.sidebar[hidden] { display: none; }
.sidebar .sb-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 8px 24px; }
.sidebar h2 { font-size: 18px; }
.sidebar .sb-body { padding: 4px 24px 24px; overflow-y: auto; }
.icon-btn {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  width: 34px; height: 34px; border-radius: 6px; font-size: 22px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.backdrop { position: fixed; inset: var(--bar-h, 0px) 0 0 0; background: var(--backdrop); z-index: 15; }
.backdrop[hidden] { display: none; }

@media (min-width: 1240px) {
  .backdrop { display: none; }
}

/* ---------- done page ---------- */

.done-card { text-align: center; padding: 28px 32px 28px; }
.done-icon {
  width: 46px; height: 46px; border-radius: 50%; margin: 0 auto 12px;
  background: var(--ok-bg); border: 1px solid var(--ok-border); color: var(--ok-text);
  display: flex; align-items: center; justify-content: center;
}
.done-icon svg { width: 24px; height: 24px; }
.done-card h1 { margin-bottom: 8px; }
.done-card p { margin: 0; color: var(--muted); }
.done-btns { display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.done-btns .btn { min-width: 170px; }

/* ---------- responsive ---------- */

@media (max-width: 760px) {
  .topbar { padding: 8px 16px; }
  .page { padding: 18px 16px 40px; }
  .label-main { padding: 14px 16px 32px; }
  .narrow-card, .wide-card { padding: 22px 18px 20px; }
  .task-item { grid-template-columns: 1fr; gap: 12px; padding: 16px; }
  .task-item .btn { width: 100%; }
  .task-sub { white-space: normal; }
  .label-bar { padding: 8px 12px; position: static; }
  .sidebar { top: 0; z-index: 30; }
  .backdrop { inset: 0; z-index: 28; }
  .label-bar .left { flex-basis: 100%; gap: 12px; }
  .label-bar .counter { min-width: 0; }
  .label-bar .counter .bar { width: 100px; }
  .player { flex-wrap: wrap; gap: 12px 14px; padding: 14px; }
  .player .track { flex-basis: calc(100% - 64px); }
  .player .skip-btns { margin-left: 60px; }
  .actions .spacer { display: none; }
  .actions .btn-primary { order: -1; flex-basis: 100%; }
  .actions .btn:not(.btn-primary) { flex: 1; }
  .legend { display: none; }
  .opt-keys { display: none; }
  .inline-progress .bar { width: 120px; }
  .start-row .btn { width: 100%; }
}

@media (hover: none) {
  .legend, .opt-keys { display: none; }
}
