:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #eef3ee;
  --ink: #17201d;
  --muted: #66716c;
  --line: #dbe2dc;
  --teal: #1d7f75;
  --teal-dark: #105b54;
  --amber: #b36b00;
  --red: #b94335;
  --green: #257447;
  --blue: #2f6690;
  --shadow: 0 18px 50px rgba(23, 32, 29, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  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,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

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

.sidebar {
  width: min(100%, 340px);
  min-height: 100vh;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
}

.brand-copy {
  min-width: 0;
  flex: 1;
}

.brand-subline {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 6px;
  margin-top: 4px;
}

.brand-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.2;
}

.brand-row p,
.field-label,
.deck-status,
.setting-row,
.queue-header span,
.word-meta,
#phoneticText {
  color: var(--muted);
}

.brand-row p {
  font-size: 13px;
  line-height: 32px;
  white-space: nowrap;
}

.panel {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
}

.select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

.deck-status {
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.4;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

.plan-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.plan-line + .plan-line {
  margin-top: 12px;
}

.plan-line strong {
  color: var(--ink);
  font-size: 14px;
  text-align: right;
}

.metric-link {
  border: 0;
  padding: 2px 0;
  background: transparent;
  color: var(--teal-dark);
  font-size: 14px;
  font-weight: 750;
  text-align: right;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.metric-link:hover {
  color: var(--teal);
}

.plan-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

/* Day switcher */
.day-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
}

.day-picker-btn,
.day-nav-btn {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}

.day-picker-btn {
  width: auto;
  min-width: 108px;
  padding: 0 10px;
  gap: 6px;
}

.day-picker-btn strong {
  font-size: 14px;
}

.day-nav-btn:hover:not(:disabled) {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}

.day-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.setting-row.spaced {
  margin-top: 18px;
}

.setting-row.mode-row {
  margin-top: 0;
}

.playback-settings.is-reading .listening-only {
  display: none;
}

.speed-row {
  margin-top: 18px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 42px;
  align-items: center;
  gap: 10px;
}

.speed-row label,
.speed-row span {
  white-space: nowrap;
}

.speed-row span {
  text-align: right;
}

.range {
  width: 100%;
  margin: 0;
  accent-color: var(--teal);
}

.switch {
  width: 46px;
  height: 26px;
  padding: 2px;
  border: 0;
  border-radius: 999px;
  background: var(--line);
}

.switch span {
  display: block;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #fff;
  transition: transform 160ms ease;
  box-shadow: 0 2px 8px rgba(23, 32, 29, 0.16);
}

.switch[aria-pressed="true"] {
  background: var(--teal);
}

.switch[aria-pressed="true"] span {
  transform: translateX(20px);
}

.mode-toggle {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 52px));
  height: 30px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf2f1;
}

.mode-toggle button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.mode-toggle button.is-active {
  background: #ffffff;
  color: var(--teal-dark);
  box-shadow: 0 1px 4px rgba(28, 39, 35, 0.12);
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.compact-action {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.player-stage {
  display: none;
}

.dict-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--teal-dark);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  transition: background 120ms ease, border-color 120ms ease;
}

.dict-link:hover {
  background: var(--surface-2);
  border-color: var(--teal);
}

.dict-link svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.brand-actions .dict-link,
.brand-actions .icon-button {
  width: 32px;
  height: 32px;
  padding: 0;
}

.brand-actions .dict-link {
  justify-content: center;
}

.brand-actions .dict-link span {
  display: none;
}

.brand-actions .dict-link svg,
.brand-actions .icon-button svg {
  width: 18px;
  height: 18px;
}

.user-phone-btn {
  min-width: 82px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
  line-height: 30px;
  text-align: center;
  white-space: nowrap;
}

.user-phone-btn:hover {
  border-color: var(--teal);
  background: var(--surface-2);
}

/* Progress track */
.progress-track {
  width: clamp(80px, 14vw, 160px);
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8ecf0;
  border: 1px solid #dce1e6;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.06);
}

.progress-bar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--blue));
  transition: width 180ms ease;
  border-radius: 999px;
}

.word-card {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.word-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  text-transform: uppercase;
}

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

#wordText {
  margin-top: 18px;
  max-width: 100%;
  font-size: 64px;
  line-height: 1.02;
  letter-spacing: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
  hyphens: auto;
}

