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

:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1d1d1f;
  --text-muted: #86868b;
  --border: #d2d2d7;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --danger: #ff3b30;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app-header {
  text-align: center;
  padding: 2.5rem 1rem 1.5rem;
}

.header-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.app-logo {
  height: 20rem;
  width: auto;
}

.history-buttons {
  display: flex;
  gap: 0.25rem;
}

.history-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 2rem;
  height: 2rem;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, background 0.2s, opacity 0.2s;
}

.history-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--bg);
}

.history-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

a.history-btn {
  text-decoration: none;
}

.app-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #0e1f43;
}

.app-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.app-container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1rem 3rem;
}

#lines-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.lyric-line {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s;
}

.lyric-line:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.drag-handle {
  cursor: grab;
  color: var(--border);
  font-size: 1.2rem;
  user-select: none;
  padding: 0 0.15rem;
  line-height: 1;
  transition: color 0.2s;
}

.drag-handle:hover {
  color: var(--text-muted);
}

.drag-handle:active {
  cursor: grabbing;
}

.lyric-line.dragging {
  opacity: 0.4;
}

.lang-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
  font-size: 1.2rem;
  cursor: pointer;
  text-align: center;
  min-width: 2.5rem;
  transition: border-color 0.2s;
}

.lang-select:hover {
  border-color: var(--accent);
}

.lang-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

.lyric-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 1rem;
  color: var(--text);
  padding: 0.4rem 0;
  outline: none;
  font-family: inherit;
}

.lyric-input::placeholder {
  color: var(--text-muted);
}

.syllable-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg);
  border-radius: 999px;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  white-space: nowrap;
}

.syllable-count:empty {
  display: none;
}

.delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
  line-height: 1;
}

.delete-btn:hover {
  color: var(--danger);
  background: rgba(255, 59, 48, 0.08);
}

.ipa-display {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0.25rem 0 0 4.25rem;
  min-height: 1.4em;
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  transition: font-weight 0.2s;
}

.rhyme-match {
  font-weight: 700;
  color: var(--text);
}


.ipa-unknown {
  opacity: 0.5;
  font-style: italic;
}

.ipa-loading {
  color: var(--text-muted);
  font-style: italic;
}

.add-line-btn {
  display: block;
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.7rem;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.95rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.add-line-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.header-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* About modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

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

.modal {
  background: var(--surface);
  border-radius: 14px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 2rem;
  position: relative;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s;
}

.modal-close:hover {
  background: var(--bg);
  color: var(--text);
}

.modal h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
}

.modal h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 1.25rem;
  margin-bottom: 0.4rem;
}

.modal p {
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 0.5rem;
}

.modal ul {
  padding-left: 1.25rem;
  margin-bottom: 0.5rem;
}

.modal li {
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 0.25rem;
}

.modal kbd {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.8rem;
  font-family: inherit;
}

.modal code {
  background: var(--bg);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-size: 0.85rem;
}

.modal-footer {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: 1.25rem;
}

.modal-footer p {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ── Suggest button ──────────────────────────────────────────────────────── */
.suggest-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
  line-height: 1;
  flex-shrink: 0;
}

.suggest-btn:hover {
  color: var(--accent);
  background: rgba(0, 113, 227, 0.08);
}

.suggest-btn.active {
  color: var(--accent);
}

/* ── Suggest panel ───────────────────────────────────────────────────────── */
.suggest-panel {
  padding: 0.55rem 0.75rem 0.65rem 4.25rem;
  border-top: 1px solid var(--border);
  margin-top: 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* ── Slider row ──────────────────────────────────────────────────────────── */
.suggest-slider-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.suggest-target-input {
  border: none;
  border-bottom: 1.5px solid var(--border);
  background: transparent;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent);
  width: 12ch;
  min-width: 3ch;
  max-width: 14ch;
  padding: 0 0.1rem 0.05rem;
  outline: none;
  text-align: center;
  transition: border-color 0.15s, width 0.1s;
}

.suggest-target-input:focus {
  border-bottom-color: var(--accent);
}

.suggest-slider-sep {
  color: var(--border);
  font-size: 0.9rem;
  flex-shrink: 0;
}

.suggest-slider-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

.suggest-slider {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
  min-width: 80px;
}

.suggest-panel[hidden] {
  display: none;
}

.suggest-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.suggest-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  white-space: nowrap;
}

.suggest-chip:hover {
  border-color: var(--accent);
  background: rgba(0, 113, 227, 0.06);
}

.suggest-chip:hover .chip-word {
  color: var(--accent);
}

.suggest-chip.copied {
  border-color: #34c759;
  background: rgba(52, 199, 89, 0.08);
}

.suggest-chip.copied .chip-word {
  color: #34c759;
}

.chip-score {
  font-size: 0.68rem;
  font-weight: 700;
  margin-left: 0.3rem;
  opacity: 0.8;
}

.chip-rhyme {
  color: #d4600a;
}

.chip-sem {
  color: #7c3aed;
}

.suggest-loading,
.suggest-empty,
.suggest-error {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
}

.suggest-error {
  color: var(--danger);
  font-style: normal;
}

@media (max-width: 480px) {
  .app-header h1 {
    font-size: 1.4rem;
  }

  .lyric-line {
    padding: 0.6rem 0.75rem;
  }

  .ipa-display {
    padding-left: 3rem;
  }
}
