:root {
  --bg: #f8f4ef;
  --panel: #ffffff;
  --text: #2f251f;
  --muted: #6f6258;
  --line: #ddcec0;
  --brand: #c30000;
  --brand-soft: #f9dddd;
  --accent: #7a6f60;
  --success: #2f7d4f;
  --success-soft: #e3f3e8;
  --danger: #b33632;
  --danger-soft: #f7dcd9;
  --listening: #b8790f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top right, #fffbf6, var(--bg) 55%);
  min-height: 100vh;
}

h1, h2, p {
  margin: 0;
}

button {
  font: inherit;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #faf6f0);
  box-shadow: 0 4px 20px rgba(195, 0, 0, 0.08);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.master-logo {
  width: 56px;
  height: 56px;
  object-fit: contain;
}

.topbar h1 {
  font-size: 1.4rem;
}

.topbar p {
  color: var(--muted);
  font-size: 0.95rem;
}

.mute-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 1.3rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mute-btn:hover {
  border-color: var(--brand);
}

/* ---- Layout ---- */
.layout {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.screen-title {
  font-size: 1.3rem;
  text-align: center;
  margin-bottom: 20px;
  color: var(--brand);
}

/* ---- Buttons (shared) ---- */
.primary {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 14px 22px;
  font-size: 1.05rem;
  font-weight: 600;
  box-shadow: 0 6px 16px rgba(195, 0, 0, 0.25);
}

.primary:hover {
  filter: brightness(1.05);
}

.primary.success {
  background: var(--success);
  box-shadow: 0 6px 16px rgba(47, 125, 79, 0.28);
}

.secondary {
  background: var(--brand-soft);
  color: var(--brand);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 20px;
  font-weight: 600;
}

.ghost {
  background: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 16px;
  color: var(--muted);
}

.ghost.small {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.speak-btn {
  background: var(--brand-soft);
  color: var(--brand);
  border: 1px solid var(--brand);
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 600;
}

.text-link-btn {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  padding: 6px 4px;
  font-size: 0.9rem;
}

.text-link-btn.mode-primary {
  background: var(--success);
  color: #fff;
  text-decoration: none;
  border-radius: 14px;
  padding: 14px 22px;
  font-weight: 600;
  font-size: 1.05rem;
  box-shadow: 0 6px 16px rgba(47, 125, 79, 0.28);
}

/* ---- Practice mode toggle ---- */
.mode-caption {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 10px;
}

.mode-toggle {
  display: flex;
  gap: 12px;
  margin-bottom: 28px;
}

.mode-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  text-align: left;
}

.mode-btn:hover {
  border-color: var(--brand);
}

.mode-btn .mode-icon {
  font-size: 1.6rem;
  line-height: 1;
}

.mode-btn .mode-text {
  display: flex;
  flex-direction: column;
}

.mode-btn .mode-label {
  font-weight: 700;
  color: var(--text);
}

.mode-btn .mode-sub {
  font-size: 0.78rem;
  color: var(--muted);
}

.mode-btn.active {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.mode-btn.active .mode-label {
  color: var(--brand);
}

.mode-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.listen-mode-hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 14px;
}

/* ---- Level select ---- */
.level-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

@media (min-width: 520px) {
  .level-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .level-card:last-child {
    grid-column: 2;
  }
}

.level-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 14px;
  text-align: center;
  box-shadow: 0 4px 14px rgba(195, 0, 0, 0.08);
}

.level-card:hover {
  border-color: var(--brand);
}

.level-card .level-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--brand);
}

.level-card .level-range {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

/* ---- Practice screen ---- */
.practice-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.practice-title {
  font-weight: 700;
  color: var(--brand);
}

.stack-counts {
  display: flex;
  gap: 8px;
}

.stack-chip {
  font-weight: 700;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.9rem;
}

.green-chip {
  background: var(--success-soft);
  color: var(--success);
}

.red-chip {
  background: var(--danger-soft);
  color: var(--danger);
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--brand-soft);
  overflow: hidden;
  margin-bottom: 24px;
}

.progress-fill {
  height: 100%;
  background: var(--brand);
  width: 0%;
  transition: width 0.3s ease;
}

.word-card {
  background: var(--panel);
  border: 3px solid var(--line);
  border-radius: 24px;
  padding: 50px 20px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(195, 0, 0, 0.1);
  transition: border-color 0.25s ease, background 0.25s ease;
}

.word-card.correct {
  border-color: var(--success);
  background: var(--success-soft);
}

.word-card.incorrect {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.word-text {
  font-size: clamp(2.4rem, 10vw, 4.2rem);
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0.5px;
}

.listen-row {
  display: flex;
  justify-content: center;
  margin-top: 28px;
}

.listen-btn {
  min-width: 220px;
  font-size: 1.15rem;
}

.listen-btn.listening {
  background: var(--listening);
  box-shadow: 0 6px 16px rgba(184, 121, 15, 0.35);
  animation: pulse 1s infinite;
}

.listen-btn:disabled,
.listen-btn.maxed-out {
  background: var(--line);
  color: var(--muted);
  box-shadow: none;
  cursor: not-allowed;
  animation: none;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.feedback-row {
  margin-top: 22px;
  text-align: center;
}

.feedback-msg {
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 12px;
}

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

/* ---- Summary screen ---- */
.summary-stacks {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin: 24px 0;
}

.summary-stack {
  flex: 1;
  max-width: 200px;
  border-radius: 18px;
  padding: 22px 10px;
  text-align: center;
  border: 2px solid var(--line);
}

.summary-stack.green-stack {
  background: var(--success-soft);
  border-color: var(--success);
}

.summary-stack.red-stack {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.summary-num {
  font-size: 2.4rem;
  font-weight: 800;
}

.summary-stack.green-stack .summary-num {
  color: var(--success);
}

.summary-stack.red-stack .summary-num {
  color: var(--danger);
}

.summary-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 6px;
}

.summary-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.summary-actions button {
  width: 100%;
  max-width: 320px;
}

/* ---- Footer ---- */
.site-footer {
  text-align: center;
  padding: 24px 20px 40px;
  color: var(--muted);
  font-size: 0.85rem;
}

.site-footer a {
  color: var(--brand);
}
