/* Shared components. Targets are at least 48 px (56 on touch); motion stays under 150 ms. */

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: var(--tap); padding: .4em 1.1em;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line-2); border-radius: var(--radius-s);
  font-weight: 550; line-height: 1.3; text-decoration: none;
  transition: background var(--ease), border-color var(--ease), transform var(--ease);
  user-select: none; -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.08); background: var(--primary); }
.btn.danger { color: var(--err); border-color: var(--err); }
.btn.primary.danger { background: var(--err); color: var(--on-err); }
.btn.on, .btn[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.btn.primary.on, .btn.primary[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); }
.btn.small { min-height: 40px; padding: .2em .8em; font-size: .92em; }
.btn.block { display: flex; width: 100%; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn .kbd { margin-left: .1em; }

/* key cap hint */
.kbd {
  display: inline-block; min-width: 1.6em; padding: 0 .4em; margin-left: .3em;
  font: 600 .78em/1.7 var(--mono); text-align: center; letter-spacing: 0;
  color: var(--text-2); background: var(--surface-2);
  border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 5px;
}
.btn.primary .kbd { color: var(--primary-ink); background: rgba(255, 255, 255, .18); border-color: rgba(255, 255, 255, .45); }
@media (pointer: coarse) { .kbd { display: none; } }

/* segmented control */
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--radius-s); overflow: hidden; background: var(--surface); }
.seg-b, .seg > button {
  min-height: var(--tap); padding: .3em 1em; background: transparent; border: 0; border-left: 1px solid var(--line);
  font-weight: 550; transition: background var(--ease);
}
.seg-b:first-child, .seg > button:first-child { border-left: 0; }
.seg-b:hover, .seg > button:hover { background: var(--surface-2); }
.seg-b[aria-pressed="true"], .seg > button[aria-pressed="true"], .seg > button.on { background: var(--primary); color: var(--primary-ink); }

/* big option: a whole-row answer with a key cap on the left */
.opts { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  min-height: max(var(--tap), 3rem); padding: .6em 1em;
  background: var(--surface); border: 2px solid var(--line-2); border-radius: var(--radius);
  transition: background var(--ease), border-color var(--ease);
}
.opt:hover { border-color: var(--text-2); background: var(--surface-2); }
.opt .key {
  flex: none; display: inline-grid; place-items: center; width: 2em; height: 2em;
  font: 700 .95em var(--mono); color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 6px;
}
.opt .lab { flex: 1 1 auto; font-weight: 600; }
.opt .sub { display: block; font-weight: 400; font-size: .9em; color: var(--text-2); }
.opt[aria-pressed="true"], .opt[aria-checked="true"], .opt.on { border-color: var(--primary); background: var(--primary-soft); }
.opt[aria-pressed="true"] .key, .opt[aria-checked="true"] .key, .opt.on .key { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
@media (max-width: 900px), (pointer: coarse) { .opt { min-height: 56px; } }

/* chip, pill */
.chip { display: inline-flex; align-items: center; gap: .35em; min-height: 32px; padding: .1em .75em; font-size: .9em; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; }
button.chip { cursor: pointer; }
.chip[aria-pressed="true"], .chip.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.pill { display: inline-block; padding: 0 .65em; font-size: .85em; font-weight: 600; line-height: 1.7; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.err { background: var(--err-soft); color: var(--err); }
.pill.info { background: var(--primary-soft); color: var(--primary); }

/* card */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

/* progress */
.progress { position: relative; display: inline-block; vertical-align: middle; width: 120px; height: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.progress > .bar { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--primary); border-radius: 999px; transition: width var(--ease); }
.progress.ok > .bar { background: var(--ok); }
.progress.block { display: block; width: 100%; }

/* toasts and banners */
.toasts { position: fixed; z-index: 90; left: 50%; bottom: calc(var(--submit-h) + 24px); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; width: max-content; max-width: calc(100vw - 32px); pointer-events: none; }
.toast { padding: .65em 1.1em; background: var(--text); color: var(--bg); border-radius: var(--radius-s); box-shadow: var(--shadow); font-weight: 550; animation: pop 120ms ease-out; }
.toast.ok { background: var(--ok); color: var(--on-ok); }
.toast.warn { background: var(--warn); color: var(--on-warn); }
.toast.err { background: var(--err); color: var(--on-err); }
.toast.out { opacity: 0; transition: opacity 150ms; }
.banners { position: fixed; z-index: 80; top: calc(var(--topbar-h, 56px) + 8px); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; width: min(720px, calc(100vw - 24px)); pointer-events: none; }
.banner { display: flex; align-items: center; gap: 12px; padding: .6em .9em; pointer-events: auto; background: var(--primary-soft); color: var(--text); border: 1px solid var(--primary); border-radius: var(--radius-s); box-shadow: var(--shadow); }
.banner.ok { background: var(--ok-soft); border-color: var(--ok); }
.banner.warn { background: var(--warn-soft); border-color: var(--warn); }
.banner.err { background: var(--err-soft); border-color: var(--err); }
.banner-msg { flex: 1 1 auto; }
.banner .btn { white-space: nowrap; flex: none; }   /* a narrow banner wraps its button onto its own line, it never breaks 重试 into two lines */
@media (max-width: 900px) { .banner.err { flex-wrap: wrap; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* modal and dialog */
.modal-back { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 16px; background: rgba(20, 24, 32, .5); overflow: auto; animation: fade 120ms ease-out; }
.modal { position: relative; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 22px 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.modal-x { position: absolute; top: 8px; right: 8px; width: var(--tap); height: var(--tap); background: transparent; border: 0; border-radius: var(--radius-s); font-size: 1.1rem; color: var(--text-2); }
.modal-x:hover { background: var(--surface-2); }
.dialog h2, .dialog h3 { margin-top: 0; padding-right: 2em; }
.dialog-body { color: var(--text-2); margin-bottom: 1em; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* playback bar: sticks under the top bar so the controls never scroll away */
.transport { position: sticky; top: var(--sticky-top, 0); z-index: 20; padding: 8px 0; background: var(--bg); }
.transport.flat { position: static; }
.tp-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.tp-play { min-width: 8.5em; font-size: 1.05em; }
.tp-ch { display: inline-flex; align-items: center; gap: 8px; }
.tp-lab { color: var(--text-2); font-size: .9em; }
.tp-time { font-variant-numeric: tabular-nums; color: var(--text-2); min-width: 7.5em; text-align: right; }
.tp-need { display: inline-flex; align-items: center; gap: 8px; font-size: .92em; }
.tp-covtxt { font-variant-numeric: tabular-nums; }
.tp-blocked { display: flex; width: 100%; margin-bottom: 8px; min-height: 64px; font-size: 1.15em; }
@media (max-width: 900px) {
  .tp-bar { gap: 6px; padding: 6px; }
  .tp-time { text-align: left; }
}

/* timeline canvases */
.tl { position: relative; width: 100%; user-select: none; -webkit-user-select: none; }
.tl canvas { display: block; }
.tl-box { position: relative; width: 100%; touch-action: pan-y; }
.tl-over { position: absolute; inset: 0; }
.tl-ov { width: 100%; margin-bottom: 6px; cursor: pointer; }

/* gentle rest card */
.rest-card { position: fixed; z-index: 60; right: 16px; bottom: calc(var(--submit-h) + 16px); width: min(340px, calc(100vw - 32px)); padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--ok); border-radius: var(--radius); box-shadow: var(--shadow); animation: pop 150ms ease-out; }
.rest-card p { margin: 0 0 10px; }
