:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --panel: #ffffff;
  --panel-strong: #eef6f4;
  --text: #17211f;
  --muted: #65726f;
  --line: #d9e2df;
  --teal: #087a72;
  --teal-dark: #075f59;
  --amber: #b76a00;
  --red: #c54040;
  --blue: #315d9c;
  --shadow: 0 16px 38px rgba(18, 45, 42, 0.09);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
}

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

@supports (min-height: 100dvh) {
  body {
    min-height: 100dvh;
  }
}

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

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
}

@supports (min-height: 100dvh) {
  .app-shell {
    min-height: 100dvh;
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: #0d625e;
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

.brand h1,
.panel h2,
.term-card h3 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 1.2rem;
  line-height: 1.2;
}

.brand p,
.panel-head p,
.status-label,
.term-meta,
.term-meaning,
.eyebrow,
.phonetic,
.meaning,
#hintText,
.result-box,
.history-list {
  color: var(--muted);
}

.brand p,
.panel-head p {
  margin: 4px 0 0;
  font-size: 0.88rem;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, 1fr));
  gap: 10px;
  width: min(420px, 100%);
}

.status-item {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
}

.status-value {
  display: block;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--teal-dark);
}

.status-label {
  display: block;
  margin-top: 2px;
  font-size: 0.75rem;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.tab {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
}

.tab.is-active {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.layout {
  display: grid;
  gap: 14px;
}

.two-column {
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
}

.listening-layout {
  grid-template-columns: minmax(0, 1fr) minmax(330px, 420px);
}

.dictation-layout {
  grid-template-columns: minmax(0, 1fr) minmax(330px, 420px);
}

.cloud-layout {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.cloud-overview {
  grid-column: 1 / -1;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

.panel h2 {
  font-size: 1rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.icon-button,
.primary-button,
.ghost-button,
.mini-button,
.icon-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

.icon-button {
  gap: 7px;
  padding: 0 12px;
}

.primary-button,
.ghost-button {
  padding: 0 14px;
}

.primary-button {
  border-color: rgba(8, 122, 114, 0.3);
  color: var(--teal-dark);
}

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

.primary-button.danger {
  border-color: rgba(197, 64, 64, 0.3);
  color: var(--red);
}

.ghost-button {
  background: transparent;
}

.icon-button.is-active {
  border-color: var(--teal);
  background: var(--panel-strong);
  color: var(--teal-dark);
}

.icon-only {
  width: 42px;
  padding: 0;
  font-size: 1.25rem;
}

.icon-only.danger {
  color: var(--red);
}

.icon-button.danger {
  border-color: rgba(197, 64, 64, 0.28);
  color: var(--red);
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 42px;
  gap: 8px;
  padding: 14px 16px 0;
}

.bulk-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 10px 16px 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
}

.bulk-row strong {
  color: var(--teal-dark);
  white-space: nowrap;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  outline: none;
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 12px;
  line-height: 1.55;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(8, 122, 114, 0.12);
}

.term-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 254px);
  min-height: 320px;
  overflow: auto;
  padding: 14px 16px 16px;
}

.term-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.term-card.is-selected {
  border-color: var(--teal);
  background: #f2fbf9;
}

.term-card.is-checked {
  border-color: rgba(49, 93, 156, 0.45);
  background: #f3f7fc;
}

.term-check-wrap {
  display: none;
  align-items: center;
  justify-content: center;
  width: 28px;
}

.term-list.is-selecting .term-check-wrap {
  display: flex;
}

.term-check {
  width: 20px;
  min-height: 20px;
  margin: 0;
  accent-color: var(--teal);
}

.term-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.term-card h3 {
  overflow-wrap: anywhere;
  font-size: 1rem;
}

.term-meta,
.term-meaning {
  margin: 5px 0 0;
  overflow-wrap: anywhere;
  font-size: 0.86rem;
}

.mini-button {
  min-width: 58px;
  padding: 0 10px;
  color: var(--blue);
}

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

.editor-panel {
  align-self: start;
}

.editor-form {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.editor-form label,
.settings-grid label,
.cloud-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.editor-form input,
.editor-form textarea,
.settings-grid input,
.settings-grid select,
.cloud-form input,
.cloud-form select {
  color: var(--text);
  font-weight: 500;
}

.cloud-form {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.cloud-step-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 16px;
}

.cloud-step {
  display: grid;
  gap: 6px;
  min-height: 118px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
}

.cloud-step span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.cloud-step strong {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--teal-dark);
  font-size: 1rem;
}

.cloud-step p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.cloud-note {
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.share-code-box {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f7faf9;
}

.share-code-box span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.share-code-box strong {
  overflow-wrap: anywhere;
  color: var(--teal-dark);
}

.cloud-list {
  display: grid;
  gap: 10px;
  max-height: 420px;
  overflow: auto;
  padding: 16px;
}

.cloud-list-item {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.cloud-list-item strong {
  overflow-wrap: anywhere;
}

.cloud-list-item p {
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
  font-size: 0.9rem;
  line-height: 1.45;
}

.hidden-file {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.import-box {
  min-height: 420px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
}

.import-actions {
  padding: 14px 16px 16px;
}

.preview-table-wrap {
  max-height: 520px;
  overflow: auto;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.9rem;
}

.preview-table th,
.preview-table td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.preview-table th {
  position: sticky;
  top: 0;
  background: #f7faf9;
  color: var(--muted);
  font-size: 0.78rem;
}

.player-panel {
  display: grid;
  min-height: 560px;
  align-content: center;
  justify-items: center;
  padding: 26px;
}

.now-playing {
  width: min(760px, 100%);
  text-align: center;
}

.pulse-bars {
  display: grid;
  grid-template-columns: repeat(4, 12px);
  align-items: end;
  justify-content: center;
  gap: 8px;
  height: 54px;
  margin-bottom: 22px;
}

.pulse-bars span {
  display: block;
  height: 18px;
  border-radius: 4px;
  background: var(--teal);
  opacity: 0.75;
  transform-origin: bottom;
}

.is-speaking .pulse-bars span:nth-child(1) {
  animation: barPulse 0.9s infinite;
}

.is-speaking .pulse-bars span:nth-child(2) {
  animation: barPulse 0.75s infinite 0.1s;
}

.is-speaking .pulse-bars span:nth-child(3) {
  animation: barPulse 0.8s infinite 0.16s;
}

.is-speaking .pulse-bars span:nth-child(4) {
  animation: barPulse 0.95s infinite 0.08s;
}

@keyframes barPulse {
  0%,
  100% {
    transform: scaleY(0.7);
  }

  50% {
    transform: scaleY(2.15);
  }
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.now-playing h2 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: clamp(2rem, 5vw, 4.6rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.phonetic {
  min-height: 1.45em;
  margin: 16px 0 0;
  font-size: 1.18rem;
}

.meaning {
  max-width: 720px;
  min-height: 2.6em;
  margin: 14px auto 0;
  overflow-wrap: anywhere;
  font-size: 1.08rem;
  line-height: 1.55;
}

.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 34px;
}

.round-button {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--teal-dark);
  font-size: 1.5rem;
  font-weight: 800;
}

.round-button.main {
  width: 70px;
  height: 70px;
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.settings-panel {
  align-self: start;
}

.settings-grid {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.toggle-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 0 16px 16px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-weight: 700;
}

.toggle input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--teal);
}

.queue {
  display: grid;
  gap: 8px;
  max-height: 256px;
  overflow: auto;
  padding: 0 16px 16px;
}

.queue-item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.86rem;
}

.queue-item.is-current {
  border-color: var(--teal);
  background: #f2fbf9;
  color: var(--text);
}

.dictation-card {
  min-height: 560px;
  padding: 22px;
}

.dictation-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.score-pill {
  min-height: 34px;
  padding: 7px 12px;
  border-radius: 999px;
  background: #edf2fa;
  color: var(--blue);
  font-weight: 800;
}

.dictation-prompt {
  display: grid;
  justify-items: center;
  gap: 18px;
  margin: 72px auto 36px;
  text-align: center;
}

#hintText {
  min-height: 1.5em;
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 1.05rem;
}

.answer-input {
  min-height: 58px;
  padding: 0 16px;
  font-size: 1.2rem;
  font-weight: 800;
}

.dictation-card .button-row {
  margin-top: 14px;
}

.result-box {
  min-height: 84px;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfc;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.result-box.correct {
  border-color: rgba(8, 122, 114, 0.3);
  background: #effaf7;
  color: var(--teal-dark);
}

.result-box.wrong {
  border-color: rgba(197, 64, 64, 0.3);
  background: #fff2f2;
  color: #8e2626;
}

.dictation-side {
  align-self: start;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 460px;
  overflow: auto;
  padding: 16px;
  font-size: 0.9rem;
}

.history-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.history-item strong {
  display: block;
  color: var(--text);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 980px) {
  .topbar,
  .two-column,
  .listening-layout,
  .dictation-layout,
  .cloud-layout,
  .cloud-step-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .status-strip {
    width: 100%;
  }

  .term-list {
    max-height: none;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding:
      max(10px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  .topbar {
    padding: 12px;
  }

  .brand-mark {
    width: 46px;
    height: 46px;
  }

  .status-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .status-item {
    padding: 8px;
  }

  .tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    position: sticky;
    top: max(8px, env(safe-area-inset-top));
    z-index: 10;
    padding: 2px 0;
    background: var(--bg);
  }

  input,
  textarea,
  select {
    font-size: 16px;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .term-card {
    grid-template-columns: 1fr;
  }

  .term-list.is-selecting .term-card {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .term-list.is-selecting .term-actions {
    grid-column: 1 / -1;
  }

  .bulk-row {
    align-items: stretch;
    flex-direction: column;
  }

  .bulk-row .button-row {
    width: 100%;
  }

  .mini-button {
    width: 100%;
  }

  .player-panel,
  .dictation-card {
    min-height: 460px;
    padding: 18px;
  }

  .round-button {
    width: 50px;
    height: 50px;
  }

  .round-button.main {
    width: 64px;
    height: 64px;
  }

  .toggle-list {
    grid-template-columns: 1fr;
  }

  .dictation-prompt {
    margin-top: 46px;
  }

  .preview-table {
    min-width: 620px;
  }

  .share-code-box {
    grid-template-columns: 1fr;
  }
}
