:root {
  --bg: #eef4fb;
  --bg-deep: #dde8f6;
  --surface: rgba(255, 255, 255, 0.76);
  --surface-strong: rgba(255, 255, 255, 0.93);
  --ink: #18242e;
  --muted: #60717d;
  --accent: #c76644;
  --accent-soft: #f1c3af;
  --accent-deep: #9d4b31;
  --green: #3f7a67;
  --green-soft: #d7e7e0;
  --gold: #d7b468;
  --border: rgba(24, 36, 46, 0.1);
  --shadow: 0 22px 60px rgba(58, 82, 112, 0.14);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --sans: "Trebuchet MS", "Segoe UI", sans-serif;
  --serif: "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --body-glow-left: rgba(255, 205, 170, 0.46);
  --body-glow-right: rgba(114, 159, 189, 0.18);
  --ambient-left-color: rgba(225, 129, 90, 0.22);
  --ambient-right-color: rgba(92, 136, 170, 0.16);
  --stat-bg: rgba(255, 255, 255, 0.92);
  --stat-border: rgba(24, 36, 46, 0.08);
  --control-bg: rgba(255, 255, 255, 0.92);
  --control-border: rgba(24, 36, 46, 0.12);
  --control-border-hover: rgba(24, 36, 46, 0.22);
  --editor-bg: rgba(255, 255, 255, 0.95);
  --editor-border: rgba(24, 36, 46, 0.12);
  --face-inset-highlight: rgba(255, 255, 255, 0.78);
  --face-front-bg: linear-gradient(150deg, rgba(255, 248, 243, 0.98), rgba(248, 234, 224, 0.98));
  --face-back-bg: linear-gradient(160deg, rgba(234, 245, 243, 0.98), rgba(217, 233, 243, 0.98));
  --rating-again-bg: rgba(247, 220, 212, 0.96);
  --rating-hard-bg: rgba(245, 233, 201, 0.96);
  --rating-good-bg: rgba(221, 237, 229, 0.96);
  --rating-easy-bg: rgba(213, 231, 241, 0.96);
  --meter-track-bg: rgba(24, 36, 46, 0.08);
  --practice-border: rgba(24, 36, 46, 0.12);
  --practice-bg: rgba(255, 255, 255, 0.86);
  --feedback-success: #2f6f57;
  --feedback-warning: #996515;
  --feedback-error: #9d4b31;
  --input-bg: rgba(255, 255, 255, 0.84);
  --input-focus-ring: rgba(199, 102, 68, 0.18);
  --card-note-border: rgba(24, 36, 46, 0.09);
}