#phoneticText {
  margin-top: 8px;
  font-size: 20px;
}

#meaningText {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.4;
  font-weight: 500;
}

.meaning-row {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.meaning-pos {
  flex: 0 0 auto;
  color: var(--teal-dark);
  font-weight: 600;
}

.meaning-def {
  min-width: 0;
}

.example-box {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.example-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.example-header > span {
  color: var(--amber);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.example-box p {
  color: #33403b;
  font-size: clamp(18px, 2.5vw, 24px);
  line-height: 1.45;
}

.example-list {
  display: grid;
  gap: 12px;
}

.example-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
}

.example-row .example-selectable {
  margin: 0;
}

.example-row .small-action-btn {
  margin-top: 2px;
  white-space: nowrap;
}

.example-selectable {
  user-select: text;
}

.example-word {
  display: inline;
  margin-bottom: 0;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
  border-radius: 3px;
  padding: 0 1px;
  transition: background 120ms ease, color 120ms ease;
}

.example-word:hover {
  background: rgba(29, 127, 117, 0.12);
  color: var(--teal-dark);
}

.small-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.small-action-btn:hover {
  background: var(--surface);
  color: var(--teal);
  border-color: var(--teal);
}

.small-action-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.example-zh {
  grid-column: 1 / -1;
  margin-top: 0;
  color: var(--teal-dark);
  font-size: clamp(15px, 2vw, 19px);
  line-height: 1.5;
  font-weight: 600;
}

.lookup-modal {
  width: min(100%, 420px);
}

.lookup-close-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}

.lookup-body {
  margin-top: 0;
}

.lookup-main-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 16px;
}

.lookup-actions {
  display: grid;
  justify-items: end;
  gap: 10px;
}

.lookup-icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
}

.lookup-icon-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.lookup-word {
  margin: 0;
  font-size: 32px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.1;
}

.lookup-phonetic {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 16px;
}

.lookup-meaning {
  margin: 14px 0 0;
  color: var(--teal-dark);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.45;
}

.lookup-definition {
  margin: 10px 0 0;
  color: #33403b;
  font-size: 15px;
  line-height: 1.5;
}

.lookup-loading {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.primary-button.compact {
  min-height: 40px;
  padding: 0 14px;
  white-space: nowrap;
}

.transport {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.study-controls {
  display: none;
  grid-template-columns: 1fr;
  align-items: center;
  gap: 14px;
  margin-top: 28px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fbfdfc, #f4faf8);
}

.study-controls.is-reading {
  display: grid;
}

.transport.in-meta.is-reading {
  display: none;
}

.transport.in-meta {
  justify-content: flex-end;
  flex-shrink: 0;
  margin-left: auto;
}

.transport.in-meta .icon-button.large {
  display: none;
}

.icon-button,
.play-button {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.icon-button {
  width: 44px;
  height: 44px;
}

.icon-button.large {
  width: 48px;
  height: 48px;
  background: #ffffff;
  color: #25342f;
}

.play-button {
  width: 68px;
  height: 68px;
  border-color: var(--teal-dark);
  background: var(--teal);
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(29, 127, 117, 0.22);
}

.icon-button:hover,
.play-button:hover,
.feedback:hover,
.word-pill:hover {
  transform: translateY(-1px);
}

.icon-button:disabled,
.play-button:disabled,
.feedback:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.icon-button svg,
.play-button svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.play-button svg {
  width: 30px;
  height: 30px;
  fill: currentColor;
  stroke: none;
}

.feedback-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 180px));
  justify-content: center;
  gap: 0;
  width: 100%;
  margin-inline: auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.study-controls.is-reading .feedback-row {
  grid-template-columns: repeat(2, minmax(0, 180px));
}

.feedback-row.in-card {
  margin-top: 0;
}

.feedback {
  position: relative;
  min-height: 50px;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  font-weight: 750;
}

.feedback + .feedback {
  border-left: 1px solid var(--line);
}

.feedback::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  opacity: 0;
}

.feedback.danger {
  background: #fffafa;
  color: var(--red);
}

.feedback.warn {
  background: #fffaf1;
  color: var(--amber);
}

.feedback.good {
  background: #f7fcf9;
  color: var(--green);
}

.feedback.danger::before {
  background: var(--red);
  opacity: 0.55;
}

.feedback.warn::before {
  background: var(--amber);
  opacity: 0.55;
}

