/* ==========================================================================
   MyVocabulary — base styles
   Mobile-first, light theme, iPhone safe-area aware.
   ========================================================================== */

:root {
  /* Colours */
  --color-bg: #f4f6fa;
  --color-surface: #ffffff;
  --color-border: #e5e8ef;
  --color-text: #1b2333;
  --color-text-muted: #6b7486;
  --color-primary: #2563eb;
  --color-primary-strong: #1d4ed8;
  --color-primary-soft: #e8efff;
  --color-accent-soft: #eef2ff;
  --color-accent: #4f46e5;
  --color-success: #16a34a;
  --color-danger: #dc2626;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Shape */
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.07), 0 1px 3px rgba(16, 24, 40, 0.05);

  /* Layout */
  --touch-min: 44px;
  --header-height: 56px;
  --nav-height: 60px;
  --content-max: 640px;
  --space: 16px;

  /* Safe areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

/* ---------- Reset ---------- */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-family);
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ---------- App shell ---------- */

.app {
  min-height: 100vh;
  min-height: 100dvh;
  /* clip (not hidden) so .app doesn't become a scroll container,
     which would stop the sticky header from sticking. */
  overflow-x: clip;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  min-height: calc(var(--header-height) + var(--safe-top));
  padding: var(--safe-top) calc(var(--space) + var(--safe-right)) 0 calc(var(--space) + var(--safe-left));
  background: rgba(255, 255, 255, 0.92);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--color-border);
}

.app-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--color-primary);
}

.app-main {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding:
    20px
    calc(var(--space) + var(--safe-right))
    calc(var(--nav-height) + var(--safe-bottom) + 24px)
    calc(var(--space) + var(--safe-left));
}

.view {
  animation: view-in 180ms ease-out;
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

.view-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: var(--space);
}

.section-title {
  font-size: 1.0625rem;
  font-weight: 600;
  margin: 28px 0 12px;
}

/* ---------- Home: welcome ---------- */

.welcome {
  margin-bottom: 20px;
}

.welcome-title {
  font-size: 1.625rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.welcome-text {
  margin-top: 4px;
  color: var(--color-text-muted);
}

/* ---------- Home: statistics ---------- */

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

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  padding: 14px 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.stat-value {
  font-size: 1.625rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--color-primary);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  margin-top: 2px;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Loading state: keep the layout, show a soft placeholder instead of numbers. */
.stats.is-loading .stat-value,
.progress-summary.is-loading .metric-value {
  color: transparent;
  border-radius: 6px;
  background: linear-gradient(90deg, #eceff5 0%, #f6f8fb 50%, #eceff5 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
  min-width: 2.5em;
}

@keyframes shimmer {
  from { background-position: 100% 0; }
  to   { background-position: -100% 0; }
}

/* ---------- Home: notice ---------- */

.notice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px 16px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: var(--radius-md);
  color: #7c2d12;
}

.notice-icon {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  color: #ea580c;
}

.notice-body {
  min-width: 0;
}

.notice-text {
  font-size: 0.9375rem;
}

.notice-action {
  min-height: var(--touch-min);
  margin-top: 4px;
  padding: 0 2px;
  font-weight: 600;
  color: var(--color-primary);
}

/* ---------- Home: study cards ---------- */

.study-cards {
  display: grid;
  gap: 12px;
}

.study-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 76px;
  padding: 16px;
  text-align: left;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.study-card:active {
  transform: scale(0.985);
  box-shadow: var(--shadow-sm);
}

.study-card-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
}

.study-card-icon svg {
  width: 24px;
  height: 24px;
}