body[data-theme="dark"] {
  --bg: #10161d;
  --bg-deep: #1a2430;
  --surface: rgba(17, 24, 31, 0.82);
  --surface-strong: rgba(22, 30, 39, 0.94);
  --ink: #edf2f4;
  --muted: #aebcc7;
  --accent: #ef8d61;
  --accent-soft: #ffc49c;
  --accent-deep: #ffc49c;
  --green: #86b7a2;
  --green-soft: #1e4137;
  --gold: #d7b161;
  --border: rgba(237, 242, 244, 0.12);
  --shadow: 0 26px 70px rgba(0, 0, 0, 0.38);
  --body-glow-left: rgba(239, 141, 97, 0.18);
  --body-glow-right: rgba(97, 161, 145, 0.14);
  --ambient-left-color: rgba(239, 141, 97, 0.24);
  --ambient-right-color: rgba(97, 161, 145, 0.18);
  --stat-bg: rgba(22, 30, 39, 0.92);
  --stat-border: rgba(237, 242, 244, 0.08);
  --control-bg: rgba(22, 30, 39, 0.92);
  --control-border: rgba(237, 242, 244, 0.12);
  --control-border-hover: rgba(237, 242, 244, 0.28);
  --editor-bg: rgba(16, 22, 29, 0.96);
  --editor-border: rgba(237, 242, 244, 0.12);
  --face-inset-highlight: rgba(255, 255, 255, 0.06);
  --face-front-bg: linear-gradient(150deg, rgba(58, 43, 36, 0.98), rgba(35, 29, 27, 0.98));
  --face-back-bg: linear-gradient(160deg, rgba(29, 63, 57, 0.98), rgba(18, 39, 42, 0.98));
  --rating-again-bg: rgba(101, 57, 48, 0.96);
  --rating-hard-bg: rgba(98, 81, 45, 0.96);
  --rating-good-bg: rgba(47, 88, 72, 0.96);
  --rating-easy-bg: rgba(42, 80, 96, 0.96);
  --meter-track-bg: rgba(237, 242, 244, 0.12);
  --practice-border: rgba(237, 242, 244, 0.14);
  --practice-bg: rgba(14, 20, 26, 0.9);
  --feedback-success: #8bc6ab;
  --feedback-warning: #e4c46b;
  --feedback-error: #ff9f84;
  --input-bg: rgba(10, 16, 22, 0.92);
  --input-focus-ring: rgba(239, 141, 97, 0.28);
  --card-note-border: rgba(237, 242, 244, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  color-scheme: light;
  background:
    radial-gradient(circle at top left, var(--body-glow-left), transparent 30%),
    radial-gradient(circle at bottom right, var(--body-glow-right), transparent 24%),
    linear-gradient(135deg, var(--bg), var(--bg-deep));
  overflow-x: hidden;
  transition: background 220ms ease, color 220ms ease;
}

body[data-theme="dark"] {
  color-scheme: dark;
}

button,
select,
input {
  font: inherit;
}

.ambient {
  position: fixed;
  width: 28rem;
  height: 28rem;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.5;
  pointer-events: none;
}

.ambient-left {
  top: -8rem;
  left: -10rem;
  background: var(--ambient-left-color);
}

.ambient-right {
  right: -8rem;
  bottom: -10rem;
  background: var(--ambient-right-color);
}

.utility-cluster {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 20;
}

.heatmap-utility {
  position: relative;
}

.utility-button {
  width: 3rem;
  height: 3rem;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.calendar-glyph {
  position: relative;
  width: 1.2rem;
  height: 1.05rem;
  display: inline-block;
}

.calendar-glyph-top,
.calendar-glyph-body {
  position: absolute;
  left: 0;
  width: 100%;
  border: 2px solid currentColor;
}

.calendar-glyph-top {
  top: 0;
  height: 0.32rem;
  border-bottom: 0;
  border-radius: 0.3rem 0.3rem 0 0;
}

.calendar-glyph-body {
  top: 0.22rem;
  height: 0.83rem;
  border-radius: 0.18rem;
}

.calendar-glyph::before,
.calendar-glyph::after {
  content: "";
  position: absolute;
  top: -0.18rem;
  width: 0.16rem;
  height: 0.28rem;
  border-radius: 999px;
  background: currentColor;
}

.calendar-glyph::before {
  left: 0.18rem;
}

.calendar-glyph::after {
  right: 0.18rem;
}

.heatmap-popover {
  position: absolute;
  top: calc(100% + 0.75rem);
  left: 0;
  width: min(25rem, calc(100vw - 2rem));
  padding: 1rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  opacity: 0;
  transform: translateY(-0.3rem);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.heatmap-utility:hover .heatmap-popover,
.heatmap-utility:focus-within .heatmap-popover {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.heatmap-popover-head {
  display: grid;
  gap: 0.35rem;
}

.heatmap-title {
  display: block;
  font-family: var(--serif);
  font-size: 1.05rem;
}

.heatmap-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.6;
}

.heatmap-shell {
  margin-top: 0.9rem;
}

.heatmap-months {
  display: grid;
  grid-template-columns: repeat(21, minmax(0, 1fr));
  gap: 0.28rem;
  margin-left: 2.35rem;
  color: var(--muted);
  font-size: 0.72rem;
  min-height: 1rem;
}

.heatmap-body {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem;
  align-items: start;
  margin-top: 0.25rem;
}

.heatmap-weekdays {
  display: grid;
  grid-template-rows: repeat(7, 0.8rem);
  align-items: center;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1;
}

.heatmap-weekdays span:nth-child(1) {
  grid-row: 2;
}

.heatmap-weekdays span:nth-child(2) {
  grid-row: 4;
}

.heatmap-weekdays span:nth-child(3) {
  grid-row: 6;
}

.app-shell {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 5.35rem 0 3rem;
}

.app-frame {
  display: grid;
  grid-template-columns: 13.5rem minmax(0, 1fr);
  gap: 1.4rem;
  align-items: start;
}

.page-stack {
  display: grid;
  gap: 1.4rem;
}

.study-page {
  display: grid;
  gap: 1.4rem;
}

.hero-panel,
.view-switcher,
.control-panel,
.card-panel,
.insight-card,
.profile-card,
.deck-editor-panel {
  backdrop-filter: blur(18px);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.hero-panel {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 1.5rem;
  padding: 1.8rem;
  border-radius: var(--radius-xl);
  animation: lift-in 0.7s ease-out;
}

.eyebrow {
  margin: 0 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.75rem;
  color: var(--accent-deep);
}

.hero-copy h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.8rem, 3vw, 3.2rem);
  line-height: 1.02;
  max-width: 14ch;
}

.hero-text {
  max-width: 56ch;
  color: var(--muted);
  line-height: 1.7;
  margin: 1rem 0 0;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.stat-card {
  padding: 1rem;
  border-radius: var(--radius-lg);
  background: var(--stat-bg);
  border: 1px solid var(--stat-border);
}

.stat-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
}

.stat-value {
  display: block;
  margin-top: 0.35rem;
  font-size: 2rem;
  font-family: var(--serif);
}

.view-switcher {
  position: sticky;
  top: 5.35rem;
  z-index: 12;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: stretch;
  align-self: start;
  padding: 1rem;
  border-radius: var(--radius-lg);
  animation: lift-in 0.82s ease-out;
}

.view-button {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  justify-content: flex-start;
  text-align: left;
}

.view-button-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  flex: 0 0 auto;
}

.view-button-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.view-button.is-active {
  border-color: color-mix(in srgb, var(--accent) 52%, var(--control-border));
  background: color-mix(in srgb, var(--accent) 12%, var(--control-bg));
  color: var(--accent-deep);
}

.control-panel {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
  gap: 0.8rem;
  align-items: end;
  padding: 1rem 1.2rem;
  border-radius: var(--radius-lg);
  animation: lift-in 0.9s ease-out;
}

.toolbar-group {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
}

.toolbar-group label {
  font-size: 0.82rem;
  color: var(--muted);
}

select,
.practice-row input,
.ghost-button,
.icon-button,
.rating-button {
  border: 1px solid var(--control-border);
  border-radius: 999px;
  background: var(--control-bg);
  color: var(--ink);
}

select {
  width: 100%;
  min-width: 0;
  padding: 0.68rem 0.92rem;
}

.practice-row input {
  padding: 0.78rem 1rem;
  background: var(--input-bg);
  color: var(--ink);
}

.practice-row input:focus {
  outline: 2px solid var(--input-focus-ring);
  border-color: var(--accent);
}

.toolbar-actions,
.card-actions,
.rating-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.toolbar-actions {
  display: flex;
  flex-wrap: nowrap;
  grid-column: auto;
  justify-self: end;
  align-self: end;
}

.toolbar-actions .ghost-button {
  width: auto;
  white-space: nowrap;
}

.ghost-button,
.icon-button,
.rating-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.78rem 1rem;
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.ghost-button:hover,
.icon-button:hover,
.rating-button:hover,
select:hover {
  transform: translateY(-1px);
  border-color: var(--control-border-hover);
}

.icon-button.has-shortcut {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
}

.button-shortcut {
  min-width: 2.9rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--control-border);
  background: rgba(255, 255, 255, 0.42);
  font-size: 0.76rem;
  line-height: 1;
}

