:root {
  --bg: #ffffff;
  --surface: #f4f4f4;
  --border: #dcdcdc;
  --text: #1a1a1a;
  --text-dim: #6a6a6a;
  --accent: #1a1a1a;         /* chrome accent = dark ink (no color) */
  --accent-soft: #ececec;    /* neutral light grey for informational pills */
  --green: #4a9d5f;          /* semantic only: improvement, strong strength */
  --red: #b13030;
  --yellow: #d4a017;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  min-height: 100vh;
  padding: 0 1rem;
  overflow-x: hidden;   /* prevent any offscreen element from expanding the viewport */
}

header {
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  color: var(--text-dim);
  padding: 0.75rem 1rem;
  margin: 0 -1rem;    /* bleed past body's 1rem padding to touch viewport edges */
  display: flex;
  gap: 1.5rem;
  align-items: center;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
}

header .stat { white-space: nowrap; }
header .stat span { color: var(--text); font-weight: 600; }

nav {
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  padding: 0.4rem 0;
  display: flex;
  gap: 1rem;
}

nav a { color: var(--text-dim); text-decoration: none; }
nav a:hover { color: var(--text); }
nav a.active { color: var(--text); font-weight: 600; }

main {
  max-width: 700px;
  margin: 0 auto;
  padding: 2rem 0;
}

/* Practice / Vocab / Cards / Settings / Auth screen toggling */
#practice-screen, #vocab-screen, #cards-screen, #placement-screen, #settings-screen, #auth-screen { display: none; }

/* Settings gear in the header (icon, not a button visually) */
.settings-btn {
  margin-left: auto;
  background: none;
  border: none;
  padding: 0.35rem;
  cursor: pointer;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  transition: color 0.12s ease-out;
}
.settings-btn:hover { color: var(--text); }
.settings-btn:focus { outline: none; }
.settings-btn.active { color: var(--text); }
.settings-btn svg { display: block; }

/* ---------------------------------------------------------------------- */
/* Settings screen                                                         */
/* ---------------------------------------------------------------------- */
.settings-inner {
  width: 100%;
  margin: 0;
  padding: 0;
}
.settings-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 1.5rem 0;
  text-align: left;
}
.settings-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 320px;
  margin: 0 auto;
  width: 100%;
}
.settings-action-btn {
  width: 100%;
  padding: 0.75rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 500;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.12s ease-out;
  text-align: center;
  box-sizing: border-box;
}
.settings-action-btn:hover {
  background: var(--accent-soft);
  border-color: #999;
}
.settings-signout-btn {
  color: #b00020;
  border-color: #f8b4b4;
  background: var(--surface);
}
.settings-signout-btn:hover {
  background: #fff0f0;
  border-color: #f08080;
}
.settings-footer {
  margin-top: 2rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-dim);
  font-family: system-ui, sans-serif;
}

/* ---------------------------------------------------------------------- */
/* Placement / level-setting screen                                        */
/* ---------------------------------------------------------------------- */
.placement-inner {
  max-width: 560px;
  margin: 3rem auto 0;
  padding: 0 0.5rem;
  text-align: center;
}
.placement-intro, .placement-test, .placement-results { display: none; }

.placement-intro h1 {
  font-size: 1.6rem;
  font-weight: 600;
  margin-bottom: 1rem;
}
.placement-intro p {
  color: var(--text-dim);
  line-height: 1.55;
  margin-bottom: 1rem;
  text-align: left;
}
.placement-intro .placement-note {
  font-size: 0.9rem;
  color: var(--text-dim);
  font-style: italic;
}

.placement-start-btn {
  margin-top: 1.5rem;
  padding: 0.85rem 2.4rem;
  font-size: 1rem;
  font-weight: 500;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.15s ease-out;
}
.placement-start-btn:hover { opacity: 0.85; }
.placement-start-btn:disabled { opacity: 0.5; cursor: default; }