.feedback.good::before {
  background: var(--green);
  opacity: 0.55;
}

@media (max-width: 1180px) {
  .study-controls {
    grid-template-columns: 1fr;
  }
}

.queue-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.queue-header h2 {
  font-size: 18px;
}

.queue-header span {
  font-size: 13px;
}

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

.empty-state,
.queue-divider {
  margin: 0;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.queue-divider {
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
}

.word-pill {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 58px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
}

.word-pill strong {
  display: block;
  font-size: 16px;
  line-height: 1.1;
}

.word-pill span {
  margin-top: 5px;
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.word-pill.is-active {
  border-color: var(--teal);
  background: #edf8f6;
}

.word-pill:disabled {
  cursor: default;
  opacity: 0.72;
  transform: none;
}

.word-pill em {
  color: var(--blue);
  font-style: normal;
  font-size: 12px;
  font-weight: 800;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 29, 0.38);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(100%, 460px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.list-modal {
  width: min(100%, 620px);
}

.day-list,
.modal-word-list {
  display: grid;
  gap: 10px;
  max-height: min(62vh, 520px);
  overflow: auto;
  padding-right: 4px;
}

.day-option {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
}

.day-option.is-active {
  border-color: var(--teal);
  background: #edf8f6;
}

.day-option:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.day-option span {
  font-weight: 750;
}

.day-option em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.modal-word-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.modal-word-row.is-readonly {
  grid-template-columns: minmax(0, 1fr);
}

.modal-word-row strong {
  display: inline-block;
  margin-right: 8px;
  font-size: 17px;
}

.modal-word-row span {
  color: var(--muted);
  font-size: 13px;
}

.modal-word-row p {
  margin-top: 6px;
  color: var(--teal-dark);
  font-size: 14px;
  line-height: 1.45;
}

.modal-word-row .modal-word-meaning {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.modal-word-row .meaning-row {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.modal-word-row .meaning-pos {
  color: var(--teal-dark);
  font-weight: 700;
}

.modal-word-row .meaning-def {
  color: var(--teal-dark);
}

.modal-word-row .compact-action {
  min-width: 48px;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 7px;
  font-size: 12px;
}

.pager-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) 96px;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.pager-row span {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.modal h2 {
  color: var(--ink);
  font-size: 20px;
  line-height: 1.2;
}

.form-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  align-items: center;
  gap: 14px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.form-field input {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
}

.form-field input.compact-number-input {
  max-width: 112px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.form-field.unlearned-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  margin-bottom: 14px;
  padding: 12px 14px;
  background: #f5fbfa;
  border-radius: 8px;
  border: 1px solid #cce5df;
}

.form-field.unlearned-display strong {
  color: var(--teal-dark);
  font-size: 20px;
  font-weight: 700;
}

.modal-note {
  margin-top: 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.form-error {
  min-height: 20px;
  margin-top: 12px;
  color: var(--red);
  font-size: 13px;
}

.modal-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.modal-actions > :only-child {
  grid-column: 2;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 750;
  width: 100%;
}

.primary-button:disabled,
.secondary-button:disabled,
.compact-action:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  filter: grayscale(0.4);
}

.primary-button {
  border: 1px solid var(--teal-dark);
  background: var(--teal);
  color: #fff;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  #wordText {
    font-size: 54px;
  }

}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    padding: 16px 16px 4px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .panel {
    margin-top: 12px;
  }

  .player-stage {
    display: none;
  }

  .word-card {
    margin-top: 12px;
  }

  .feedback-row.in-card {
    margin-top: 0;
  }

  .study-controls {
    margin-top: 22px;
    padding: 10px;
    gap: 10px;
  }

  .brand-subline {
    align-items: flex-end;
  }

  .brand-actions {
    gap: 5px;
  }

  .word-card {
    padding: 16px;
  }

  #wordText {
    font-size: 42px;
    line-height: 1.08;
  }

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

  .feedback {
    min-height: 52px;
    font-size: 15px;
  }

  .example-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .example-row .small-action-btn {
    justify-self: start;
  }

  .lookup-main-row {
    grid-template-columns: 1fr;
  }

  .lookup-actions {
    grid-template-columns: auto 1fr;
    justify-items: stretch;
  }

  .lookup-icon-button {
    width: 44px;
  }

  .modal-actions {
    display: grid;
  }
}