#autoSpeakButton {
  gap: 0.65rem;
  min-width: 9.75rem;
  justify-content: space-between;
  font-weight: 600;
}

#autoSpeakButton[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--green) 52%, var(--control-border));
  background: color-mix(in srgb, var(--green) 14%, var(--control-bg));
  color: var(--green);
}

.button-main {
  display: inline-flex;
  align-items: center;
  gap: 0.58rem;
  min-width: 0;
}

.button-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  color: currentColor;
  flex: 0 0 auto;
}

.button-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.button-status {
  min-width: 3.1rem;
  padding: 0.24rem 0.62rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, currentColor 40%, transparent);
  background: color-mix(in srgb, currentColor 10%, transparent);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1.1;
  text-transform: uppercase;
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.study-grid {
  display: grid;
  gap: 1.4rem;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.8fr);
}

.study-sidebar {
  display: grid;
  gap: 1rem;
  align-content: start;
}

.stats-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stats-wide {
  grid-column: span 2;
}

.stats-hero-card {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at top right, rgba(215, 180, 104, 0.2), transparent 35%),
    radial-gradient(circle at left center, rgba(199, 102, 68, 0.16), transparent 32%),
    linear-gradient(145deg, color-mix(in srgb, var(--surface) 92%, rgba(255, 255, 255, 0.03)), var(--surface));
  border-color: color-mix(in srgb, var(--gold) 18%, var(--border));
}