.placement-progress {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 3rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  font-family: system-ui, sans-serif;
}
#placement-counter { white-space: nowrap; min-width: 3.5rem; text-align: right; }
.placement-bar {
  flex: 1;
  height: 4px;
  background: var(--surface);
  border-radius: 2px;
  overflow: hidden;
}
.placement-bar-fill {
  height: 100%;
  background: var(--text);
  width: 0%;
  transition: width 0.25s ease-out;
}

.placement-item {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 3rem;
  font-weight: 400;
  padding: 3.5rem 0;
  min-height: 8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}

.placement-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 1.5rem;
}
.placement-answer-btn {
  flex: 1;
  max-width: 200px;
  padding: 0.95rem 1.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease-out, border-color 0.12s ease-out;
  font-family: system-ui, sans-serif;
}
.placement-answer-btn:hover { background: var(--surface); border-color: #999; }
.placement-answer-btn:active { background: var(--border); }
.placement-label {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
}

.placement-results h2 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
}
.placement-summary {
  color: var(--text-dim);
  line-height: 1.55;
  text-align: left;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border-radius: 6px;
  margin-bottom: 0.5rem;
}
.placement-summary p { margin-bottom: 0.6rem; }
.placement-summary p:last-child { margin-bottom: 0; }
.placement-summary strong { color: var(--text); }

@media (max-width: 640px) {
  .placement-inner { margin-top: 1.5rem; }
  .placement-intro h1 { font-size: 1.4rem; }
  .placement-item { font-size: 2.4rem; padding: 2.5rem 0; min-height: 6rem; }
  .placement-answer-btn { padding: 1rem 0.6rem; }
}