.study-card-icon--learn {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.study-card-icon--quiz {
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

.study-card-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.study-card-title {
  font-size: 1.0625rem;
  font-weight: 600;
}

.study-card-text {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.study-card-chevron {
  flex: 0 0 auto;
  color: #a3abbb;
}

.study-card-chevron svg {
  width: 20px;
  height: 20px;
  display: block;
}

/* ---------- Placeholder views ---------- */

.placeholder-card {
  padding: 28px 20px;
  text-align: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.placeholder-title {
  font-weight: 600;
}

.placeholder-text {
  margin-top: 4px;
  font-size: 0.9375rem;
  color: var(--color-text-muted);
}

/* ---------- Utilities ---------- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--touch-min);
  padding: 0 18px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  white-space: nowrap;
  transition: background-color 120ms ease, transform 120ms ease, opacity 120ms ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

.btn-primary:active:not(:disabled) {
  background: var(--color-primary-strong);
}

.btn-secondary {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text);
}

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

.btn-block {
  width: 100%;
}

.btn-icon {
  width: 18px;
  height: 18px;
  margin-left: -4px;
}

.btn-icon-only {
  display: inline-grid;
  place-items: center;
  width: var(--touch-min);
  height: var(--touch-min);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  transition: background-color 120ms ease, color 120ms ease;
}

.btn-icon-only svg {
  width: 20px;
  height: 20px;
}

.btn-icon-only:active:not(:disabled) {
  background: var(--color-bg);
  color: var(--color-primary);
}

.btn-icon-only--danger:active:not(:disabled) {
  color: var(--color-danger);
}

.btn-icon-only:disabled {
  opacity: 0.4;
}

@media (hover: hover) {
  .btn-primary:hover:not(:disabled) { background: var(--color-primary-strong); }
  .btn-secondary:hover:not(:disabled) { background: var(--color-bg); }
  .btn-icon-only:hover:not(:disabled) { background: var(--color-bg); color: var(--color-primary); }
  .btn-icon-only--danger:hover:not(:disabled) { color: var(--color-danger); }
}

/* ---------- Form controls ---------- */

.input {
  display: block;
  width: 100%;
  min-height: var(--touch-min);
  padding: 10px 14px;
  /* 16px minimum prevents iOS Safari from zooming in on focus. */
  font: inherit;
  font-size: 16px;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.input::placeholder {
  color: #9aa2b1;
}

.input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.input[aria-invalid="true"] {
  border-color: var(--color-danger);
}

.input[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

.input:disabled {
  background: var(--color-bg);
  color: var(--color-text-muted);
}

.textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.45;
}

.select {
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7486' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
}

/* Segmented control (filters and Entry Type) */
.segmented {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  background: #e9edf3;
  border-radius: var(--radius-sm);
}

.segmented-item,
.segmented-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 10px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--color-text-muted);
  border-radius: 7px;
  transition: background-color 120ms ease, color 120ms ease;
}

.segmented-item.is-active,
.segmented-option input:checked + span {
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* Each segment sits inside the 4px track: 36px + 2 × 4px = 44px touch height. */
.segmented-option {
  position: relative;
  cursor: pointer;
}

.segmented-option input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.segmented-option input:focus-visible + span {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.segmented-option input:disabled + span {
  opacity: 0.6;
}

/* ---------- Vocabulary: list ---------- */

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.view-header .view-title {
  margin-bottom: 0;
}

.view-title--inline {
  flex: 1 1 auto;
  min-width: 0;
}

.view-header .btn-icon-only {
  margin-left: -10px;
  color: var(--color-primary);
}

.view-subtitle {
  font-size: 0.9375rem;
  color: var(--color-text-muted);
}

.vocab-toolbar {
  display: grid;
  gap: 10px;
}

.search-field {
  position: relative;
  display: block;
}

.search-icon {
  position: absolute;
  top: 50%;
  left: 13px;
  width: 18px;
  height: 18px;
  color: var(--color-text-muted);
  transform: translateY(-50%);
  pointer-events: none;
}

.search-input {
  padding-left: 40px;
}

.search-input::-webkit-search-decoration {
  -webkit-appearance: none;
}

.results-info {
  margin: 14px 2px 8px;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.results-info:empty {
  margin-bottom: 0;
}

.vocab-list {
  display: grid;
  gap: 10px;
}

.vocab-card {
  min-width: 0;
  padding: 14px 14px 6px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.vocab-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.vocab-card-text {
  min-width: 0;
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.vocab-card-turkish {
  margin-top: 4px;
  font-weight: 500;
  color: var(--color-primary-strong);
  overflow-wrap: anywhere;
}

.vocab-card-english {
  margin-top: 2px;
  font-size: 0.9375rem;
  color: var(--color-text-muted);
  overflow-wrap: anywhere;
}

.vocab-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}

.vocab-card-stats {
  display: flex;
  gap: 14px;
}

.score {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.875rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.score svg {
  width: 16px;
  height: 16px;
}

.score--correct {
  color: var(--color-success);
}

.score--wrong {
  color: var(--color-danger);
}

.vocab-card-actions {
  display: flex;
  margin-right: -6px;
}

.badge {
  flex: 0 0 auto;
  padding: 3px 9px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
  border-radius: 999px;
  white-space: nowrap;
}

.badge--word {
  background: var(--color-primary-soft);
  color: var(--color-primary-strong);
}

.badge--idiom {
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

.empty-state {
  padding: 36px 20px;
  text-align: center;
  background: var(--color-surface);
  border: 1px dashed #d3d9e4;
  border-radius: var(--radius-lg);
}

.empty-state-icon {
  width: 40px;
  height: 40px;
  margin-bottom: 8px;
  color: #b4bccb;
}

.empty-state-title {
  font-weight: 600;
}

.empty-state-text {
  margin-top: 4px;
  font-size: 0.9375rem;
  color: var(--color-text-muted);
}

#vocab-load-more {
  margin-top: 14px;
}

/* ---------- Vocabulary: form ---------- */

.form-card {
  display: grid;
  gap: 18px;
  padding: 18px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.form-field {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.form-label {
  display: block;
  margin-bottom: 6px;
  padding: 0;
  font-size: 0.9375rem;
  font-weight: 600;
}

.form-error {
  margin-top: 6px;
  font-size: 0.875rem;
  color: var(--color-danger);
}

.form-error:empty {
  display: none;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

/* ---------- Learn Mode ---------- */

.view-intro {
  margin-bottom: 16px;
}

.btn-lg {
  min-height: 52px;
  font-size: 1.0625rem;
  border-radius: var(--radius-md);
}

.btn-compact {
  padding: 0 14px;
  font-size: 0.9375rem;
}

.btn-success {
  background: var(--color-success);
  color: #fff;
}

.btn-success:active:not(:disabled) {
  background: #15803d;
}

.btn-review {
  background: #fff1e6;
  border-color: #fed7aa;
  color: #c2410c;
}

.btn-review:active:not(:disabled) {
  background: #ffe4cc;
}

@media (hover: hover) {
  .btn-success:hover:not(:disabled) { background: #15803d; }
  .btn-review:hover:not(:disabled) { background: #ffe4cc; }
}

.setup-summary {
  padding: 12px 14px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
}

.setup-available {
  font-weight: 600;
}

.setup-info {
  margin-top: 2px;
  font-size: 0.9375rem;
  color: var(--color-text-muted);
}

.setup-info:empty {
  display: none;
}

.session-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.session-progress-text {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.progress {
  height: 8px;
  overflow: hidden;
  background: #e3e8f0;
  border-radius: 999px;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: var(--color-success);
  border-radius: inherit;
  transition: width 240ms ease;
}

.session-meta {
  margin: 8px 2px 14px;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.flashcard {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: 0;
  min-height: 240px;
  padding: 28px 20px;
  text-align: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  transition: opacity 160ms ease, transform 160ms ease;
}

.flashcard.is-leaving {
  opacity: 0;
  transform: translateX(-16px);
}

.flashcard.is-entering {
  animation: card-in 200ms ease-out;
}

@keyframes card-in {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: none; }
}

.flashcard-text {
  max-width: 100%;
  font-size: clamp(1.625rem, 7vw, 2.125rem);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.flashcard-hint {
  font-size: 0.9375rem;
  color: var(--color-text-muted);
}

.flashcard-answer {
  width: 100%;
  margin-top: 6px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
}

.flashcard-answer.is-revealing {
  animation: reveal-in 200ms ease-out;
}

@keyframes reveal-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.flashcard-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #9aa2b1;
}

.flashcard-turkish {
  margin: 2px 0 14px;
  font-size: 1.1875rem;
  font-weight: 600;
  color: var(--color-primary-strong);
  overflow-wrap: anywhere;
}

.flashcard-english {
  margin-top: 2px;
  color: var(--color-text-muted);
  overflow-wrap: anywhere;
}

.flashcard-actions {
  margin-top: 16px;
}

.answer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.answer-actions .btn {
  padding: 0 10px;
}

.complete-card {
  padding: 28px 20px 20px;
  text-align: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.complete-icon {
  display: inline-grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: 12px;
  color: var(--color-success);
  background: #dcfce7;
  border-radius: 50%;
}

.complete-icon svg {
  width: 32px;
  height: 32px;
}

.complete-title {
  font-size: 1.625rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.complete-title:focus {
  outline: none;
}

.complete-text {
  margin-top: 4px;
  color: var(--color-text-muted);
}

.summary-list {
  margin: 20px 0;
  text-align: left;
  border-top: 1px solid var(--color-border);
}

.summary-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--color-border);
}

.summary-row dt {
  color: var(--color-text-muted);
}

.summary-row dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.complete-actions {
  display: grid;
  gap: 10px;
}

/* ---------- Quiz Mode ---------- */

.progress-fill--primary {
  background: var(--color-primary);
}

/* Quiz type list */
.choice-list {
  display: grid;
  gap: 8px;
}

.choice {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  min-height: var(--touch-min);
  padding: 10px 14px;
  text-align: left;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: border-color 120ms ease, background-color 120ms ease;
}

.choice-title {
  font-weight: 600;
}

.choice-text {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.choice.is-active {
  background: var(--color-primary-soft);
  border-color: var(--color-primary);
  box-shadow: inset 0 0 0 1px var(--color-primary);
}

.choice.is-active .choice-title {
  color: var(--color-primary-strong);
}

/* Session */
.quiz-tally {
  display: flex;
  gap: 16px;
  margin: 10px 2px 14px;
}

.question-card {
  padding: 22px 18px;
  text-align: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.question-card.is-entering {
  animation: card-in 200ms ease-out;
}

.question-instruction {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #9aa2b1;
}

.question-prompt {
  margin-top: 8px;
  font-size: clamp(1.5rem, 6.5vw, 2rem);
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.question-prompt--long {
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.45;
}

.answer-options {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.answer-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 14px;
  text-align: left;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: border-color 120ms ease, background-color 120ms ease, opacity 120ms ease;
}

.answer-option:active:not(:disabled) {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
}

@media (hover: hover) {
  .answer-option:hover:not(:disabled) { border-color: var(--color-primary); }
  .choice:hover:not(.is-active) { border-color: #c5cede; }
}

.answer-option:disabled {
  cursor: default;
}

.answer-letter {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-primary-strong);
  background: var(--color-primary-soft);
  border-radius: 8px;
}

.answer-text {
  min-width: 0;
  font-size: 1rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.answer-option.is-correct {
  border-color: var(--color-success);
  background: #f0fdf4;
}

.answer-option.is-correct .answer-letter {
  background: var(--color-success);
  color: #fff;
}

.answer-option.is-wrong {
  border-color: var(--color-danger);
  background: #fef2f2;
}

.answer-option.is-wrong .answer-letter {
  background: var(--color-danger);
  color: #fff;
}

.answer-option.is-dimmed {
  opacity: 0.55;
}

/* Feedback */
.quiz-feedback {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding: 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left-width: 4px;
  border-radius: var(--radius-md);
  scroll-margin-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
}

.quiz-feedback.is-correct {
  border-left-color: var(--color-success);
}

.quiz-feedback.is-wrong {
  border-left-color: var(--color-danger);
}

.quiz-feedback.is-revealing {
  animation: reveal-in 200ms ease-out;
}

.feedback-title {
  font-size: 1.25rem;
  font-weight: 700;
}

.quiz-feedback.is-correct .feedback-title {
  color: var(--color-success);
}

.quiz-feedback.is-wrong .feedback-title {
  color: var(--color-danger);
}

.feedback-correct {
  overflow-wrap: anywhere;
}

.feedback-label {
  font-weight: 600;
}

.feedback-entry {
  padding: 12px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  overflow-wrap: anywhere;
}

.feedback-entry-text {
  font-weight: 700;
}

.feedback-entry-turkish {
  font-weight: 500;
  color: var(--color-primary-strong);
}

.feedback-entry-english {
  font-size: 0.9375rem;
  color: var(--color-text-muted);
}

.feedback-error {
  font-size: 0.9375rem;
  color: var(--color-danger);
}

/* Results */
.score-ring {
  position: relative;
  width: 140px;
  height: 140px;
  margin: 18px auto 6px;
  --ring-color: var(--color-primary);
}

.score-ring[data-level="high"] { --ring-color: var(--color-success); }
.score-ring[data-level="low"]  { --ring-color: #ea580c; }

.score-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.score-ring circle {
  fill: none;
  stroke-width: 12;
}

.score-ring-track {
  stroke: #e3e8f0;
}

.score-ring-value {
  stroke: var(--ring-color);
  stroke-linecap: round;
  transition: stroke-dashoffset 600ms ease-out;
}

.score-ring-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

.review-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.review-item {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 14px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left-width: 4px;
  border-radius: var(--radius-md);
}

.review-item.is-correct { border-left-color: var(--color-success); }
.review-item.is-wrong   { border-left-color: var(--color-danger); }

.review-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.review-text {
  min-width: 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.status-badge {
  flex: 0 0 auto;
  padding: 3px 9px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
}

.status-badge--correct { background: #dcfce7; color: #166534; }
.status-badge--wrong   { background: #fee2e2; color: #991b1b; }

.review-row {
  display: grid;
  gap: 1px;
  font-size: 0.9375rem;
  overflow-wrap: anywhere;
}

.review-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #9aa2b1;
}

.review-value.is-correct { color: #166534; }
.review-value.is-wrong   { color: #b91c1c; }

/* ---------- Home: learning progress ---------- */

.progress-summary {
  display: grid;
  gap: 12px;
  padding: 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.progress-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  text-align: center;
}

.metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.metric-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.metric-value--primary { color: var(--color-primary); }
.metric-value--danger  { color: var(--color-danger); }

.metric-label {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.progress-summary-note {
  font-size: 0.875rem;
  text-align: center;
  color: var(--color-text-muted);
}

.progress-summary-note:empty {
  display: none;
}

.btn-icon--trailing {
  margin-left: 0;
  margin-right: -6px;
}

/* ---------- Statistics ---------- */

.stats-content {
  display: grid;
  gap: 12px;
  transition: opacity 150ms ease;
}

.stats-content.is-loading {
  opacity: 0.5;
}

.stats-content > .section-title {
  margin: 16px 0 0;
}

.stats-card {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.stats-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.stats-card-title {
  font-weight: 600;
}

.stats-card-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-primary);
  font-variant-numeric: tabular-nums;
}

.stats-card-caption {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.stats-card-caption:empty {
  display: none;
}

.accuracy-card {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  column-gap: 16px;
}

.score-ring--compact {
  width: 112px;
  height: 112px;
  margin: 0;
}

.score-ring--compact .score-ring-label {
  font-size: 1.5rem;
}

.score-ring[data-level="none"] .score-ring-label {
  color: #a3abbb;
}

.accuracy-details {
  min-width: 0;
}

.accuracy-figures {
  display: grid;
  gap: 4px;
  margin: 8px 0 0;
}

.accuracy-figures div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.accuracy-figures dt {
  color: var(--color-text-muted);
}

.accuracy-figures dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.text-success { color: var(--color-success); }
.text-danger  { color: var(--color-danger); }

.accuracy-note {
  grid-column: 1 / -1;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.stats-tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.stat-value--success { color: var(--color-success); }
.stat-value--danger  { color: var(--color-danger); }
.stat-value--muted   { color: #8a93a5; }

.progress--large {
  height: 12px;
}

/* Learning status distribution */
.distribution-bar {
  display: flex;
  height: 14px;
  overflow: hidden;
  background: #e3e8f0;
  border-radius: 999px;
}

.distribution-segment {
  height: 100%;
  min-width: 3px;
  transition: width 300ms ease;
}

.distribution-segment + .distribution-segment {
  border-left: 2px solid var(--color-surface);
}

.distribution-segment--mastered,
.legend-dot--mastered { background: var(--color-success); }
.distribution-segment--learning,
.legend-dot--learning { background: var(--color-primary); }
.distribution-segment--difficult,
.legend-dot--difficult { background: var(--color-danger); }
.distribution-segment--not-practiced,
.legend-dot--not-practiced { background: #c3cad6; }

.legend {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.legend-row {
  display: grid;
  grid-template-columns: auto 1fr auto 3.25em;
  align-items: center;
  gap: 10px;
  min-height: 32px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-count {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.legend-share {
  text-align: right;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

/* Entry lists (difficult / recent) */
.stat-entry-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.stat-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 12px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.stat-entry-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.stat-entry-text {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.stat-entry-meaning {
  font-size: 0.9375rem;
  color: var(--color-primary-strong);
  overflow-wrap: anywhere;
}

.stat-entry-date {
  margin-top: 2px;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.stat-entry-meta {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.accuracy-pill {
  min-width: 3.25em;
  padding: 3px 8px;
  font-size: 0.8125rem;
  font-weight: 700;
  text-align: center;
  border-radius: 999px;
  background: var(--color-bg);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.accuracy-pill--high { background: #dcfce7; color: #166534; }
.accuracy-pill--mid  { background: var(--color-primary-soft); color: var(--color-primary-strong); }
.accuracy-pill--low  { background: #fee2e2; color: #991b1b; }

.empty-state--compact {
  padding: 20px 16px;
  font-size: 0.9375rem;
  color: var(--color-text-muted);
}

.stats-practice-btn {
  margin-top: 2px;
}

@media (max-width: 359px) {
  .accuracy-card {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .accuracy-details {
    width: 100%;
  }

  .stat-entry {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ---------- Header action (Settings gear) ---------- */

.app-header {
  justify-content: space-between;
}

.header-action {
  margin-right: -10px;
  color: var(--color-text-muted);
}

.header-action svg {
  width: 22px;
  height: 22px;
}

/* ---------- Settings ---------- */

.settings-content {
  display: grid;
  gap: 12px;
}

.info-list {
  margin: 0;
  border-top: 1px solid var(--color-border);
}

.info-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
}

.info-row dt {
  flex: 0 0 auto;
  color: var(--color-text-muted);
}

.info-row dd {
  min-width: 0;
  margin: 0;
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.info-list--compact .info-row {
  padding: 6px 0;
}

.info-list[aria-busy="true"] dd {
  color: #a3abbb;
}

.notice--info {
  margin: 0;
  background: var(--color-primary-soft);
  border-color: #c7d7fe;
  color: #1e3a8a;
}

.notice--info .notice-icon {
  color: var(--color-primary);
}

.notice--danger {
  margin: 0;
  background: #fef2f2;
  border-color: #fecaca;
  color: #7f1d1d;
}

.notice--danger .notice-icon {
  color: var(--color-danger);
}

.notice--danger .notice-action {
  color: #b91c1c;
}

.file-picker {
  position: relative;
  cursor: pointer;
}

.file-picker:focus-within {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.file-picker.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}

.import-preview {
  display: grid;
  gap: 14px;
}

/* Radio cards (import mode) reuse the .choice look */
.choice--radio {
  position: relative;
  cursor: pointer;
}

.choice--radio input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

/* .is-active / .is-danger are set from JS (works without :has()). */
.choice--radio.is-danger.is-active {
  background: #fef2f2;
  border-color: var(--color-danger);
  box-shadow: inset 0 0 0 1px var(--color-danger);
}

.choice--radio.is-danger.is-active .choice-title {
  color: #b91c1c;
}

.choice--radio:focus-within {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.status-message {
  padding: 12px 14px;
  font-size: 0.9375rem;
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  overflow-wrap: anywhere;
}

.status-message[data-type="success"],
.status-message--success {
  background: #f0fdf4;
  color: #14532d;
}

.status-message[data-type="error"],
.status-message--error {
  background: #fef2f2;
  color: #7f1d1d;
}

.status-message[data-type="info"] {
  background: var(--color-primary-soft);
  color: #1e3a8a;
}

.status-message-title {
  font-weight: 700;
}

.status-message-list {
  margin: 6px 0 0;
  padding-left: 18px;
  font-size: 0.875rem;
}

.status-message-list[hidden] {
  display: none;
}

.status-message--success .info-list {
  margin-top: 8px;
  border-top-color: #bbf7d0;
}

.status-message--success .info-row {
  border-bottom-color: #bbf7d0;
}

.status-message--success .info-row dt {
  color: #166534;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: calc(16px + var(--safe-left));
  right: calc(16px + var(--safe-right));
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
  z-index: 30;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: #fff;
  background: #1f2937;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.18);
  overflow-wrap: anywhere;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: none;
}

.toast[data-type="success"] {
  background: #166534;
}

.toast[data-type="error"] {
  background: #b91c1c;
}

/* ---------- Confirmation dialog ---------- */

.dialog {
  width: min(calc(100% - 32px), 400px);
  max-width: none;
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: 0 20px 50px rgba(16, 24, 40, 0.25);
}

.dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-panel {
  padding: 22px 20px 18px;
}

.dialog-title {
  font-size: 1.125rem;
  font-weight: 700;
}

.dialog-message {
  margin-top: 8px;
  color: var(--color-text-muted);
  overflow-wrap: anywhere;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

/* Allow longer labels such as "Continue Studying" to wrap on narrow phones. */
.dialog-actions .btn {
  padding: 8px 12px;
  white-space: normal;
  line-height: 1.25;
}

/* ---------- Bottom navigation ---------- */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: rgba(255, 255, 255, 0.95);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--color-border);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  min-height: var(--nav-height);
  padding: 6px 4px;
  color: var(--color-text-muted);
  transition: color 120ms ease;
}

.nav-icon {
  width: 24px;
  height: 24px;
}

.nav-label {
  font-size: 0.6875rem;
  font-weight: 500;
  white-space: nowrap;
}

.nav-item.is-active {
  color: var(--color-primary);
}

.nav-item.is-active .nav-label {
  font-weight: 600;
}

/* ---------- Larger screens ---------- */

@media (min-width: 600px) {
  .stat-card {
    padding: 18px 16px;
  }

  .study-cards {
    grid-template-columns: 1fr 1fr;
  }

  .bottom-nav {
    padding-left: calc(50% - var(--content-max) / 2);
    padding-right: calc(50% - var(--content-max) / 2);
  }
}

@media (prefers-reduced-motion: reduce) {
  .view,
  .stats.is-loading .stat-value,
  .toast,
  .btn,
  .flashcard,
  .flashcard.is-entering,
  .flashcard-answer.is-revealing,
  .question-card.is-entering,
  .quiz-feedback.is-revealing,
  .score-ring-value,
  .progress-fill,
  .stats-content,
  .distribution-segment,
  .progress-summary.is-loading .metric-value,
  .study-card,
  .nav-item {
    animation: none;
    transition: none;
  }
}

/* ---------- PWA: connection status ---------- */

.header-end {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text-muted);
  background: var(--color-bg);
  border-radius: 999px;
  white-space: nowrap;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-success);
}

.connection-status[data-state="offline"] {
  color: #92400e;
  background: #fffbeb;
}

.connection-status[data-state="offline"] .connection-dot {
  background: #d97706;
}

/* ---------- PWA: Settings ---------- */

.offline-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.offline-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-muted);
}

.offline-status[data-state="ready"] {
  color: var(--color-success);
}

.offline-status[data-state="ready"]::before {
  background: var(--color-success);
}

.offline-status[data-state="unavailable"] {
  color: var(--color-text-muted);
  font-weight: 500;
}

.install-steps {
  margin: 0;
  padding-left: 22px;
  display: grid;
  gap: 6px;
  font-size: 0.9375rem;
}

.install-steps li::marker {
  color: var(--color-primary);
  font-weight: 700;
}

/* ---------- PWA: update banner ---------- */

.update-banner {
  position: fixed;
  left: calc(12px + var(--safe-left));
  right: calc(12px + var(--safe-right));
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
  z-index: 25;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  padding: 12px 12px 12px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.14);
  animation: view-in 180ms ease-out;
}

.update-banner[hidden] {
  display: none;
}

.update-banner-body {
  flex: 1 1 180px;
  min-width: 0;
}

.update-banner-title {
  font-weight: 700;
}

.update-banner-text {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.update-banner-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

/* Keep page content and toasts clear of the banner while it is shown. */
body.has-update-banner .app-main {
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 150px);
}

body.has-update-banner .toast {
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 130px);
}

@media (prefers-reduced-motion: reduce) {
  .update-banner {
    animation: none;
  }
}