.stats-hero-card::after {
  content: "";
  position: absolute;
  inset: auto -8% -38% auto;
  width: 15rem;
  height: 15rem;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(215, 180, 104, 0.16), transparent 70%);
  pointer-events: none;
}

.stats-hero-top {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) auto;
  gap: 1rem;
  align-items: start;
}

.stats-hero-copy h2 {
  margin-bottom: 0.45rem;
  font-size: clamp(1.35rem, 2.6vw, 2.2rem);
  font-family: var(--serif);
}

.stats-hero-text {
  max-width: 58ch;
  color: var(--muted);
}

.stats-badge {
  align-self: start;
  justify-self: end;
  padding: 0.5rem 0.8rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--gold) 44%, var(--accent) 20%);
  background: linear-gradient(135deg, rgba(215, 180, 104, 0.16), rgba(199, 102, 68, 0.12));
  color: var(--accent-deep);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.stats-badge-subtle {
  border-color: var(--stat-border);
  background: var(--stat-bg);
  color: var(--muted);
}

.reward-grid {
  position: relative;
  display: grid;
  gap: 0.85rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 1.2rem;
}

.reward-card {
  position: relative;
  display: grid;
  gap: 0.28rem;
  padding: 1rem;
  border-radius: calc(var(--radius-md) + 0.1rem);
  border: 1px solid color-mix(in srgb, var(--gold) 18%, var(--stat-border));
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 48%),
    var(--stat-bg);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    0 10px 22px rgba(10, 14, 18, 0.08);
}

.reward-card::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 0.18rem;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  opacity: 0.9;
}

.reward-label {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.reward-value {
  font-family: var(--serif);
  font-size: clamp(1.55rem, 2.6vw, 2.3rem);
  line-height: 1;
}

.reward-note {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.reward-track-card {
  position: relative;
  display: grid;
  gap: 0.65rem;
  margin-top: 1rem;
  padding: 1rem 1.05rem;
  border-radius: var(--radius-md);
  border: 1px solid color-mix(in srgb, var(--gold) 20%, var(--stat-border));
  background:
    linear-gradient(135deg, rgba(215, 180, 104, 0.08), rgba(199, 102, 68, 0.06)),
    var(--stat-bg);
}

.reward-track-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
}

.reward-track-label {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.reward-track-title {
  display: block;
  margin-top: 0.12rem;
  font-size: 1rem;
}

.reward-track-progress {
  color: var(--accent-deep);
  font-weight: 600;
  white-space: nowrap;
}

.reward-track-bar {
  height: 0.65rem;
  overflow: hidden;
  border-radius: 999px;
  background: var(--meter-track-bg);
}

.reward-track-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  box-shadow: 0 0 16px rgba(215, 180, 104, 0.28);
  transition: width 220ms ease;
}

.reward-track-note,
.stats-section-note {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.6;
}

.topic-meter-toggle {
  position: relative;
  z-index: 1;
  margin: -1.4rem auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.08rem;
  width: 100%;
  padding: 0.45rem 1rem 0.2rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 500;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  transition: color 180ms ease, transform 180ms ease, opacity 180ms ease;
}

.topic-meter-toggle[aria-expanded="true"] {
  margin-top: 0.7rem;
}

.topic-meter-toggle:hover {
  color: var(--ink);
}

.topic-meter-toggle-label {
  letter-spacing: 0.02em;
}

.topic-meter-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 0.8rem;
  opacity: 0.72;
}