/* Cards screen */
.card-face {
  position: relative;
  perspective: 1200px;
  max-width: 352px;
  margin: 0 auto;
  cursor: pointer;
  user-select: none;
  transition: transform 0.2s ease-out, box-shadow 0.2s ease-out;
}
.card-def-flyout {
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 1.25rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.95rem;
  color: var(--text);
  width: 320px;
  line-height: 1.4;
  white-space: normal;
  text-align: left;
  opacity: 0;
  transition: opacity 0.35s ease-out;
  pointer-events: none;
}
.card-def-flyout::before {
  content: 'Def.';
  display: block;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
}
.card-def-flyout.show {
  opacity: 1;
  transition: opacity 0.2s ease-in;
}
.card-face:hover:not(.flipped) {
  transform: translateY(-4px);
  box-shadow: 0 10px 22px rgba(0,0,0,0.08);
}
.card-flipper {
  position: relative;
  min-height: 220px;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.65, 0.05, 0.36, 1);
}
.card-face.flipped .card-flipper {
  transform: rotateY(180deg);
}
.card-side {
  position: absolute;
  inset: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.card-back { transform: rotateY(180deg); }
.card-lemma {
  font-family: Georgia, serif;
  font-size: 2.1rem;
  color: var(--text);
  letter-spacing: 0.01em;
  text-align: center;
}
.card-gloss {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.2rem;
  color: var(--text-dim);
  margin-top: 0.9rem;
  text-align: center;
  max-width: 90%;
  line-height: 1.4;
}
.card-gloss-placeholder { visibility: hidden; }
.card-lemma-hint {
  font-family: Georgia, serif;
  font-style: italic;
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-top: 0.4rem;
  text-align: center;
}
.card-lemma-hint:empty { display: none; }
.card-score-update {
  position: absolute;
  right: 0;
  top: 0;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-style: normal;
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity 0.45s ease-out;
}
.card-score-update.show { opacity: 1; transition: opacity 0.15s ease-in; }
.card-score-update.up   { color: var(--green); }
.card-score-update.down { color: var(--red); }
.card-score-update.neutral { color: var(--text-dim); }

.card-hints {
  position: relative;
  max-width: 352px;
  margin: 0.5rem auto 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
  font-style: italic;
  line-height: 1.6;
  height: 1.6em;   /* reserve one line so the two hints overlay cleanly */
}
.card-hints .hint-flip, .card-hints .hint-rate {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
}
.card-hints .hint-flip, .card-hints .hint-rate {
  transition: opacity 0.175s ease;
}
.card-hints .hint-rate { opacity: 0; }
.card-hints .hint-flip-mobile { display: none; }   /* mobile-only, activated in media query */
#card-face.flipped ~ .card-hints .hint-flip { opacity: 0; }
#card-face.flipped ~ .card-hints .hint-rate { opacity: 1; }

/* Mobile: replace the keyboard-shortcut hints with tap-friendly buttons. */
.card-rate-buttons {
  display: none;   /* shown only via mobile media query below */
  gap: 0.5rem;
  max-width: 352px;
  margin: 0.6rem auto 0;
}
.card-rate-buttons button {
  flex: 1;
  padding: 0.75rem 0;
  background: #f9f9f9;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 0.92rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}
.card-rate-buttons button:hover { background: #ececec; }
.card-rate-buttons button:active { background: var(--text); color: #fff; border-color: var(--text); }


/* Vocabulary tab */
#vocab-summary {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}
#vocab-summary .num { font-weight: 600; }
#vocab-summary .vs-mobile-slashes { display: none; }   /* mobile-only variant */
#vocab-summary .vs-rate { margin-left: auto; text-align: right; }   /* stick to right edge */
#vocab-summary .vs-rate-mobile { display: none; }
#vocab-summary .vs-rate-desktop { display: inline; }

/* Mobile-only column picker cell — hidden on desktop. */
.vocab-table .col-mobile-picker { display: none; }
.vocab-table .col-mobile-picker select {
  font: inherit;
  color: var(--text-dim);
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  cursor: pointer;
}

.vocab-table {
  width: 100%;
  border-collapse: collapse;
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
}

.vocab-table th, .vocab-table td {
  padding: 0.4rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.vocab-table th {
  color: var(--text-dim);
  font-weight: 500;
  font-size: 0.85rem;
  white-space: nowrap;
}

.vocab-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.vocab-table th.sortable:hover {
  color: var(--text);
}

.vocab-table th.sortable.active {
  color: var(--text);
  font-weight: 600;
}

.sort-arrow {
  display: inline-block;
  width: 0.8rem;
  text-align: center;
  color: var(--text);
  margin-left: 0.15rem;
}

.vocab-table td.lemma {
  font-family: Georgia, serif;
  font-size: 1rem;
}

.strength-label {
  font-weight: 500;
}
.strength-strong { color: var(--green); }
.strength-medium { color: var(--yellow); }
.strength-weak   { color: var(--red); }

.rank-label {
  color: var(--text-dim);
}

/* Vocab pagination & load-more */
.vocab-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.2rem;
  padding: 0.75rem 0 1.5rem;
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.vocab-pagination .page-info {
  font-variant-numeric: tabular-nums;
}
.vocab-pagination button,
.load-more-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 1rem;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.vocab-pagination button:hover:not(:disabled),
.load-more-btn:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: #999;
}
.vocab-pagination button:disabled,
.load-more-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#paragraph-area {
  font-family: "Georgia", "Times New Roman", serif;
  font-size: 1.35rem;
  line-height: 1.9;
  letter-spacing: 0.01em;
  min-height: 4rem;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow-wrap: break-word;
  word-break: normal;
}

#translation-area,
#translation-display {
  width: 100%;
  min-height: 60px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1.05rem;
  font-family: inherit;
  line-height: 1.7;
  padding: 0.75rem;
  overflow-wrap: break-word;
  word-break: normal;
  white-space: pre-wrap;
}

#translation-area {
  resize: none;
  outline: none;
}

#translation-area:focus { border-color: var(--accent); }

#translation-area:disabled,
#translation-area[readonly] {
  color: var(--text);
  background: var(--surface);
  opacity: 1;
  -webkit-text-fill-color: var(--text);
  cursor: default;
}

#translation-display {
  cursor: default;
  user-select: text;
}

