/* ========== Design Tokens ========== */
:root {
  --bg: #f0f2f5;
  --card-bg: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #5a6070;
  --text-muted: #8e95a5;
  --border: #dfe2ea;
  --border-light: #eceef3;
  --primary: #5b6abf;
  --primary-hover: #4a58a8;
  --primary-light: #eef0fb;
  --primary-glow: rgba(91, 106, 191, 0.15);
  --danger: #d94f5c;
  --danger-hover: #c4404d;
  --success: #3aaf6a;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08);
  --radius: 14px;
  --radius-sm: 8px;
  --radius-xs: 5px;
  --font: "HarmonyOS Sans", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", "Cascadia Code", Consolas,
    monospace;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --card-bg: #1a1d2e;
  --text: #e2e4ea;
  --text-secondary: #9ba1b0;
  --text-muted: #636980;
  --border: #2a2e42;
  --border-light: #232740;
  --primary: #7b8ae0;
  --primary-hover: #6a79cf;
  --primary-light: #1e2240;
  --primary-glow: rgba(123, 138, 224, 0.12);
  --danger: #f06575;
  --danger-hover: #e05060;
  --success: #4cd68a;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* ========== Reset ========== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.hidden {
  display: none !important;
}

/* ========== Layout ========== */
.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 28px 20px 40px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding: 0 4px;
}

header h1 {
  font-size: 1.5em;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
}

header h1 span {
  color: var(--primary);
}

.btn-theme {
  border: none;
  background: var(--primary-light);
  font-size: 1.2em;
  width: 40px;
  height: 40px;
}

/* ========== Cards ========== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-light);
  transition: background 0.3s, box-shadow 0.3s, border-color 0.3s;
}

.card h2 {
  font-size: 0.88em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border-light);
}

/* ========== Buttons ========== */
.btn {
  height: 38px;
  padding: 0 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: white;
  font-size: 0.88em;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn:hover {
  background: var(--primary-hover);
  box-shadow: 0 2px 8px var(--primary-glow);
}

.btn:active {
  transform: scale(0.97);
}

.btn-danger {
  background: var(--danger);
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-icon {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--card-bg);
  color: var(--text-secondary);
  font-size: 1.2em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  border: 1.5px solid var(--border);
}

.btn-icon:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-icon:active {
  transform: scale(0.92);
}

.btn-play {
  width: 56px;
  height: 56px;
  font-size: 1.4em;
  background: var(--primary);
  color: white;
  border: none;
  box-shadow: 0 4px 16px var(--primary-glow);
}

.btn-play:hover {
  background: var(--primary-hover);
  box-shadow: 0 6px 20px var(--primary-glow);
  transform: scale(1.04);
}

.btn-play:active {
  transform: scale(0.95);
}

.btn-sm {
  height: 30px;
  padding: 0 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.82em;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-sm:hover,
.btn-sm.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 2px 6px var(--primary-glow);
}

/* ========== Inputs ========== */
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95em;
  font-family: inherit;
  line-height: 1.6;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

textarea::placeholder {
  color: var(--text-muted);
}

select,
input[type="text"] {
  height: 36px;
  padding: 0 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg);
  color: var(--text);
  font-size: 0.88em;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: none;
  -webkit-appearance: none;
}

select:focus,
input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.input-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
  flex-wrap: wrap;
}

.input-controls label {
  font-size: 0.88em;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.input-controls select {
  width: auto;
}

/* ========== Delimiter Chips ========== */
.delimiter-section {
  margin-top: 12px;
}

.delimiter-label {
  font-size: 0.88em;
  font-weight: 600;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 8px;
}

.delimiter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.delimiter-chip {
  cursor: pointer;
  user-select: none;
}

.delimiter-chip input[type="checkbox"] {
  display: none;
}

.delimiter-chip span {
  display: inline-block;
  height: 30px;
  padding: 0 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85em;
  font-weight: 600;
  line-height: 28px;
  transition: all 0.15s ease;
}

.delimiter-chip input:checked + span {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.delimiter-chip span:hover {
  border-color: var(--primary);
}

.custom-chip span {
  background: var(--primary-light);
  border-style: dashed;
}

.custom-delimiter-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  align-items: center;
}

.custom-delimiter-row input[type="text"] {
  width: 100px;
  height: 30px;
  font-size: 0.85em;
}

.custom-delimiter-row .btn-sm {
  height: 30px;
}

.input-actions {
  margin-top: 12px;
}

/* ========== Word Preview ========== */
.word-preview {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  font-size: 0.88em;
  color: var(--text-secondary);
  font-weight: 500;
}

.word-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.word-tag {
  padding: 4px 12px;
  background: var(--primary);
  color: white;
  border-radius: 20px;
  font-size: 0.82em;
  font-weight: 600;
}

/* ========== Settings ========== */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-item > label {
  font-size: 0.88em;
  font-weight: 600;
  color: var(--text-secondary);
}

input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 3px;
  outline: none;
  margin: 4px 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px var(--primary-glow);
  transition: transform 0.15s, box-shadow 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 2px 10px var(--primary-glow);
}