.topic-meter-toggle-icon::before {
  content: "";
  width: 0.46rem;
  height: 0.46rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  border-radius: 0.08rem;
  transform: rotate(45deg) translateY(-0.04rem);
  transition: transform 180ms ease, opacity 180ms ease;
}

.topic-meter-toggle[aria-expanded="true"] .topic-meter-toggle-icon::before {
  transform: rotate(-135deg) translate(-0.04rem, -0.02rem);
}

.topic-meter-preview {
  position: relative;
  overflow: hidden;
  transition: max-height 220ms ease;
}

.topic-meter-preview[data-expanded="false"] {
  max-height: 23.5rem;
}

.topic-meter-preview[data-expanded="true"] {
  max-height: 120rem;
}

.topic-meter-preview[data-expanded="false"]::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 5.5rem;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0),
    color-mix(in srgb, var(--surface) 18%, transparent) 24%,
    var(--surface)
  );
  pointer-events: none;
}

.profile-card {
  padding: 1.5rem;
  border-radius: var(--radius-xl);
  animation: lift-in 1s ease-out;
}

.profile-card h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.5rem, 3vw, 2.4rem);
}

.profile-text,
.profile-note {
  margin: 1rem 0 0;
  max-width: 64ch;
  color: var(--muted);
  line-height: 1.75;
}

.profile-guest-tools {
  margin-top: 1.25rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--border);
}

.profile-tools-label {
  margin: 0 0 0.45rem;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 600;
}

.profile-status-card {
  margin-top: 1.25rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface-strong) 72%, transparent);
}

.profile-status-card h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.15rem, 2vw, 1.45rem);
}

.profile-status-text {
  margin: 0.75rem 0 0;
  color: var(--muted);
  line-height: 1.7;
  max-width: 62ch;
}

.profile-display-name {
  margin-top: 1.15rem;
}

.profile-display-name-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  flex-wrap: wrap;
}

.profile-display-name-head .field-label {
  margin-bottom: 0;
}

.field-label {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.required-mark {
  color: var(--accent-deep);
}

.profile-display-name input {
  width: min(26rem, 100%);
}

.profile-actions-compact {
  margin-top: 0.95rem;
}

.profile-note[data-state="success"] {
  color: var(--feedback-success);
}

.profile-note[data-state="warning"] {
  color: var(--feedback-warning);
}

.profile-note.is-flashing {
  animation: profile-flash 820ms ease-out;
}

.profile-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.4rem;
}

.subtle-button {
  padding: 0.62rem 0.95rem;
  font-size: 0.88rem;
}

.google-button-host {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  align-self: flex-start;
  color-scheme: light;
  background: transparent;
}

.profile-danger {
  margin-top: 1.2rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border);
}

.profile-danger-note {
  margin: 0.75rem 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.danger-button {
  border-color: color-mix(in srgb, var(--accent) 48%, var(--control-border));
  color: var(--accent-deep);
}

@keyframes profile-flash {
  0% {
    background: color-mix(in srgb, var(--feedback-success) 18%, transparent);
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--feedback-success) 26%, transparent);
  }

  45% {
    background: color-mix(in srgb, var(--feedback-success) 14%, transparent);
    box-shadow: 0 0 0 10px color-mix(in srgb, var(--feedback-success) 0%, transparent);
  }

  100% {
    background: transparent;
    box-shadow: 0 0 0 0 transparent;
  }
}

.deck-editor-panel {
  padding: 1.4rem;
  border-radius: var(--radius-xl);
  animation: lift-in 1.2s ease-out;
}

.deck-editor-header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: start;
}

.deck-editor-header h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.5rem, 3vw, 2.1rem);
}

.deck-editor-text,
.deck-editor-status {
  color: var(--muted);
  line-height: 1.65;
}

.deck-editor-text {
  max-width: 62ch;
  margin: 0.7rem 0 0;
}

.deck-editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.deck-editor-label {
  display: block;
  margin-top: 1rem;
  margin-bottom: 0.45rem;
  color: var(--muted);
  font-size: 0.88rem;
}

