* { box-sizing: border-box; }

:root {
  --accent: #6366f1;
  --accent2: #8b5cf6;
  --grad: linear-gradient(135deg, #6366f1, #8b5cf6);
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: rgba(17, 24, 39, 0.08);
  --green: #16a34a;
  --yellow: #ca8a04;
  --red: #dc2626;
  --radius: 20px;
  --shadow: 0 1px 3px rgba(17, 24, 39, 0.06), 0 8px 24px rgba(17, 24, 39, 0.05);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Icons ---------- */

.icon {
  width: 1.1em;
  height: 1.1em;
  vertical-align: -0.18em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.icon-fill { fill: currentColor; stroke: none; }

/* ---------- Header ---------- */

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(246, 247, 251, 0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 0.7rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 700; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--grad);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(17, 24, 39, 0.05);
}

/* ---------- Layout ---------- */

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem 1rem 6.5rem; /* keep content clear of the tab bar */
}

/* ---------- Bottom tab bar ---------- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  max-width: 640px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 0.35rem 0.4rem calc(0.35rem + env(safe-area-inset-bottom));
}

.tabbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  border: none;
  background: none;
  box-shadow: none;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.4rem 0;
  border-radius: 12px;
}
.tabbar button .icon { width: 1.45em; height: 1.45em; }
.tabbar button.active { color: var(--accent); }
.tabbar button:active { transform: none; }

.section-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 1.6rem 0 0.7rem;
}
.section-label:first-child { margin-top: 0.4rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem;
  margin: 0.8rem 0;
}

/* ---------- Buttons ---------- */

button {
  font: inherit;
  font-weight: 600;
  padding: 0.75rem 1.15rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: default; transform: none; }

button.primary {
  background: var(--grad);
  border: none;
  color: white;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}
button.primary:disabled { box-shadow: none; }

button.recording {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  border: none;
  color: white;
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.4);
  animation: rec-pulse 1.6s ease-in-out infinite;
}
@keyframes rec-pulse {
  0%, 100% { box-shadow: 0 4px 14px rgba(220, 38, 38, 0.4); }
  50% { box-shadow: 0 4px 22px rgba(220, 38, 38, 0.65); }
}

button.link {
  border: none;
  background: none;
  box-shadow: none;
  color: var(--accent);
  padding: 0.3rem 0.2rem;
  font-weight: 600;
}

button.full { width: 100%; margin-top: 0.7rem; }

/* ---------- Chapter cards ---------- */

.lesson-grid { display: grid; gap: 0.7rem; }

.lesson-card {
  display: block;
  text-align: left;
  width: 100%;
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.lesson-card:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(17, 24, 39, 0.08), 0 12px 32px rgba(17, 24, 39, 0.07); }
.lesson-card.complete { border-color: rgba(22, 163, 74, 0.35); }

.lesson-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}

.chapter-num {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.chapter-count {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--bg);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
}

.chapter-done {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--green);
  background: rgba(22, 163, 74, 0.1);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.lesson-title { font-weight: 700; font-size: 1rem; }
.lesson-desc { color: var(--muted); font-size: 0.85rem; margin-top: 0.2rem; font-weight: 400; }

.chapter-progress {
  height: 6px;
  background: var(--bg);
  border-radius: 999px;
  margin-top: 0.7rem;
  overflow: hidden;
}
.chapter-bar {
  height: 100%;
  background: var(--grad);
  border-radius: 999px;
  transition: width 0.4s ease;
}
.lesson-card.complete .chapter-bar { background: var(--green); }

/* ---------- Practice view ---------- */

.practice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.3rem;
}

.pill-count {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
}

.practice-heading { font-size: 1.05rem; margin: 0.6rem 0 0.4rem; }

.practice-card { text-align: center; }

.practice-text {
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.45;
  margin: 0.4rem 0 0.3rem;
  letter-spacing: -0.01em;
}

.tip { color: var(--muted); font-size: 0.9rem; margin: 0.3rem 0 0; }

#wave {
  width: 100%;
  height: 56px;
  display: block;
  margin-top: 0.8rem;
  border-radius: 12px;
  background: var(--bg);
}

.controls { display: flex; gap: 0.6rem; margin-top: 0.8rem; }
.controls button { flex: 1; }
.nav-controls { margin-top: 0.4rem; }

.record-big {
  padding: 1rem 1.2rem;
  font-size: 1.05rem;
}
.record-big .icon { width: 1.25em; height: 1.25em; }

.status { min-height: 1.2em; color: var(--muted); font-size: 0.9rem; margin: 0.7rem 0 0; }
.status.recording { color: var(--red); font-weight: 600; }
.status.error { color: var(--red); }