.keyboard-hint {
  font-family: system-ui, sans-serif;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.5rem;
  letter-spacing: 0.02em;
}

.submit-btn {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--text);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 8px;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 500;
  cursor: pointer;
  overflow: hidden;
  box-sizing: border-box;
  transition: background-color 0.25s ease,
              color 0.25s ease,
              border-color 0.25s ease,
              opacity 0.2s ease-out,
              max-height 0.2s ease-out,
              min-height 0.2s ease-out,
              margin-top 0.2s ease-out,
              padding-top 0.2s ease-out,
              padding-bottom 0.2s ease-out,
              border-width 0.2s ease-out;
  max-height: 8rem;
}

.submit-btn:hover:not(.editing):not(.hidden) {
  background: #333333;
}

.submit-btn.editing {
  background: #e5e7eb !important;
  color: #111827 !important;
  border-color: #d1d5db !important;
}

.submit-btn.editing:hover {
  background: #d1d5db !important;
  color: #111827 !important;
}

.submit-btn.editing:active {
  background: #cbd5e1 !important;
  color: #111827 !important;
}

.submit-btn.hidden {
  opacity: 0;
  pointer-events: none;
  max-height: 0;
  min-height: 0;
  margin-top: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-width: 0;
}

.ru-token {
  border-radius: 3px;
  cursor: pointer;
  transition: background-color 0.4s ease-out;
  /* iOS native tap highlight — fires reliably on touch. Kept slightly
     stronger than the desktop hover so the tap feedback reads clearly. */
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.18);
}
.ru-token.scanning {
  background-color: rgba(0, 0, 0, 0.09);
  transition: background-color 0.05s ease-in;
}
/* Desktop: darken on hover. Mobile: darken while pressed (:active).
   The .tap-flash class is toggled by JS touchstart/end so the darkening
   lingers ~150ms — plain :active on mobile Safari fires too briefly to see. */
@media (hover: hover) {
  .ru-token:hover { background-color: rgba(0, 0, 0, 0.07); transition: background-color 0.1s ease-out; }
}
.ru-token:active,
.ru-token.tap-flash {
  background-color: rgba(0, 0, 0, 0.16);
  transition: background-color 0.05s ease-out;
}

/* Play (TTS) button */
.speak-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  border-radius: 4px;
  transition: color 0.12s, background 0.12s;
}
.speak-btn:hover, .speak-btn:focus { color: var(--text); outline: none; background: rgba(0,0,0,0.04); }
.speak-btn.speaking { color: var(--green); }
.paragraph-wrap {
  position: relative;
}
.paragraph-wrap .speak-btn {
  position: absolute;
  top: 12px;
  right: 12px;
}
.card-face .speak-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  padding: 6px;                     /* +50% from base 4px */
}
/* Fade the speaker button out through the first half of the flip and back
   in through the second half — matches the 550ms flip transition so the
   button appears to travel with the card instead of hovering statically. */
@keyframes speak-btn-flip-fade {
  0%,  100% { opacity: 1; }
  25%,  75% { opacity: 0; }
}
.card-face .speak-btn.flipping {
  animation: speak-btn-flip-fade 0.55s ease-in-out;
}

/* Feedback */
#feedback-area {
  margin-top: 1.75rem;
  display: none;
}

.feedback-divider {
  border: none;
  border-top: 1px solid #aaaaaa;
  width: 40%;
  margin: 0 auto 1.75rem;
}

.feedback-bottom {
  display: flex;
  align-items: stretch;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

#schedule-section {
  flex: 0 0 auto;
  min-width: 0;
  margin-bottom: 0;
  position: relative;
}
/* Wrapper around the header + rows: sizes to its widest row and centers
   within the card, so on any card width the info block is horizontally
   centered while columns still line up between header and data rows. */
.schedule-block {
  width: fit-content;
  margin: 0 auto;
}

.next-btn {
  flex: 1;
  padding: 0;
  background: #f9f9f9;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 0.88rem;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.next-btn:hover {
  border-color: #999;
}

