/* Shared palette and controls */
:root {
  --bg: #f7f8fa; --surface: #fff; --subtle: #eef1f5; --border: #dfe4eb;
  --text: #182333; --muted: #627084; --primary: #2563eb; --primary-hover: #1d4ed8;
  --again: #c73636; --hard: #b77913; --good: #087e62; --easy: #2563eb;
}
[data-theme="dark"] {
  --bg: #121923; --surface: #1b2532; --subtle: #263343; --border: #354356;
  --text: #edf2f7; --muted: #a3b1c2; --primary: #70a4ff; --primary-hover: #4f8ef5;
  --again: #ff9090; --hard: #f4c16a; --good: #68d5b3; --easy: #85b4ff;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif; line-height: 1.5; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
button,input,select,textarea { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible,input:focus-visible,select:focus-visible,textarea:focus-visible,summary:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
button,input,select,textarea { transition: background-color .15s,border-color .15s; }
.btn-main,.btn-secondary,.btn-danger,.small-btn,.icon-btn,.google-signin {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px; border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); background: var(--surface); font-size: .9rem; font-weight: 600; line-height: 1.4;
}
.btn-main { background: var(--primary); border-color: var(--primary); color: #fff; }
[data-theme="dark"] .btn-main { color: #10213f; }
.btn-main:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-secondary:hover,.small-btn:hover,.icon-btn:hover,.google-signin:hover { background: var(--subtle); }
.btn-danger { background: #bc3030; border-color: #bc3030; color: #fff; }
.btn-danger:hover { background: #9e2424; border-color: #9e2424; }
.icon-btn { width: 42px; min-height: 42px; padding: 10px; flex-shrink: 0; }
.icon-btn svg { width: 21px; height: 21px; }
.link-btn,.back-link,.danger-link { border: 0; background: none; color: var(--primary); font-size: .86rem; font-weight: 600; min-height: 40px; padding: 6px 0; }
.link-btn:hover,.back-link:hover,.danger-link:hover { text-decoration: underline; }
.back-link { color: var(--muted); }
.full-width { width: 100%; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.divider { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
.app-message { max-width: 760px; margin: 0 auto 20px; padding: 12px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); font-size: .9rem; }
.app-message.error { color: var(--again); border-color: var(--again); }

/* Navigation and the one active course */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1080px; margin: auto; padding: 16px 24px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.brand-logo { font-size: 1.6rem; font-weight: 800; letter-spacing: -.045em; }
.nav-tabs { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--subtle); }
.nav-btn { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 48px; min-width: 112px; padding: 10px 22px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; font-size: 1.05rem; font-weight: 650; }
.nav-btn:hover { background: var(--subtle); }
.nav-btn.active { color: var(--primary); background: var(--surface); box-shadow: 0 1px 4px #1823330d; }
.nav-btn svg { width: 19px; height: 19px; }
.nav-chevron { width: 18px; height: 18px; flex-shrink: 0; color: var(--muted); }
.nav-chevron.is-back { transform: rotate(180deg); }
.back-link { display: inline-flex; align-items: center; gap: 6px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.google-signin { padding: 9px 12px; min-height: 42px; }
.google-icon { flex: 0 0 18px; }
.container { max-width: 1040px; margin: auto; padding: 24px 24px 80px; }
.course-context { display: flex; justify-content: center; margin-bottom: 30px; }
.course-switch { display: flex; align-items: center; gap: 20px; padding: 8px 12px; border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--text); text-align: left; }
.course-switch:hover { border-color: var(--border); background: var(--surface); }
.course-switch strong { display: block; font-size: 1rem; font-weight: 700; }
.course-switch span span { display: block; margin-top: 1px; color: var(--muted); font-size: .8rem; }
.course-switch svg { width: 18px; height: 18px; color: var(--muted); }
.lesson-mode .topbar,.lesson-mode #courseContext,.lesson-mode #feedbackBtn { display: none; }
.lesson-mode .container { padding-top: 24px; }

/* Study overview */
.study-overview { max-width: 560px; margin: 0 auto; }
.overview-card { padding: 34px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); text-align: center; }
.overview-title { font-size: 1.7rem; font-weight: 750; letter-spacing: -.025em; }
.overview-stats { display: flex; align-items: center; margin: 28px 0; padding: 18px 0; }
.stat-item { flex: 1; }
.stat-num { font-size: 2rem; font-weight: 750; line-height: 1.2; }
.stat-lbl { margin-top: 6px; color: var(--muted); font-size: .82rem; }
.stat-divider { height: 38px; width: 1px; background: var(--border); }
#startStudyBtn { width: 100%; min-height: 50px; font-size: 1rem; }
.overview-footer { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px 18px; margin-top: 16px; color: var(--muted); font-size: .82rem; }

/* Topics and vocabulary */
.words-toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.search-input,.select-input,.text-area-input,.form-row input[type="number"] { width: 100%; min-width: 0; min-height: 44px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text); font-size: .9rem; }
.search-input { flex: 1 1 240px; }
.words-toolbar .select-input { flex: 0 1 220px; }
.phase-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; padding: 3px 0; }
.phase-pill { white-space: nowrap; min-height: 38px; padding: 8px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--muted); font-size: .85rem; font-weight: 600; }
.phase-pill.active { border-color: var(--primary); color: var(--primary); }
.words-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-bottom: 24px; color: var(--muted); font-size: .82rem; }
.phases-topics-container { display: flex; flex-direction: column; gap: 32px; }
.phase-group-header { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 12px; }
.phase-group-title { font-size: 1.08rem; font-weight: 700; }
.phase-group-meta { font-size: .8rem; color: var(--muted); }
.topics-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(270px,1fr)); gap: 16px; }
.topic-card { position: relative; display: flex; align-items: center; gap: 16px; width: 100%; min-height: 114px; padding: 18px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); text-align: left; }
.topic-card:hover { border-color: var(--primary); box-shadow: 0 4px 12px #18233309; }
.topic-card .vocab-img { width: 60px; height: 60px; border-radius: 12px; }
.topic-card.is-prioritized { border-color: var(--hard); }
.topic-info { flex: 1; min-width: 0; }
.topic-name { display: block; font-size: .95rem; font-weight: 650; margin-bottom: 4px; }
.topic-count,.topic-skipped { display: block; color: var(--muted); font-size: .78rem; }
.topic-priority-star { position: absolute; top: -13px; right: 14px; display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--hard); border-radius: 11px; background: var(--surface); color: var(--hard); font-size: 1.5rem; line-height: 1; pointer-events: none; }
.topic-card.is-skipped { background: var(--subtle); color: var(--muted); }
.topic-card.is-skipped .vocab-img { filter: grayscale(1); opacity: .5; }
.topic-card.is-skipped .nav-chevron { opacity: .55; }
.topic-detail-header { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.topic-detail-header .back-link { flex-basis: 100%; text-align: left; }
.topic-detail-title-wrap { flex: 1; min-width: 180px; }
.topic-detail-title { font-size: 1.45rem; letter-spacing: -.02em; }
.topic-detail-sub { color: var(--muted); font-size: .82rem; }
.topic-actions { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.topic-actions button { width: 100%; padding: 10px 14px; font-size: .83rem; }
.topic-actions [aria-pressed="true"] { border-color: var(--primary); color: var(--primary); }
.vocab-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(280px,1fr)); gap: 14px; }
.vocab-card { display: flex; flex-direction: column; gap: 18px; padding: 18px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.vocab-top { display: flex; align-items: center; gap: 14px; flex: 1; }
.vocab-img { display: block; width: 52px; height: 52px; padding: 7px; object-fit: contain; flex-shrink: 0; background: #24516c; border-radius: 10px; }
.vocab-card .vocab-img { width: 72px; height: 72px; padding: 10px; }
.vocab-text { flex: 1; min-width: 0; }
.vocab-word { font-size: 1.18rem; font-weight: 700; overflow-wrap: anywhere; }
.vocab-trans { color: var(--muted); font-size: .88rem; margin-top: 3px; overflow-wrap: anywhere; }
.vocab-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .78rem; }
.small-btn { font-size: .76rem; padding: 5px 9px; min-height: 34px; }
.word-status { color: var(--good); font-weight: 600; }

/* Audio is secondary in browsing, full-sized during a lesson. */
.audio-player { text-align: center; }
.audio-row { display: flex; justify-content: center; margin: 14px 0; }
.listen-control { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.listen-main-btn,.listen-speed-btn { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 44px; padding: 10px 18px; border: 0; color: var(--text); background: transparent; font-size: .85rem; font-weight: 600; }
.listen-speed-btn { border-left: 1px solid var(--border); }
.listen-main-btn:hover,.listen-speed-btn:hover { background: var(--subtle); }
.listen-icon { width: 18px; height: 18px; }
.listen-control:focus-within { outline: 2px solid var(--primary); outline-offset: 3px; }
.listen-control.is-unavailable { opacity: .6; }
.listen-control.is-playing { border-color: var(--primary); }
.listen-control.is-playing .listen-main-btn { color: var(--primary); }
.audio-notice { color: var(--muted); font-size: .78rem; margin: 6px 0; }
.computer-voice-btn { font-size: .78rem; }
.audio-compact { flex: 0 0 auto; }
.audio-compact .audio-row { margin: 0; }
.audio-compact .listen-control { border: 1px solid var(--border); background: transparent; border-radius: 8px; }
.audio-compact .listen-main-btn { width: 38px; min-height: 36px; padding: 8px; color: var(--muted); }
.audio-compact .listen-speed-btn { min-height: 36px; padding: 7px 9px; color: var(--muted); font-size: .72rem; }
.audio-compact .audio-notice,.audio-compact .computer-voice-btn { font-size: .7rem; overflow-wrap: anywhere; }

/* Lessons retain one image, one word and one set of grade controls. */
.study-session { max-width: 560px; margin: auto; }
#studySessionView:focus { outline: none; }
.session-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; color: var(--muted); font-size: .8rem; }
.flashcard { display: flex; flex-direction: column; gap: 22px; padding: 28px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); text-align: center; }
.card-image { display: grid; place-items: center; width: 150px; height: 150px; margin: 8px auto 18px; padding: 14px; border-radius: 16px; background: #24516c; }
.card-image img { width: 100%; height: 100%; object-fit: contain; }
.word-primary { margin: 6px 0; font-size: 2rem; line-height: 1.2; font-weight: 750; overflow-wrap: anywhere; }
.word-secondary { margin: 8px 0 12px; color: var(--muted); font-size: 1.12rem; font-weight: 500; }
.example-block { max-width: 440px; margin: 20px auto 0; padding: 14px; border-radius: 10px; background: var(--bg); }
.example-target { font-size: .95rem; }
.example-source { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.study-info { align-self: flex-end; text-align: right; margin-bottom: 8px; }
.study-info summary { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; color: var(--muted); cursor: pointer; list-style: none; }
.study-info summary::-webkit-details-marker { display: none; }
.study-info summary:hover { background: var(--subtle); }
.study-info > div { color: var(--muted); font-size: .8rem; margin: 8px 0 16px; }
.grade-help { text-align: left; max-width: 340px; }
.grade-help p { margin-bottom: 10px; }
.study-info .report-card-btn { font-size: .8rem; }
.fsrs-bar { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 8px; margin-top: 16px; }
.fsrs-btn { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 12px 4px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.fsrs-btn .ivl { color: var(--muted); font-size: .72rem; }
.fsrs-btn .lbl { font-size: .9rem; font-weight: 650; }
.fsrs-btn.rate-1 .lbl { color: var(--again); }
.fsrs-btn.rate-2 .lbl { color: var(--hard); }
.fsrs-btn.rate-3 .lbl { color: var(--good); }
.fsrs-btn.rate-4 .lbl { color: var(--easy); }
.fsrs-btn:hover,.fsrs-btn.suggested { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.grade-tooltip { display: none; position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); width: 180px; padding: 10px; border-radius: 8px; background: var(--text); color: var(--surface); z-index: 30; font-size: .8rem; line-height: 1.4; pointer-events: none; }
.fsrs-btn:first-child .grade-tooltip { left: 0; transform: none; }
.fsrs-btn:last-child .grade-tooltip { left: auto; right: 0; transform: none; }
.fsrs-btn:hover .grade-tooltip,.fsrs-btn:focus-visible .grade-tooltip { display: block; }
[data-shortcut] { position: relative; }
[data-shortcut]::after { content: attr(data-shortcut); position: absolute; top: 5px; right: 7px; font-size: .62rem; font-weight: 500; line-height: 1; opacity: .6; color: var(--muted); }
#skipKnownBtn,#learnWordBtn { padding-right: 22px; }
.completion-actions { display: flex; gap: 10px; margin-top: 12px; }
.answer-slots { display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: 8px 0.8ch; margin: 16px 0; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: clamp(1.1rem, 4.5vw, 1.4rem); font-weight: 600; line-height: 2.5rem; }
.slot-word { display: inline-flex; max-width: 100%; align-items: baseline; }
.letter-run { position: relative; display: inline-block; width: calc(var(--slot-count) * 1.25ch); min-width: 1.25ch; max-width: 100%; overflow: hidden; border-radius: 3px; }
.slot-mask { position: absolute; top: 0; left: 0; color: var(--muted); pointer-events: none; letter-spacing: 0.25ch; white-space: pre; }
.letter-run:focus-within .slot-mask { color: var(--primary); }
.slot-input { display: block; width: 100%; height: 2.5rem; padding: 0; font: inherit; letter-spacing: 0.25ch; line-height: 2.5rem; color: var(--text); caret-color: var(--primary); border: 0; border-radius: 0; outline: none !important; background: transparent; }
.letter-run:focus-within { background: var(--subtle); }
.typed-attempt { margin: 12px 0; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 1.1rem; overflow-wrap: anywhere; }
.attempt-label { font-family: inherit; color: var(--muted); font-size: 0.75rem; margin-bottom: 3px; }
.answer-term { font-size: 1.85rem; overflow-wrap: anywhere; }
.type-form {
  margin-top: 14px;
}

.diff-ok {
  color: var(--good);
  font-weight: 700;
}
.diff-bad {
  color: var(--again);
  text-decoration: line-through;
  padding: 0 1px;
}
.diff-miss {
  color: var(--hard);
  font-weight: 700;
}

/* Dialogs, profile and settings */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; overflow-y: auto; background: #0f172a66; }
.modal { width: 100%; max-width: 440px; max-height: calc(100dvh - 32px); overflow-y: auto; padding: 24px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); box-shadow: 0 16px 60px #0002; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.modal-title { font-size: 1.15rem; font-weight: 700; }
.modal-header .icon-btn { width: 34px; min-height: 34px; padding: 6px; }
.form-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 16px; font-size: .88rem; }
.form-row > label,.form-row > span { flex: 1; }
.form-row > select { flex: 0 1 190px; }
.form-row input[type="number"] { width: 80px; text-align: center; }
.form-column { flex-direction: column; align-items: stretch; gap: 7px; }
.form-column > select { flex: auto; }
.setting-help { margin: 4px 0 20px; color: var(--muted); font-size: .8rem; line-height: 1.6; }
.text-area-input { resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.theme-options { display: flex; padding: 3px; border: 1px solid var(--border); border-radius: 10px; background: var(--subtle); }
.theme-choice { display: grid; place-items: center; width: 38px; height: 34px; border: 1px solid transparent; border-radius: 7px; color: var(--muted); background: transparent; }
.theme-choice svg { width: 21px; height: 21px; }
.theme-choice[aria-pressed="true"] { border-color: var(--border); color: var(--primary); background: var(--surface); }
.account-title,.section-title { font-size: .88rem; font-weight: 650; margin-bottom: 8px; }
.account-desc { color: var(--muted); font-size: .8rem; }
.account-email { display: flex; gap: 9px; align-items: center; margin: 12px 0; font-size: .85rem; overflow-wrap: anywhere; }
.account-email span { min-width: 0; }
.profile-name { font-size: 1.3rem; font-weight: 700; margin-bottom: 4px; }
.profile-courses { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.profile-course { display: flex; justify-content: space-between; align-items: center; gap: 14px; width: 100%; min-height: 72px; border: 1px solid var(--border); border-radius: 10px; padding: 14px; background: var(--surface); color: var(--text); text-align: left; }
.profile-course.is-current { border-color: var(--primary); }
.profile-course strong { display: block; font-size: .95rem; }
.profile-course small { display: block; margin-top: 3px; font-size: .76rem; color: var(--muted); }
.profile-course > span:last-child { font-size: .74rem; color: var(--muted); }
.profile-settings { display: block; margin: 14px auto 0; }
.testing-reset { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }
.danger-link { color: var(--again); font-size: .74rem; font-weight: 500; text-align: left; }
.reset-warning { font-size: .9rem; color: var(--again); margin-bottom: 14px; font-weight: 600; }
#resetStatus { margin-top: 16px; }

/* Feedback stays secondary. */
.feedback-float-btn { position: fixed; bottom: 20px; right: 20px; z-index: 50; display: flex; align-items: center; gap: 7px; min-height: 38px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--muted); font-size: .78rem; }
.report-context-box { padding: 12px; margin-bottom: 18px; border-radius: 9px; background: var(--subtle); color: var(--muted); font-size: .84rem; }
.report-status { margin-top: 14px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; font-size: .84rem; }
.report-status.success { color: var(--good); }
.report-status.error { color: var(--again); }

@media (max-width: 640px) {
  .topbar-inner { padding: 14px 16px 10px; gap: 12px; flex-wrap: wrap; }
  .brand-logo { font-size: 1.45rem; }
  .top-actions { margin-left: auto; gap: 6px; }
  .nav-tabs { order: 3; width: 100%; gap: 8px; }
  .nav-btn { flex: 1; min-height: 48px; font-size: 1.02rem; }
  .google-signin { padding: 8px; font-size: .8rem; gap: 6px; }
  .top-actions .icon-btn { width: 38px; min-height: 38px; padding: 8px; }
  .container { padding: 18px 16px 70px; }
  .course-context { margin-bottom: 22px; }
  .overview-card { padding: 26px 20px; }
  .overview-title { font-size: 1.5rem; }
  .overview-stats { margin: 24px 0; }
  .topics-grid,.vocab-grid { grid-template-columns: 1fr; }
  .topic-actions { width: 100%; }
  .topic-detail-title { font-size: 1.3rem; }
  .words-toolbar .select-input { flex: 1 1 160px; }
  .flashcard { padding: 20px 14px; }
  .word-primary { font-size: 1.8rem; }
  .fsrs-bar { gap: 6px; }
  .fsrs-btn .lbl { font-size: .8rem; }
  .session-progress-text { font-size: .74rem; text-align: right; }
  .feedback-label { display: none; }
  .feedback-float-btn { right: 16px; bottom: 16px; }
  .modal { padding: 20px; }
}

@media (max-width: 380px) {
  .google-signin { width: 38px; min-height: 38px; padding: 8px; }
  .google-signin span { display: none; }
}
