:root {
  color-scheme: light;
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-soft: #edf4f0;
  --ink: #172221;
  --muted: #60706c;
  --line: #cfdbd6;
  --accent: #174c4f;
  --accent-2: #b13d2e;
  --accent-soft: #d9eeeb;
  --gold: #af7c22;
  --shadow: 0 14px 36px rgba(23, 34, 33, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(14px, 3vw, 28px);
  background: rgba(244, 247, 245, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 24px;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.1;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

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

.profile-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(54px, 1fr));
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.profile-switch button {
  min-height: 40px;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  padding: 0 12px;
  font-weight: 700;
}

.profile-switch button.active {
  background: var(--accent);
  color: white;
}

.icon-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
}

.primary-button {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.layout {
  display: grid;
  grid-template-columns: minmax(230px, 280px) 1fr;
  min-height: calc(100vh - 73px);
}

.sidebar {
  padding: 18px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.control-group {
  display: grid;
  gap: 7px;
  margin-bottom: 16px;
}

.control-group > label,
.flow-toolbar > label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

select,
input[type="search"] {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.segmented button {
  min-height: 38px;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.segmented button.active {
  background: var(--accent);
  color: white;
}

.compact-checks {
  gap: 9px;
}

.compact-checks label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  text-transform: none;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 20px;
}

.stats div {
  padding: 10px;
  background: var(--surface-soft);
  border-radius: 6px;
}

.stats strong,
.stats span {
  display: block;
}

.stats strong {
  font-size: 18px;
}

.stats span {
  color: var(--muted);
  font-size: 11px;
}

.workspace {
  min-width: 0;
  padding: 18px clamp(14px, 2.4vw, 28px) 28px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tabs button {
  padding: 0 18px;
}

.tabs button.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.practice-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  gap: 18px;
  align-items: start;
}

.phrase-stage,
.queue-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.phrase-stage {
  min-height: 520px;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
}

.stage-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.stage-meta span,
.chip {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
}

#audioBadge.has-audio {
  background: #e6f2df;
  color: #27651f;
}

#qualityBadge.warning-chip {
  background: #fae8dc;
  color: #8b2f22;
}

#weakBadge.weak-chip {
  background: #fff0c9;
  color: #7c520b;
}

.phrase-display {
  display: grid;
  align-content: center;
  gap: 16px;
  padding: clamp(20px, 5vw, 56px);
}

.japanese-text {
  font-size: clamp(34px, 6vw, 72px);
  line-height: 1.12;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.furigana-text,
.romaji-text,
.english-text {
  max-width: 900px;
  overflow-wrap: anywhere;
}

.furigana-text {
  font-size: 24px;
  line-height: 1.35;
  color: #2d625f;
}

.romaji-text {
  font-size: 21px;
  line-height: 1.35;
  color: var(--accent-2);
}

.english-text {
  font-size: 20px;
  line-height: 1.45;
  color: var(--muted);
}

.hidden-line {
  display: none;
}

.alignment-check {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: #f8fbf9;
}

.alignment-row {
  display: grid;
  gap: 4px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.alignment-row.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.alignment-row span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.alignment-row strong {
  font-size: 15px;
  line-height: 1.3;
}

.alignment-row small,
.alignment-row em {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.alignment-row em {
  color: var(--accent-2);
  font-style: normal;
  font-weight: 700;
}

.player-controls,
.shadow-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px;
  border-top: 1px solid var(--line);
}

.round-button {
  width: 46px;
  border-radius: 50%;
  font-size: 26px;
  line-height: 1;
}

.shadow-controls {
  flex-wrap: wrap;
  justify-content: flex-start;
}

.shadow-controls label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.shadow-controls input[type="range"] {
  max-width: 180px;
}

#autoButton.active,
#weakButton.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}

#weakButton.active {
  background: #fff0c9;
  border-color: var(--gold);
  color: #7c520b;
}

.queue-panel {
  max-height: calc(100vh - 126px);
  display: grid;
  grid-template-rows: auto 1fr;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2 {
  font-size: 15px;
}

.queue-list,
.phrase-table,
.flow-list {
  overflow: auto;
}

.queue-list {
  padding: 8px;
}

.queue-item,
.flow-item,
.phrase-row {
  display: grid;
  gap: 5px;
  width: 100%;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  text-align: left;
}

.queue-item {
  cursor: pointer;
}

.queue-item.active,
.phrase-row.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.queue-item.weak,
.phrase-row.weak {
  box-shadow: inset 3px 0 0 var(--gold);
}

.queue-item strong,
.flow-item strong,
.phrase-row strong {
  font-size: 16px;
  line-height: 1.25;
}

.queue-item span,
.flow-item span,
.phrase-row span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.queue-item .audio-dot,
.queue-item .weak-dot,
.phrase-row .audio-dot,
.phrase-row .weak-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line);
  flex: 0 0 auto;
}

.queue-item .audio-dot.on,
.phrase-row .audio-dot.on {
  background: var(--gold);
}

.queue-item .weak-dot,
.phrase-row .weak-dot {
  background: transparent;
}

.queue-item .weak-dot.on,
.phrase-row .weak-dot.on {
  background: var(--accent-2);
}

.line-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.flow-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.flow-toolbar .segmented {
  min-width: min(100%, 280px);
}

.flow-toolbar input[type="range"] {
  max-width: 160px;
}

.flow-list {
  display: grid;
  gap: 10px;
}

.flow-item {
  grid-template-columns: auto 1fr auto;
  align-items: start;
  background: var(--surface);
  border-color: var(--line);
  box-shadow: 0 7px 20px rgba(23, 34, 33, 0.06);
}

.flow-index {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 13px;
  font-weight: 800;
}

.flow-actions {
  display: flex;
  gap: 6px;
}

.flow-actions button {
  min-height: 34px;
  padding: 0 10px;
}

.phrase-table {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 140px);
}

.phrase-row {
  background: var(--surface);
  border-color: var(--line);
  cursor: pointer;
}

.empty-state {
  padding: 28px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

@media (max-width: 940px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .practice-grid {
    grid-template-columns: 1fr;
  }

  .queue-panel {
    max-height: none;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: stretch;
  }

  .profile-switch {
    flex: 1 1 100%;
  }

  .top-actions > button {
    flex: 1;
  }

  .tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .tabs button {
    padding: 0 8px;
  }

  .phrase-stage {
    min-height: 460px;
  }

  .japanese-text {
    font-size: 36px;
  }

  .furigana-text {
    font-size: 20px;
  }

  .romaji-text,
  .english-text {
    font-size: 18px;
  }

  .player-controls {
    justify-content: space-between;
  }

  .primary-button {
    flex: 1;
  }
}