.next-btn.pressing {
  background: #2a2a2a;
  color: #fff;
  border-color: #2a2a2a;
}

.schedule-header {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin-bottom: 0.35rem;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 500;
}

.schedule-header .lemma    { min-width: 8rem; }
.schedule-header .action   { min-width: 8rem; }

.feedback-section {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.feedback-section h3 {
  font-family: system-ui, sans-serif;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
}

.word-grade {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.25rem 0.4rem 0.25rem 0;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
}

.word-grade.correct { background: rgba(45,122,58,0.10); color: var(--green); }
.word-grade.wrong   { background: rgba(177,48,48,0.10); color: var(--red); }

.schedule-row {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  font-family: system-ui, sans-serif;
  font-size: 0.88rem;
  padding: 0.25rem 0;
  color: var(--text);
  /* Lock row height so lemma-box changes (view underline vs. edit-mode
     filled box) can't propagate into the card's overall height. */
  min-height: 1.9rem;
}

.schedule-row .lemma-wrap {
  min-width: 8rem;
  display: inline-block;
}
.schedule-row .lemma {
  font-family: Georgia, serif;
  font-size: 1rem;
  position: relative;   /* popover / tooltip anchors from the end of the text */
  display: inline-block;
  border-bottom: 1px dotted var(--text-dim);
  padding-bottom: 1px;
}
.schedule-row .lemma:hover {
  color: var(--text);
  border-bottom-color: var(--text);
}

/* Gloss tooltip — shown on hover in view mode only. Positioned to the right
   of the word with a left-pointing arrow, mirroring .override-popover. */
.gloss-tooltip {
  position: absolute;
  top: 50%;
  left: 100%;
  transform: translateY(-50%);
  margin-left: 0.6rem;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.10);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.35;
  width: max-content;
  max-width: 640px;
  white-space: normal;
  text-align: left;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
  z-index: 40;
}
.gloss-tooltip::before,
.gloss-tooltip::after {
  content: '';
  position: absolute;
  top: 50%;
  right: 100%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-right-color: var(--border);
}
.gloss-tooltip::after {
  margin-right: -1px;
  border-right-color: #fff;
}
.schedule-row .lemma:hover .gloss-tooltip,
.schedule-row .lemma:focus .gloss-tooltip,
.schedule-row .lemma.open .gloss-tooltip {
  opacity: 1;
  pointer-events: auto;
}