input[type="range"]:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.preset-btns,
.repeat-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ========== Toggle Switches ========== */
.toggle-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.88em;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.toggle-label input[type="checkbox"] {
  display: none;
}

.toggle-switch {
  position: relative;
  width: 42px;
  height: 24px;
  background: var(--border);
  border-radius: 12px;
  flex-shrink: 0;
  transition: background 0.2s;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s ease;
}

.toggle-label input:checked + .toggle-switch {
  background: var(--primary);
}

.toggle-label input:checked + .toggle-switch::after {
  transform: translateX(18px);
}

.toggle-label input:disabled + .toggle-switch {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ========== Word List Management ========== */
.wordlist-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.wordlist-controls input[type="text"] {
  flex: 1;
  min-width: 120px;
}

.wordlist-controls select {
  flex: 1;
  min-width: 140px;
}

/* ========== Player Section ========== */
.player-section {
  text-align: center;
}

.current-word {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 20px 0;
  min-height: 64px;
}

#currentWord {
  font-size: 2.8em;
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--primary);
  user-select: none;
  transition: opacity 0.3s, filter 0.3s;
  font-family: var(--font);
}

.word-hidden {
  filter: blur(10px);
  opacity: 0.4;
}

.progress-area {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 14px 0;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--success));
  border-radius: 3px;
  width: 0%;
  transition: width 0.4s ease;
}

#progressText {
  font-size: 0.82em;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 56px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.player-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin: 20px 0;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82em;
  color: var(--text-muted);
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-light);
}

#statusText {
  font-weight: 500;
}

.wake-lock-badge {
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--primary-light);
  font-size: 0.85em;
  font-weight: 500;
}

/* ========== Collapsible List ========== */
.collapsible-header {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
  transition: color 0.15s;
}

.collapsible-header:hover {
  color: var(--primary);
}

.toggle-icon {
  font-size: 0.75em;
  transition: transform 0.3s ease;
}

.collapsible-content {
  margin-top: 14px;
}

.full-word-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.full-word-item {
  padding: 5px 14px;
  background: var(--bg);
  border-radius: 20px;
  font-size: 0.9em;
  font-weight: 500;
  border: 1.5px solid var(--border);
  transition: all 0.25s ease;
  cursor: default;
}

.full-word-item.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  transform: scale(1.06);
  box-shadow: 0 2px 8px var(--primary-glow);
}

.full-word-item.done {
  opacity: 0.4;
  text-decoration: line-through;
}

/* ========== Footer ========== */
footer {
  text-align: center;
  padding: 16px 0 8px;
  color: var(--text-muted);
  font-size: 0.78em;
}

kbd {
  display: inline-block;
  padding: 2px 7px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9em;
  font-family: var(--font-mono);
  font-weight: 500;
  box-shadow: 0 1px 0 var(--border);
  line-height: 1.4;
}

.shortcut-hint {
  line-height: 2.2;
}

/* ========== Responsive ========== */
@media (max-width: 600px) {
  .container {
    padding: 16px 12px 32px;
  }

  header h1 {
    font-size: 1.25em;
  }

  .settings-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  #currentWord {
    font-size: 2em;
    letter-spacing: 4px;
  }

  .wordlist-controls {
    flex-direction: column;
  }

  .wordlist-controls select,
  .wordlist-controls input[type="text"] {
    width: 100%;
    flex: none;
  }

  .player-controls {
    gap: 10px;
  }

  .btn-play {
    width: 50px;
    height: 50px;
    font-size: 1.2em;
  }

  .btn-icon {
    width: 40px;
    height: 40px;
    font-size: 1.05em;
  }

  .card {
    padding: 18px;
  }
}

/* ========== Animations ========== */
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.08); }
}

.playing-pulse {
  animation: pulse 1.2s ease-in-out infinite;
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ========== Selection ========== */
::selection {
  background: var(--primary);
  color: white;
}