#deckEditor {
  width: 100%;
  min-height: 420px;
  padding: 1rem;
  resize: vertical;
  border-radius: var(--radius-lg);
  border: 1px solid var(--editor-border);
  background: var(--editor-bg);
  color: var(--ink);
  font: 0.95rem/1.55 Consolas, "Courier New", monospace;
}

.deck-editor-status {
  margin: 0.75rem 0 0;
}

.deck-editor-status[data-state="error"] {
  color: var(--accent-deep);
}

.deck-editor-status[data-state="success"] {
  color: var(--green);
}

.card-panel {
  padding: 1.4rem;
  border-radius: var(--radius-xl);
  animation: lift-in 1.05s ease-out;
}

.card-topline {
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  align-items: start;
}

.card-meta {
  min-width: 0;
  flex: 1 1 auto;
}

.card-kicker,
.card-progress {
  margin: 0;
}

.card-kicker {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  color: var(--accent-deep);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.74rem;
}

.card-category-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-level-badge {
  flex: 0 0 auto;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 38%, var(--control-border));
  background: color-mix(in srgb, var(--accent) 10%, var(--control-bg));
  letter-spacing: 0.08em;
}

.card-level-badge:empty {
  display: none;
}

.card-progress {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 0.35rem;
  color: var(--muted);
}

.card-actions {
  flex: 0 0 auto;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.flashcard {
  position: relative;
  width: 100%;
  min-height: 420px;
  margin-top: 1rem;
  border: 0;
  background: transparent;
  cursor: pointer;
  perspective: 1200px;
  text-align: left;
}

.flashcard.is-locked {
  cursor: default;
}

.flashcard .face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 2rem;
  border-radius: calc(var(--radius-xl) - 4px);
  backface-visibility: hidden;
  transition: transform 0.65s ease;
  box-shadow: inset 0 1px 0 var(--face-inset-highlight);
  color: var(--ink);
}

.face-front {
  background: var(--face-front-bg);
}

.face-back {
  background: var(--face-back-bg);
  transform: rotateY(180deg);
}

.flashcard.is-flipped .face-front {
  transform: rotateY(-180deg);
}

.flashcard.is-flipped .face-back {
  transform: rotateY(0deg);
}

.flashcard.is-resetting .face {
  transition: none;
}

.face-label {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
  color: var(--muted);
}

.face-text {
  margin: auto 0;
  font-family: var(--serif);
  font-size: clamp(2rem, 5vw, 3.6rem);
  line-height: 1.04;
  max-width: 13ch;
}

.face-hint,
.pronunciation,
.example,
.example-translation,
.card-note {
  color: var(--muted);
  line-height: 1.55;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.pronunciation {
  margin-top: 1rem;
  font-style: italic;
}

.example {
  margin-top: 0.75rem;
}

.example-translation,
.card-note {
  margin-top: 0.65rem;
}

.card-note {
  padding-top: 0.85rem;
  border-top: 1px solid var(--card-note-border);
}

.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 20;
  width: 3rem;
  height: 3rem;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 600;
}

.practice-panel {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--practice-border);
  background: var(--practice-bg);
}

.practice-label {
  display: block;
  font-size: 0.84rem;
  color: var(--muted);
}

.practice-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.65rem;
  margin-top: 0.6rem;
}

.character-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.char-button {
  min-width: 2.25rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--control-border);
  border-radius: 999px;
  background: var(--control-bg);
  color: var(--ink);
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.char-button:hover {
  transform: translateY(-1px);
  border-color: var(--control-border-hover);
}

