:root {
  color-scheme: light;
  --bg: #f8fafc;
  --topbar-bg: rgba(248, 250, 252, 0.96);
  --panel: #ffffff;
  --ink: #111827;
  --muted: #64748b;
  --line: #d7dee8;
  --accent: #147a63;
  --accent-strong: #0f5f4d;
  --selected-bg: #111827;
  --selected-ink: #ffffff;
  --danger: #b42318;
  --done: #f1f5f9;
  --shadow: 0 1px 4px rgba(15, 23, 42, 0.08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120;
  --topbar-bg: rgba(11, 17, 32, 0.96);
  --panel: #111827;
  --ink: #e5e7eb;
  --muted: #94a3b8;
  --line: #334155;
  --accent: #34d399;
  --accent-strong: #10b981;
  --selected-bg: #065f46;
  --selected-ink: #ecfdf5;
  --danger: #fca5a5;
  --done: #1e293b;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100%;
  font-family: Arial, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button,
textarea,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 680px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 12px 10px 28px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0 12px;
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
}

h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
  letter-spacing: 0;
}

.summary {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.icon-button,
.primary-button,
.quick-actions button,
.file-button,
.shuffle-row button,
.segment,
.delete-button,
.copy-button,
.audio-button,
.clipper-close,
.clipper-actions button,
.nudge-grid button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  min-height: 40px;
}

.icon-button {
  min-width: 54px;
  padding: 0 10px;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin: 0 0 10px;
}

.quick-actions button,
.file-button,
.shuffle-row button,
.clipper-actions button,
.nudge-grid button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 8px;
  font-size: 14px;
  font-weight: 700;
}

.add-panel {
  display: grid;
  gap: 8px;
  margin: 0 0 10px;
}

#newCardText,
.card-text,
#searchInput {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

#newCardText {
  min-height: 328px;
  padding: 13px;
  resize: vertical;
  line-height: 1.5;
  box-shadow: var(--shadow);
}

.add-status {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

#newCardText:focus,
.card-text:focus,
#searchInput:focus,
.field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 122, 99, 0.14);
}

.primary-button {
  min-height: 50px;
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  font-size: 17px;
  font-weight: 800;
}

.primary-button:active {
  background: var(--accent-strong);
}

.controls {
  display: grid;
  gap: 8px;
  margin: 10px 0;
}

#searchInput {
  height: 42px;
  padding: 0 12px;
}

.segments {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.segment {
  height: 40px;
  padding: 0 8px;
  font-weight: 700;
}

.segment.active {
  border-color: var(--ink);
  background: var(--selected-bg);
  color: var(--selected-ink);
}

.sort-controls {
  display: grid;
  gap: 6px;
}

.sort-switch {
  display: grid;
  gap: 6px;
}

.sort-switch[aria-label="완료 정렬"] {
  grid-template-columns: repeat(3, 1fr);
}

.sort-switch[aria-label="시간 정렬"] {
  grid-template-columns: repeat(2, 1fr);
}

.sort-switch button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
}

.sort-switch button.active {
  border-color: var(--accent);
  background: var(--selected-bg);
  color: var(--selected-ink);
}

.shuffle-row {
  display: grid;
  grid-template-columns: 1fr;
}

.clipper-panel {
  display: grid;
  gap: 9px;
  margin: 0 0 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.clipper-panel.hidden,
.youtube-player-wrap.hidden {
  display: none;
}

.clipper-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 8px;
}

.clipper-head h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.3;
  letter-spacing: 0;
}

.clipper-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.clipper-close {
  min-width: 56px;
  padding: 0 10px;
  font-weight: 700;
}

.field-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field-input,
.clipper-time-grid input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

.field-input {
  padding: 0 11px;
}

.clipper-time-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.clipper-time-grid label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.clipper-time-grid input {
  padding: 0 8px;
  text-align: center;
}

.nudge-grid,
.clipper-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.nudge-grid {
  grid-template-columns: repeat(4, 1fr);
}

.clipper-actions button,
.nudge-grid button {
  font-size: 13px;
}

#youtubePreviewButton,
#saveYoutubeClipButton {
  border-color: var(--accent);
  color: var(--accent);
}

.youtube-player-wrap {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #000000;
  aspect-ratio: 16 / 9;
}

#youtubePlayer,
#youtubePlayer iframe {
  width: 100%;
  height: 100%;
}

.local-audio-button {
  min-height: 44px;
  color: var(--accent);
}

#localAudioInput {
  display: none;
}

.clipper-picker {
  display: grid;
  gap: 6px;
}