/* ---------- Results ---------- */

.scores { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.9rem; }

.score-chip {
  background: var(--bg);
  border-radius: 14px;
  padding: 0.5rem 0.85rem;
  text-align: center;
  flex: 1;
  min-width: 70px;
}
.score-chip .num { font-size: 1.35rem; font-weight: 800; display: block; letter-spacing: -0.02em; }
.strict-chip.good .num { color: var(--green); }
.strict-chip.ok .num { color: var(--yellow); }
.strict-chip.bad .num { color: var(--red); }
.strict-chip { border: 1px solid var(--line); }
.score-chip .label { font-size: 0.65rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.word {
  cursor: pointer;
  border-bottom: 3px solid transparent;
  padding: 0 1px;
  border-radius: 2px;
}
.word.good { border-bottom-color: var(--green); }
.word.ok { border-bottom-color: var(--yellow); color: var(--yellow); }
.word.bad { border-bottom-color: var(--red); color: var(--red); }
.word.omitted { opacity: 0.4; text-decoration: line-through; }

.ph-good { color: var(--green); }
.ph-ok { color: var(--yellow); }
.ph-bad { color: var(--red); font-weight: 700; }

/* ---------- Word detail panel ---------- */

.word-detail { text-align: left; }

.wd-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.6rem 0 0.5rem;
  border-top: 1px solid var(--bg);
  margin-top: 0.4rem;
}
.wd-head strong { font-size: 1.15rem; }
.wd-spacer { flex: 1; }

.ph-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.3rem 0;
}

.ph-chip {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  box-shadow: none;
}
.ph-chip .icon { width: 0.95em; height: 0.95em; }
.ph-chip.ph-good { color: var(--green); border-color: rgba(22, 163, 74, 0.3); }
.ph-chip.ph-ok { color: var(--yellow); border-color: rgba(202, 138, 4, 0.3); }
.ph-chip.ph-bad { color: var(--red); border-color: rgba(220, 38, 38, 0.3); }
.ph-yours { color: var(--accent); border-color: rgba(99, 102, 241, 0.3); }

.ph-score { font-weight: 800; font-size: 0.9rem; min-width: 2ch; }
.ph-you { flex: 1; font-size: 0.85rem; color: var(--red); }

/* ---------- Coaching ---------- */

.coaching { margin-top: 0.9rem; }
.coaching h3 {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}
.coach-item {
  background: var(--bg);
  border-radius: 14px;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
  text-align: left;
}
.coach-tip { color: var(--muted); font-size: 0.85rem; margin-top: 0.3rem; }
.coach-ok {
  color: var(--green);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* ---------- Progress panel ---------- */

#progress-box { margin-top: 0; }
#progress-box h3 { font-size: 0.95rem; margin: 1rem 0 0.4rem; }

.recent-row {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--bg);
  font-size: 0.9rem;
}
.recent-row:last-child { border-bottom: none; }
.recent-row span:first-child { color: var(--muted); white-space: nowrap; font-size: 0.8rem; }
.recent-text {
  flex: 1;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-row.clickable { cursor: pointer; }
.recent-row.clickable:hover .recent-text { color: var(--accent); }

.sum-up {
  color: var(--green);
  background: rgba(22, 163, 74, 0.1);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
}

.take-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}
.take-text { font-size: 1.15rem; text-align: left; }
#summary-box h3, #today-box h3 { font-size: 0.95rem; margin: 1rem 0 0.4rem; }

/* ---------- Inputs ---------- */

textarea {
  width: 100%;
  font: inherit;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  resize: vertical;
  background: var(--bg);
  transition: border-color 0.15s ease, background 0.15s ease;
}
textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--card);
}

.hint { color: var(--muted); font-size: 0.85rem; }

/* ---------- Custom tab ---------- */

input[type="text"] {
  width: 100%;
  font: inherit;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
  margin-bottom: 0.5rem;
  transition: border-color 0.15s ease, background 0.15s ease;
}
input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--card);
}

.custom-card { cursor: pointer; }
.del-btn { color: var(--red); font-size: 0.8rem; padding: 0; }

.topic-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--bg);
}
.topic-row:last-child { border-bottom: none; }
.topic-name { font-weight: 600; }
.topic-row .link { color: var(--red); font-size: 0.8rem; }

.topic-add { display: flex; gap: 0.5rem; margin-top: 0.6rem; }
.topic-add input { flex: 1; margin-bottom: 0; }
.topic-add button { flex-shrink: 0; }

#tab-custom code {
  background: var(--bg);
  border-radius: 6px;
  padding: 0.05rem 0.35rem;
  font-size: 0.8rem;
}
