/* Small component layer on top of Tailwind (CDN build has no @apply, so plain CSS). */
:root {
  --accent: #4f46e5;
  --accent-soft: #e0e7ff;
  --line: #e2e8f0;
  --panel: #ffffff;
  --muted: #64748b;
  --chip: #f1f5f9;
  --chip-hover: #e2e8f0;
  --text: #0f172a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #818cf8;
    --accent-soft: rgba(129, 140, 248, .15);
    --line: #1e293b;
    --panel: #0f172a;
    --muted: #94a3b8;
    --chip: #1e293b;
    --chip-hover: #334155;
    --text: #f1f5f9;
  }
}

html { -webkit-tap-highlight-color: transparent; }
button { -webkit-user-select: none; user-select: none; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 2.25rem; width: 2.25rem; border-radius: .75rem;
  color: inherit; transition: background-color .15s, transform .1s;
}
.icon-btn:hover { background: var(--chip); }
.icon-btn:active { transform: scale(.94); }
.icon-btn:disabled { opacity: .35; pointer-events: none; }

.chip {
  height: 2rem; padding: 0 .85rem; border-radius: 999px; font-size: .8125rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: .35rem;
  background: var(--chip); color: var(--muted); transition: all .15s;
}
.chip::before {
  content: ''; width: .5rem; height: .5rem; border-radius: 999px; background: currentColor; opacity: .5;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.chip[aria-pressed="true"]::before { opacity: 1; }
.chip[aria-pressed="false"] { text-decoration: line-through; }

.seg { display: flex; gap: .25rem; padding: .25rem; border-radius: .9rem; background: var(--chip); }
.seg > button {
  flex: 1; height: 2.25rem; border-radius: .7rem; font-size: .875rem; font-weight: 600; color: var(--muted);
  transition: all .15s;
}
.seg > button[aria-pressed="true"] { background: var(--panel); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.preset {
  height: 2.25rem; border-radius: .7rem; font-size: .8125rem; font-weight: 600; background: var(--chip); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.preset[aria-pressed="true"] { background: var(--accent); color: #fff; }

.btn-primary, .btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; height: 2.75rem; padding: 0 1rem;
  border-radius: .85rem; font-size: .875rem; font-weight: 600; transition: all .15s;
}
.btn-primary { background: #4f46e5; color: #fff; }
.btn-primary:hover { background: #6366f1; }
.btn-secondary { background: var(--chip); }
.btn-secondary:hover { background: var(--chip-hover); }
.btn-primary:active, .btn-secondary:active { transform: scale(.98); }

.field {
  width: 100%; border-radius: .85rem; border: 1px solid var(--line); background: var(--panel);
  padding: .65rem .8rem; font-size: 1rem; line-height: 1.5; outline: none; resize: vertical;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.menu-item {
  display: flex; align-items: center; width: 100%; text-align: left; height: 3rem; padding: 0 1rem;
  border-radius: .85rem; font-size: .9375rem; font-weight: 500;
}
.menu-item:hover { background: var(--chip); }
.menu-item:disabled { opacity: .4; pointer-events: none; }

/* Bottom sheet (mobile) / centered dialog (desktop) */
.sheet { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet.hidden { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); animation: fade .15s ease-out; }
.sheet-panel {
  position: relative; width: 100%; max-width: 32rem; max-height: 88vh; overflow-y: auto;
  background: var(--panel); color: var(--text);
  border-radius: 1.5rem 1.5rem 0 0; padding: .75rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom));
  animation: slideUp .2s cubic-bezier(.2,.8,.2,1);
}
.sheet-handle { width: 2.5rem; height: .3rem; border-radius: 999px; background: var(--line); margin: 0 auto .9rem; }
@media (min-width: 640px) {
  .sheet { align-items: center; }
  .sheet-panel { border-radius: 1.5rem; padding-bottom: 1.5rem; }
  .sheet-handle { display: none; }
}
@keyframes slideUp { from { transform: translateY(24px); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Clip cards */
.clip {
  background: var(--panel); border: 1px solid var(--line); border-radius: 1.25rem; padding: .85rem;
  transition: border-color .15s, box-shadow .15s; cursor: pointer;
}
.clip:hover { border-color: #c7d2fe; }
.clip.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.clip canvas { display: block; width: 100%; height: 2.5rem; cursor: pointer; touch-action: manipulation; }
@media (min-width: 640px) { .clip { padding: 1rem 1.1rem; } }

.clip-play {
  height: 2.75rem; width: 2.75rem; border-radius: 999px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--chip); color: var(--text); transition: all .15s;
}
.clip.active .clip-play { background: var(--accent); color: #fff; }

.clip-loop[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }

.sub { font-size: 1.0625rem; line-height: 1.55; }
.sub.ko { font-size: .9375rem; color: var(--muted); }
.sub.masked { filter: blur(6px); opacity: .7; cursor: pointer; transition: filter .2s; }
.sub.masked:hover { filter: blur(4px); }
.sub.empty { font-size: .8125rem; color: var(--muted); opacity: .7; font-style: italic; }
@media (min-width: 640px) { .sub { font-size: 1.125rem; } }

/* Tappable words in English subtitles + dictionary popup */
.w { cursor: pointer; border-radius: .3rem; padding: 0 .05em; margin: 0 -.05em; transition: background-color .12s; }
.w:hover { background: var(--accent-soft); }
.w.w-active { background: #fde68a; color: #111827; box-shadow: 0 0 0 2px #fde68a; }
@media (prefers-color-scheme: dark) { .w.w-active { background: #facc15; box-shadow: 0 0 0 2px #facc15; } }

.word-pop {
  position: fixed; z-index: 45; width: min(22rem, calc(100vw - 1.5rem));
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 1rem;
  box-shadow: 0 12px 32px rgba(15, 23, 42, .18), 0 2px 6px rgba(15, 23, 42, .08);
  padding: .9rem 1rem 1rem; animation: popIn .12s ease-out;
}
.word-pop.hidden { display: none; }
@keyframes popIn { from { transform: translateY(4px); } to { transform: none; } }
.word-pop .wp-pos {
  display: inline-block; font-size: .7rem; font-weight: 700; padding: .1rem .45rem; border-radius: .4rem;
  background: var(--accent-soft); color: var(--accent); vertical-align: middle;
}

/* Library (projects / tracks) */
.lib-card {
  display: flex; align-items: center; gap: .85rem; padding: .9rem 1rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 1.1rem;
  cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .1s;
}
.lib-card:hover { border-color: #c7d2fe; box-shadow: 0 1px 6px rgba(15, 23, 42, .06); }
.lib-card:active { transform: scale(.995); }
.lib-icon {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  height: 2.75rem; width: 2.75rem; border-radius: .85rem; background: var(--accent-soft); color: var(--accent);
}
.lib-empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 3rem 1.5rem; border: 2px dashed var(--line); border-radius: 1.5rem;
}
.lib-upload {
  display: flex; align-items: center; justify-content: center; gap: .5rem; height: 3.25rem;
  border: 1.5px dashed var(--accent); border-radius: 1rem; color: var(--accent);
  font-size: .9rem; cursor: pointer; transition: background-color .15s;
}
.lib-upload:hover { background: var(--accent-soft); }
.lib-bar { display: block; height: .25rem; margin-top: .25rem; border-radius: 999px; background: var(--chip); overflow: hidden; }
.lib-bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* Per-clip subtitle buttons */
.sub-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  height: 2.25rem; padding: 0 .85rem; border-radius: .75rem;
  font-size: .8125rem; font-weight: 600; white-space: nowrap;
  background: var(--chip); color: var(--muted); border: 1px solid transparent;
  transition: background-color .15s, color .15s, transform .1s;
}
.sub-btn:hover { background: var(--chip-hover); color: var(--text); }
.sub-btn:active { transform: scale(.97); }
.sub-btn.gen { background: transparent; color: var(--accent); border: 1px dashed var(--accent); }
.sub-btn.gen:hover { background: var(--accent-soft); }
.sub-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.sub-btn:disabled { cursor: default; opacity: .8; transform: none; }

.gapbar { height: .25rem; border-radius: 999px; background: var(--chip); overflow: hidden; }
.gapbar > div { height: 100%; width: 0; background: #f59e0b; }

/* Dictation (영어 타이핑) + comparison */
.typing-input { resize: none; overflow: hidden; min-height: 2.75rem; font-size: 1rem; }
.cmp-hint { font-size: .8125rem; color: var(--muted); }
.cmp-score {
  display: inline-flex; align-items: center; height: 1.6rem; padding: 0 .6rem; border-radius: .5rem;
  font-size: .8125rem; font-weight: 700; background: var(--chip); color: var(--text); font-variant-numeric: tabular-nums;
}
.cmp-score.good { background: #dcfce7; color: #15803d; }
.cmp-chip { display: inline-flex; align-items: center; height: 1.6rem; padding: 0 .55rem; border-radius: .5rem; font-size: .75rem; font-weight: 600; }
.cmp-row {
  display: flex; flex-wrap: wrap; gap: .35rem .3rem; padding: .6rem; border-radius: .85rem;
  background: var(--chip); font-size: .9375rem; line-height: 1.35;
}
.cmp-col { display: inline-flex; flex-direction: column; align-items: flex-start; padding: .2rem .35rem; border-radius: .5rem; }
.cmp-col > span { white-space: pre; }
.cmp-t { font-weight: 600; min-height: 1.3em; }
.cmp-a { color: var(--muted); font-size: .85em; }
.cmp-l { font-size: .65rem; font-weight: 700; letter-spacing: .02em; min-height: 1em; }
.cmp-legend { color: var(--muted); font-size: .75rem; font-weight: 600; padding-right: .15rem; }
.cmp-legend .cmp-t { font-weight: 600; }
.cmp-legend .cmp-a { font-size: 1em; }
.cmp-gap { display: inline-block; width: 2.2em; height: 1.05em; vertical-align: middle; border-bottom: 2px dashed currentColor; }
.cx { border-radius: .2rem; }
.cmp-sp { padding: 0 .1em; }

/* colors per difference kind (light) */
.t-ok .cmp-t { color: #15803d; }
.t-minor { background: #e0f2fe; } .t-minor .cx { background: #7dd3fc; color: #0c4a6e; } .t-minor .cmp-l { color: #0369a1; }
.t-wrong { background: #fee2e2; } .t-wrong .cmp-t { color: #b91c1c; } .t-wrong .cmp-t .cx { background: #fca5a5; color: #7f1d1d; }
.t-wrong .cmp-a .cx { background: #bbf7d0; color: #14532d; font-weight: 700; } .t-wrong .cmp-l { color: #b91c1c; }
.t-missing { background: #ffedd5; } .t-missing .cmp-t { color: #c2410c; } .t-missing .cmp-a { color: #9a3412; font-weight: 600; } .t-missing .cmp-l { color: #c2410c; }
.t-extra { background: #f3e8ff; } .t-extra .cmp-t { color: #7e22ce; text-decoration: line-through; } .t-extra .cmp-l { color: #7e22ce; }
.t-join, .t-split { background: #fef9c3; } .t-join .cmp-l, .t-split .cmp-l { color: #a16207; }
.t-join .cx, .t-split .cx { background: #fde047; color: #713f12; font-weight: 700; }
.t-contr { background: #e0e7ff; } .t-contr .cmp-l { color: #4338ca; }
.cmp-chip.t-wrong { color: #b91c1c; } .cmp-chip.t-missing { color: #c2410c; } .cmp-chip.t-extra { color: #7e22ce; }
.cmp-chip.t-join { color: #a16207; } .cmp-chip.t-contr { color: #4338ca; } .cmp-chip.t-minor { color: #0369a1; }
.cmp-ai { font-size: .875rem; line-height: 1.5; padding: .7rem .8rem; border-radius: .85rem; border: 1px solid var(--line); }
.cmp-kind {
  display: inline-block; font-size: .7rem; font-weight: 700; padding: .05rem .4rem; margin-right: .35rem; border-radius: .35rem;
  background: var(--accent-soft); color: var(--accent); vertical-align: 1px;
}
@media (prefers-color-scheme: dark) {
  .cmp-score.good { background: rgba(34, 197, 94, .18); color: #4ade80; }
  .t-ok .cmp-t { color: #4ade80; }
  .t-minor { background: rgba(14, 165, 233, .15); } .t-minor .cmp-l { color: #7dd3fc; }
  .t-wrong { background: rgba(239, 68, 68, .16); } .t-wrong .cmp-t, .t-wrong .cmp-l, .cmp-chip.t-wrong { color: #fca5a5; }
  .t-missing { background: rgba(249, 115, 22, .16); } .t-missing .cmp-t, .t-missing .cmp-a, .t-missing .cmp-l, .cmp-chip.t-missing { color: #fdba74; }
  .t-extra { background: rgba(168, 85, 247, .16); } .t-extra .cmp-t, .t-extra .cmp-l, .cmp-chip.t-extra { color: #d8b4fe; }
  .t-join, .t-split { background: rgba(234, 179, 8, .16); } .t-join .cmp-l, .t-split .cmp-l, .cmp-chip.t-join { color: #fde047; }
  .t-contr { background: rgba(99, 102, 241, .18); } .t-contr .cmp-l, .cmp-chip.t-contr { color: #a5b4fc; }
  .cmp-chip.t-minor { color: #7dd3fc; }
}

#dropOverlay.show { display: flex; }

.sub-btn.sub-del { color: #dc2626; }
.sub-btn.sub-del:hover { background: #fee2e2; color: #b91c1c; }
@media (prefers-color-scheme: dark) {
  .sub-btn.sub-del { color: #f87171; }
  .sub-btn.sub-del:hover { background: rgba(239, 68, 68, .16); color: #fca5a5; }
}

/* bookmark */
.bm-btn {
  display: inline-flex; align-items: center; justify-content: center; height: 1.75rem; width: 1.75rem;
  margin: -.35rem 0; border-radius: .5rem; color: var(--muted); transition: background-color .15s, color .15s, transform .1s;
}
.bm-btn:hover { background: var(--chip); color: var(--text); }
.bm-btn:active { transform: scale(.9); }
.bm-btn[aria-pressed="true"] { color: #f59e0b; }
.chip-bm[aria-pressed="true"] { background: #fef3c7; color: #b45309; }
@media (prefers-color-scheme: dark) { .chip-bm[aria-pressed="true"] { background: rgba(245, 158, 11, .18); color: #fbbf24; } }
#bmCount:not(:empty) { margin-left: .1rem; opacity: .8; }

/* option chip (on/off): no strike-through when off */
.chip.chip-opt[aria-pressed="false"] { text-decoration: none; }

/* comparison columns: tap = jump to that word in the audio */
.cmp-tap { cursor: pointer; transition: box-shadow .12s; }
.cmp-tap:hover { box-shadow: inset 0 0 0 1.5px var(--accent); }
.cmp-tap:active { transform: scale(.97); }

.btn-danger { color: #dc2626; }
.btn-danger:hover { background: #fee2e2; }
.btn-danger:disabled { color: var(--muted); opacity: .6; pointer-events: none; }
@media (prefers-color-scheme: dark) { .btn-danger { color: #f87171; } .btn-danger:hover { background: rgba(239, 68, 68, .16); } }

/* Grammar points under the English subtitle */
.g-row { display: flex; flex-wrap: wrap; gap: .4rem; margin: .45rem 0 .2rem; }
.g-chip {
  display: inline-flex; align-items: center; gap: .35rem; min-height: 1.9rem; padding: .2rem .7rem; border-radius: 999px;
  font-size: .8rem; font-weight: 600; line-height: 1.3; text-align: left;
  background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; transition: background-color .15s, box-shadow .15s, transform .1s;
}
.g-chip:hover { background: #d1fae5; }
.g-chip:active { transform: scale(.97); }
.g-chip.active { background: #10b981; color: #fff; border-color: #10b981; }
.g-chip b { font-weight: 800; }
.g-chip.g-gen { background: transparent; border-style: dashed; }
.g-chip[aria-disabled="true"] { opacity: .8; }
.w.g-hl { background: #a7f3d0; color: #064e3b; box-shadow: 0 0 0 2px #a7f3d0; }
.g-ex { font-size: .8125rem; color: var(--muted); }
.g-ex li { padding-left: .8rem; position: relative; }
.g-ex li::before { content: '•'; position: absolute; left: 0; }
@media (prefers-color-scheme: dark) {
  .g-chip { background: rgba(16, 185, 129, .12); color: #6ee7b7; border-color: rgba(16, 185, 129, .35); }
  .g-chip:hover { background: rgba(16, 185, 129, .2); }
  .g-chip.active { background: #10b981; color: #052e1f; border-color: #10b981; }
  .g-chip.g-gen { background: transparent; }
  .w.g-hl { background: #34d399; color: #022c22; box-shadow: 0 0 0 2px #34d399; }
}