.practice-feedback {
  min-height: 1.5rem;
  margin: 0.75rem 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.practice-feedback[data-state="success"] {
  color: var(--feedback-success);
}

.practice-feedback[data-state="warning"] {
  color: var(--feedback-warning);
}

.practice-feedback[data-state="error"] {
  color: var(--feedback-error);
}

.rating-row {
  margin-top: 1rem;
}

.rating-button {
  flex: 1 1 120px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.rating-key {
  min-width: 1.8rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--control-border);
  background: rgba(255, 255, 255, 0.42);
  font-size: 0.78rem;
  line-height: 1;
}

.rating-again {
  background: var(--rating-again-bg);
}

.rating-hard {
  background: var(--rating-hard-bg);
}

.rating-good {
  background: var(--rating-good-bg);
}

.rating-easy {
  background: var(--rating-easy-bg);
}

.insight-card {
  padding: 1.2rem;
  border-radius: var(--radius-lg);
  animation: lift-in 1.15s ease-out;
}

.insight-card h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.insight-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.insight-card-head h2 {
  margin: 0;
}

.inline-select {
  display: inline-grid;
  gap: 0.2rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.inline-select select {
  min-width: 8.4rem;
  padding: 0.45rem 0.7rem;
  font-size: 0.88rem;
}

.insight-card p,
.tips-list {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.mini-stat-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mini-stat-card {
  padding: 0.9rem;
  border-radius: var(--radius-md);
  background: var(--stat-bg);
  border: 1px solid var(--stat-border);
}

.mini-stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

.mini-stat-value {
  display: block;
  margin-top: 0.25rem;
  font-family: var(--serif);
  font-size: 1.5rem;
}

.completion-block {
  display: grid;
  gap: 0.55rem;
}

.completion-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.completion-note {
  font-size: 0.88rem;
}

.tips-list {
  padding-left: 1.1rem;
}

.meter-stack {
  display: grid;
  gap: 0.65rem;
}

.topic-meter-stack {
  max-width: 54rem;
}

.meter-row {
  display: grid;
  gap: 0.3rem;
  padding: 0.45rem 0.6rem 0.55rem;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--stat-bg) 92%, transparent);
  border: 1px solid color-mix(in srgb, var(--gold) 8%, var(--stat-border));
}

.meter-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.meter-track {
  height: 0.5rem;
  border-radius: 999px;
  overflow: hidden;
  background: var(--meter-track-bg);
}

.meter-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
}

.achievement-grid {
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
}

.achievement-card {
  display: grid;
  gap: 0.2rem;
  padding: 0.9rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--stat-border);
  background: var(--stat-bg);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.achievement-card-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 0.7rem;
}

.achievement-card:not(.is-locked) {
  border-color: color-mix(in srgb, var(--gold) 56%, var(--accent) 18%);
  background:
    linear-gradient(135deg, rgba(215, 180, 104, 0.22), rgba(199, 102, 68, 0.1)),
    var(--stat-bg);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.36),
    0 10px 24px rgba(157, 75, 49, 0.14);
}

.achievement-card:not(.is-locked):hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--gold) 72%, var(--accent) 24%);
}

.achievement-card.is-locked {
  opacity: 0.58;
  filter: saturate(0.72);
}

.achievement-state {
  padding: 0.2rem 0.52rem;
  border-radius: 999px;
  border: 1px solid var(--stat-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}

.achievement-card:not(.is-locked) .achievement-state {
  border-color: color-mix(in srgb, var(--gold) 50%, var(--accent) 24%);
  background: rgba(215, 180, 104, 0.16);
  color: var(--accent-deep);
}

.achievement-title {
  display: block;
  font-weight: 600;
  color: var(--ink);
}

.achievement-card:not(.is-locked) .achievement-title {
  color: var(--accent-deep);
}

.achievement-meta {
  display: block;
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.achievement-date {
  margin-top: 0.28rem;
}

.achievement-card:not(.is-locked) .achievement-meta:last-child {
  color: var(--green);
}

.heatmap-grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 0.8rem);
  grid-auto-columns: minmax(0, 1fr);
  gap: 0.28rem;
}

.heatmap-cell {
  width: 100%;
  height: 0.8rem;
  border-radius: 0.22rem;
  background: var(--meter-track-bg);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.heat-0 {
  background: var(--meter-track-bg);
}

.heat-1 {
  background: color-mix(in srgb, var(--accent) 28%, var(--meter-track-bg));
}

.heat-2 {
  background: color-mix(in srgb, var(--accent) 48%, var(--gold));
}

.heat-3 {
  background: color-mix(in srgb, var(--accent) 72%, var(--gold));
}

.heat-4 {
  background: linear-gradient(135deg, var(--accent), var(--gold));
}

.heatmap-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.7rem;
  color: var(--muted);
  font-size: 0.76rem;
}