.clipper-selected-card {
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.clipper-selected-card.selected {
  border-color: var(--accent);
  color: var(--ink);
}

.clipper-card-results {
  display: grid;
  gap: 5px;
  max-height: 220px;
  overflow: auto;
}

.clipper-card-result {
  display: grid;
  gap: 2px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  text-align: left;
}

.clipper-card-result strong {
  overflow: hidden;
  font-size: 13px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clipper-card-result span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-list {
  display: grid;
  gap: 8px;
  padding: 2px 0 12px;
}

.sentence-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 74px;
  grid-template-rows: minmax(82px, 1fr) auto;
  grid-template-areas:
    "text check"
    "text actions";
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  touch-action: pan-y;
  transition: transform 140ms ease;
}

.sentence-card.swiping {
  transition: none;
}

.sentence-card.done {
  background: var(--done);
  color: #475569;
}

[data-theme="dark"] .sentence-card.done {
  color: #94a3b8;
}

.check-wrap {
  grid-area: check;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 82px;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  background: color-mix(in srgb, var(--panel) 78%, transparent);
  font-size: 13px;
  font-weight: 700;
}

.done-check {
  width: 18px;
  height: 18px;
}

.card-text {
  grid-area: text;
  min-height: 118px;
  padding: 12px;
  resize: none;
  overflow: hidden;
  line-height: 1.52;
  white-space: pre-wrap;
}

.card-actions {
  grid-area: actions;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: repeat(3, 36px);
  align-self: start;
  gap: 5px;
  min-height: 118px;
}

.delete-button,
.copy-button,
.audio-button {
  min-height: 36px;
  width: 100%;
  padding: 0 4px;
  font-size: 12px;
  font-weight: 700;
}

.delete-button {
  color: var(--danger);
}

.copy-button {
  color: var(--accent);
}

.audio-button {
  color: var(--ink);
  font-size: 16px;
}

.audio-button.ready {
  border-color: var(--accent);
  color: var(--accent);
}

.audio-button.pending {
  color: var(--muted);
}

.audio-button.failed {
  color: var(--danger);
}

.empty-state {
  padding: 28px 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

#importInput {
  display: none;
}

.card-menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  background: rgba(15, 23, 42, 0.42);
}

.card-menu-sheet {
  width: min(100%, 520px);
  max-height: min(82vh, 720px);
  overflow: auto;
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px 12px 8px 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.26);
}

.card-menu-title {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.folder-choice-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.folder-choice,
.related-toggle,
.sheet-close,
.related-search-button,
.related-result,
.related-chip {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
}

.folder-choice {
  min-height: 44px;
  padding: 0 8px;
}

.folder-choice.active {
  border-color: var(--accent);
  background: var(--selected-bg);
  color: var(--selected-ink);
}

.related-toggle,
.sheet-close {
  min-height: 42px;
}

.related-sheet {
  display: grid;
  gap: 8px;
}

.related-sheet.hidden {
  display: none;
}

.pronunciation-sheet {
  gap: 12px;
}

.pronunciation-body {
  display: grid;
  gap: 10px;
}

.pronunciation-block,
.pronunciation-rule,
.pronunciation-message {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 88%, var(--bg));
}

.pronunciation-label,
.pronunciation-section-title,
.pronunciation-rule-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
}

.pronunciation-value {
  margin-top: 5px;
  white-space: pre-wrap;
  line-height: 1.55;
}

.pronunciation-phonetic {
  font-family: "Arial", "Segoe UI Symbol", sans-serif;
  font-size: 17px;
}

.pronunciation-section-title {
  margin: 4px 0 -4px;
  color: var(--accent);
}

.pronunciation-rule {
  display: grid;
  gap: 5px;
}

.pronunciation-rule-target {
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.4;
  word-break: break-word;
}

.pronunciation-rule p {
  margin: 0;
  line-height: 1.5;
}

.pronunciation-practice {
  color: var(--muted);
  font-size: 13px;
}

.pronunciation-tips {
  margin: 0;
  padding-left: 18px;
  line-height: 1.5;
}

.pronunciation-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.pronunciation-refresh {
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--panel);
  color: var(--accent);
  font-weight: 800;
}

.related-direct-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.related-chip {
  max-width: 100%;
  min-height: 30px;
  padding: 0 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--accent);
  font-size: 12px;
}

.related-empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.related-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 6px;
}

.related-search-input {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

.related-search-button {
  min-height: 40px;
}

.related-search-results {
  display: grid;
  gap: 5px;
}

.related-result {
  display: grid;
  gap: 2px;
  min-height: 38px;
  padding: 7px 9px;
  text-align: left;
  line-height: 1.35;
}

.related-result-meta {
  color: var(--accent);
  font-size: 11px;
}

.related-result-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.related-result-snippet {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 420px) {
  .app-shell {
    padding-left: 8px;
    padding-right: 8px;
  }

  .sentence-card {
    grid-template-columns: minmax(0, 1fr) 64px;
    gap: 7px;
    padding: 8px;
  }

  .card-actions {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(3, 36px);
    gap: 4px;
  }

  .check-label,
  .delete-button,
  .copy-button,
  .audio-button {
    font-size: 12px;
  }

  .card-text {
    min-height: 132px;
    padding: 11px;
  }

  .quick-actions,
  .nudge-grid {
    gap: 5px;
  }
}