/* Editable "after" score — always visible grey pill; click opens override popover. */
.score-editable {
  position: relative;
  display: inline-block;
  padding: 1px 6px;
  margin: 0 -2px;
  border-radius: 4px;
  background: #ececec;
  cursor: pointer;
  transition: background 0.1s;
}
.score-editable:hover { background: #dcdcdc; }

.override-popover {
  display: none;
  position: absolute;
  top: 50%;
  left: 100%;
  transform: translateY(-50%);
  margin-left: 0.6rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0;
  z-index: 30;
  box-shadow: 0 4px 12px rgba(0,0,0,0.10);
  white-space: nowrap;
}
.override-popover.open { display: inline-flex; gap: 0; }
.override-popover::before,
.override-popover::after {
  content: '';
  position: absolute;
  top: 50%;
  right: 100%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-right-color: var(--border);
}
.override-popover::after {
  margin-right: -1px;
  border-right-color: #fff;
}
.override-popover button {
  background: none;
  border: none;
  border-radius: 0;
  padding: 0.35rem 0.75rem;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 0.78rem;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}
.override-popover button + button { border-left: 1px solid var(--border); }
.override-popover button:first-child {
  border-top-left-radius: 5px;
  border-bottom-left-radius: 5px;
}
.override-popover button:last-child {
  border-top-right-radius: 5px;
  border-bottom-right-radius: 5px;
}
.override-popover button:hover { background: #ececec; color: var(--text); }

/* Keep the score pill visually "held down" while its popover is open. */
.score-editable:has(.override-popover.open) {
  background: #dcdcdc;
}

.schedule-row .action {
  color: var(--text-dim);
  font-size: 0.8rem;
  min-width: 8rem;
}

.schedule-row .strength-change {
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.schedule-row .arrow {
  display: inline-block;
  padding: 0 0.15rem;
  font-weight: 700;
}
.delta-up      { color: var(--green); }
.delta-down    { color: var(--red); }
.delta-neutral { color: var(--text-dim); }

.conversational-feedback {
  font-size: 1rem;
  line-height: 1.75;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.conversational-feedback .ru {
  font-family: "Georgia", "Times New Roman", serif;
}

.user-translation-echo {
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Loading + reveal */
.loading-dots {
  display: inline-block;
  color: var(--text-dim);
  font-size: 1.35rem;
  letter-spacing: 0.15em;
  min-width: 2ch;
}
.loading-dots::after {
  content: '';
  display: inline-block;
  animation: dots 1.4s steps(4, end) infinite;
}
@keyframes dots {
  0%   { content: '.'; }
  25%  { content: '..'; }
  50%  { content: '...'; }
  75%  { content: '..'; }
  100% { content: '.'; }
}

/* New (unseen) words: dotted underline, gloss on hover */
.new-word {
  position: relative;
  border-bottom: 2px dotted var(--text-dim);
  cursor: help;
  padding-bottom: 1px;
}
.new-word:hover { border-bottom-color: var(--text); }

.new-word-tooltip {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
  padding: 0.4rem 0.65rem;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 0.8rem;
  line-height: 1.4;
  letter-spacing: normal;
  white-space: nowrap;
  max-width: min(260px, calc(100vw - 1.5rem));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
  z-index: 10;
}
.new-word-tooltip::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-bottom-color: var(--border);
}
.new-word-tooltip::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: -1px;
  border: 5px solid transparent;
  border-bottom-color: var(--bg);
}
.new-word:hover .new-word-tooltip,
.new-word:focus .new-word-tooltip { opacity: 1; }

h2.section-title {
  font-family: system-ui, sans-serif;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 1.5rem 0 0.5rem;
}

/* -----------------------------------------------------------------------
   Mobile — stack scorecard over Next button and tighten scorecard cols.
   Breakpoint 640px is roughly the phone-portrait / small-tablet cutoff.
   ----------------------------------------------------------------------- */
@media (max-width: 640px) {
  body { padding: 0 0.5rem; }
  main { padding: 0.5rem 0; }
  header {
    padding: 0.6rem 0.5rem;
    margin: 0 -0.5rem;
    gap: 0.9rem;
  }
  nav { font-size: 1.17rem; gap: 1.1rem; }

  #paragraph-area {
    font-size: 1.4rem;
    line-height: 1.5;
    padding: 0.6rem 0.7rem;
    margin-bottom: 0.75rem;
  }
  #translation-area,
  #translation-display {
    font-size: 1.2rem;
    padding: 0.55rem 0.6rem;
  }
  .submit-btn {
    min-height: 60px;
    font-size: 1.2rem;
    padding: 0.55rem 0.6rem;
  }
  .feedback-section { padding: 0.55rem 0.7rem; margin-bottom: 0.75rem; }
  #feedback-area { margin-top: 0.75rem; }
  .feedback-divider { margin: 0 auto 0.75rem; }
  .conversational-feedback {
    font-size: 1.15rem;
    line-height: 1.55;
  }

  .card-lemma { font-size: 2rem; }
  .card-gloss { font-size: 1.15rem; margin-top: 0.55rem; }

  #cards-screen .card-face { margin-top: 1.25rem; }

  .card-def-flyout {
    left: 0;
    right: 0;
    top: 100%;
    transform: none;
    margin-left: 0;
    margin-top: 0.5rem;
    width: auto;
    max-width: 352px;
    text-align: center;
  }

  .vocab-table { font-size: 1.05rem; }
  .vocab-table th, .vocab-table td { padding: 0.55rem 0.1rem; }
  .vocab-table th { font-size: 1.05rem; }
  .vocab-table td.lemma { font-size: 1.12rem; }
  .vocab-table .col-mobile-picker { width: 1%; white-space: nowrap; }
  .vocab-table .col-mobile-picker select {
    appearance: none;
    -webkit-appearance: none;
    font-size: 1.05rem;
    padding: 2px 12px 2px 5px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='7' height='5' viewBox='0 0 7 5'><path d='M0 0l3.5 4L7 0z' fill='%236a6a6a'/></svg>");
    background-repeat: no-repeat;
    background-position: right 4px center;
    width: 6rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .vocab-table th:nth-child(1),
  .vocab-table td:nth-child(1) { width: 38%; }
  .vocab-table th:nth-child(2),
  .vocab-table td:nth-child(2) { width: auto; }

  .feedback-bottom {
    flex-direction: column;
  }
  #schedule-section {
    flex: 1 1 auto;
    width: 100%;
  }
  .next-btn {
    flex: 0 0 auto;
    width: 100%;
    min-height: 4.15rem;
  }
  .schedule-block {
    width: 100%;
    display: grid;
    grid-template-columns: auto auto auto;
    justify-content: space-between;
    column-gap: 0.6rem;
    row-gap: 0.4rem;
    align-items: baseline;
  }
  .schedule-header,
  #schedule-rows,
  .schedule-row { display: contents; }

  .schedule-row { font-size: 1.15rem; }
  .schedule-header { font-size: 1rem; }
  .schedule-row .lemma-wrap,
  .schedule-header .lemma { min-width: 0; }
  .schedule-header .action,
  .schedule-row .action {
    min-width: 0;
    font-size: 1.05rem;
  }
  .schedule-row .lemma { font-size: 1.3rem; }
  .schedule-row .strength-change { font-size: 1.12rem; }
  .override-popover {
    left: auto;
    right: 0;
    top: auto;
    bottom: 100%;
    transform: none;
    margin-left: 0;
    margin-bottom: 0.4rem;
  }
  .override-popover::before,
  .override-popover::after {
    top: 100%;
    right: 0.5rem;
    bottom: auto;
    transform: none;
    border-right-color: transparent;
    border-top-color: var(--border);
  }
  .override-popover::after {
    margin-right: 0;
    margin-top: -1px;
    border-top-color: #fff;
  }
  .gloss-tooltip {
    left: 0;
    right: auto;
    top: auto;
    bottom: calc(100% + 8px);
    transform: none;
    margin-left: 0;
    max-width: min(280px, calc(100vw - 3rem));
    z-index: 50;
  }
  .gloss-tooltip::before,
  .gloss-tooltip::after {
    top: 100%;
    left: 0.75rem;
    right: auto;
    bottom: auto;
    transform: none;
    border: 6px solid transparent;
    border-right-color: transparent;
    border-top-color: var(--border);
  }
  .gloss-tooltip::after {
    margin-right: 0;
    margin-top: -1px;
    border-right-color: transparent;
    border-top-color: #fff;
  }
  .card-hints .hint-flip,
  .card-hints .hint-rate { display: none; }
  .card-hints {
    height: auto;
    min-height: 1.5em;
    margin-top: 0.75rem;
    transition: min-height 0.175s ease;
  }
  #card-face.flipped ~ .card-hints { min-height: 5rem; }
  .card-hints .hint-flip-mobile {
    display: block;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    opacity: 1;
    transition: opacity 0.175s ease;
  }
  #card-face.flipped ~ .card-hints .hint-flip-mobile { opacity: 0; }

  .card-rate-buttons {
    display: flex;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    margin-top: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.175s ease;
  }
  #card-face.flipped ~ .card-hints .card-rate-buttons {
    opacity: 1;
    pointer-events: auto;
  }
  .card-rate-buttons button {
    padding: 2.25rem 0;
    font-style: normal;
  }

  #vocab-summary { font-size: 1.1rem; }
  #vocab-summary .vs-desktop-labels { display: none; }
  #vocab-summary .vs-mobile-slashes { display: block; }
  #vocab-summary .vs-rate-desktop { display: none; }
  #vocab-summary .vs-rate-mobile { display: inline; }

  .vocab-table .col-metric { display: none; }
  .vocab-table .col-mobile-picker { display: table-cell; }
  .vocab-table[data-metric="effective_strength"] .col-metric-strength,
  .vocab-table[data-metric="reps"]                .col-metric-reps,
  .vocab-table[data-metric="lapses"]              .col-metric-lapses,
  .vocab-table[data-metric="frequency_rank"]      .col-metric-difficulty {
    display: table-cell;
  }
  .vocab-table thead .col-metric { display: none !important; }
}