.heatmap-legend-title {
  font-weight: 600;
}

.heatmap-legend-scale {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.heatmap-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
}

@keyframes lift-in {
  from {
    opacity: 0;
    transform: translateY(18px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 920px) {
  .app-frame,
  .stats-grid,
  .hero-panel,
  .study-grid {
    grid-template-columns: 1fr;
  }

  .stats-wide {
    grid-column: span 1;
  }

  .stats-hero-top,
  .reward-grid {
    grid-template-columns: 1fr;
  }

  .stats-badge {
    justify-self: start;
  }

  .hero-copy h1,
  .face-text {
    max-width: none;
  }

  .view-switcher {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.7rem;
    padding: 0.9rem 1rem;
  }

  .view-button {
    justify-content: center;
    text-align: center;
  }

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

  .toolbar-actions {
    grid-column: 1 / -1;
    justify-self: stretch;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar-actions .ghost-button {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 1rem, 100%);
    padding-top: 5rem;
  }

  .hero-panel,
  .view-switcher,
  .control-panel,
  .card-panel,
  .insight-card,
  .profile-card,
  .deck-editor-panel {
    padding: 1rem;
  }

  .utility-cluster {
    top: 0.8rem;
    left: 0.8rem;
  }

  .heatmap-popover {
    position: fixed;
    top: 4.6rem;
    left: 0.8rem;
    right: 0.8rem;
    width: auto;
  }

  .flashcard {
    min-height: 320px;
  }

  .flashcard .face {
    padding: 1.1rem;
  }

  .study-grid {
    gap: 1rem;
  }

  .control-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.7rem;
    align-items: stretch;
  }

  .reward-card {
    padding: 0.9rem;
  }

  .reward-track-head,
  .achievement-card-head {
    align-items: start;
    flex-direction: column;
  }

  .reward-track-progress,
  .stats-badge-subtle {
    white-space: normal;
  }

  .achievement-grid {
    grid-template-columns: 1fr;
  }

  .toolbar-group label {
    font-size: 0.78rem;
  }

  .toolbar-actions {
    grid-column: 1 / -1;
    grid-template-columns: 1fr;
    gap: 0.55rem;
  }

  .toolbar-actions .ghost-button,
  #autoSpeakButton,
  #shuffleButton {
    min-width: 0;
  }

  .hero-stats {
    gap: 0.75rem;
  }

  .stat-card {
    padding: 0.85rem;
  }

  .stat-value {
    font-size: 1.6rem;
  }

  .card-topline {
    flex-direction: column;
    align-items: stretch;
    gap: 0.8rem;
  }

  .card-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    gap: 0.55rem;
  }

  .card-actions .icon-button {
    width: 100%;
    min-width: 0;
    padding: 0.72rem 0.7rem;
    font-size: 0.92rem;
  }

  .face-text {
    font-size: clamp(1.7rem, 9vw, 2.35rem);
    line-height: 1.08;
  }

  .example,
  .example-translation,
  .card-note {
    font-size: 0.95rem;
    line-height: 1.48;
  }

  .profile-actions,
  .profile-display-name-head,
  .view-button,
  .toolbar-group,
  .toolbar-actions,
  .deck-editor-actions,
  .card-actions,
  .practice-row,
  .rating-button {
    width: 100%;
  }

  .view-switcher {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    top: 4.8rem;
    gap: 0.6rem;
    padding: 0.85rem 1rem;
  }

  .toolbar-actions {
    justify-self: stretch;
  }

  .practice-row {
    grid-template-columns: 1fr;
  }

  .rating-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
  }

  .rating-button {
    min-width: 0;
    padding: 0.72rem 0.85rem;
    justify-content: center;
  }

  .rating-key,
  .button-shortcut {
    display: none;
  }

  .icon-button.has-shortcut {
    justify-content: center;
    gap: 0;
  }

  .mini-stat-grid {
    grid-template-columns: 1fr;
  }

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

  .heatmap-months {
    margin-left: 2rem;
  }

  .view-button {
    justify-content: center;
  }
}