/* ===========================================================================
   Dedicated Auth Screen (for unauthenticated state)
   =========================================================================== */
#auth-screen {
  display: none;
  justify-content: center;
  align-items: center;
  min-height: 70vh;
  padding: 1.5rem 1rem;
}

.auth-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.05);
  width: 100%;
  max-width: 380px;
  padding: 2rem 1.75rem;
}

.auth-header {
  text-align: center;
  margin-bottom: 1.75rem;
}
.auth-logo {
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
  letter-spacing: -0.02em;
}

.form-group {
  margin-bottom: 1.1rem;
}
.form-group label {
  display: block;
  font-size: 0.8rem;
  font-family: system-ui, sans-serif;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}
.form-group input {
  width: 100%;
  height: 38px;
  padding: 0.5rem 0.75rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.form-group input:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 1px var(--text);
}

.auth-msg {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 1.1rem;
}
.auth-error {
  background: #fde8e8;
  color: #c81e1e;
  border: 1px solid #f8b4b4;
}
.auth-success {
  background: #def7ec;
  color: #03543f;
  border: 1px solid #84e1bc;
}

.auth-submit-btn {
  width: 100%;
  height: 38px;
  padding: 0 1rem;
  background: var(--text);
  color: #fff;
  border: 1px solid var(--text);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.12s, transform 0.08s ease;
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-submit-btn:hover:not(:disabled) {
  opacity: 0.88;
}
.auth-submit-btn:active:not(:disabled) {
  transform: scale(0.99);
}
.auth-submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.auth-toggle-link {
  width: 100%;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.6rem 0;
  margin-top: 0.35rem;
  cursor: pointer;
  text-align: center;
  transition: color 0.12s;
}
.auth-toggle-link:hover {
  color: var(--text);
  text-decoration: underline;
}

.auth-divider {
  position: relative;
  width: 100%;
  text-align: center;
  margin: 1.1rem 0;
}
.auth-divider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  border-top: 1px solid var(--border);
  z-index: 1;
}
.auth-divider span {
  position: relative;
  z-index: 2;
  background: #ffffff;
  padding: 0 0.6rem;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.auth-google-btn {
  width: 100%;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0 1rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.08s ease;
}
.auth-google-btn:hover {
  background: #fafafa;
  border-color: #b5b5b5;
}
.auth-google-btn:active {
  transform: scale(0.99);
}
.gsi-container {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-bottom: 0.5rem;
}
.gsi-container:empty {
  display: none;
}
.gsi-container iframe {
  margin: 0 auto !important;
}

/* Toast Notification Component */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 1000;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 240px;
  max-width: 380px;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.4;
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.toast.toast-show {
  opacity: 1;
  transform: translateY(0);
}
.toast.toast-error {
  background: #fde8e8;
  color: #9b1c1c;
  border-color: #f8b4b4;
}
.toast.toast-success {
  background: #def7ec;
  color: #03543f;
  border-color: #84e1bc;
}
.toast-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  color: inherit;
  opacity: 0.6;
  padding: 0 0.2rem;
}
.toast-close:hover { opacity: 1; }
