/* Cobalt2 (Visual Studio Code theme) palette */
:root {
  color-scheme: dark;     /* native form controls and scrollbars follow the dark theme */
  --bg: #193549;          /* editor background */
  --panel: #15232d;       /* darker side panels */
  --text: #ffffff;        /* foreground */
  --muted: #8ea9bf;       /* comments, secondary text */
  --border: #2c4a62;
  --accent: #0050a4;      /* Cobalt2 dark blue: primary buttons, active tab, badge */
  --accent-text: #ffffff;
  --highlight: #9effff;   /* light cyan: pinyin, mastered */
  --yellow: #ffc600;      /* flashcard outline */
  --good: #3ad900;        /* green */
  --hard: #ff9d00;        /* orange */
  --again: #ff628c;       /* pink */
  --easy: #0088ff;        /* blue */
  --on-grade: #193549;    /* text on the bright grade buttons */
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", "PingFang SC", sans-serif;
  line-height: 1.45;
}

[v-cloak] { display: none; }
[hidden] { display: none !important; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  max-width: 880px;
  margin: 0 auto;
}

.topbar h1 { font-size: 1.3rem; margin: 0; }
.topbar h1 span { font-weight: 400; color: var(--muted); font-size: 1rem; }

nav { display: flex; flex-wrap: wrap; gap: 8px; }

.topbar-right { display: flex; flex-wrap: wrap; align-items: stretch; gap: 12px; }
.menu { position: relative; display: flex; align-items: stretch; }
.menu-toggle { padding: 8px 14px; display: inline-flex; align-items: center; justify-content: center; }
.menu-toggle span { font-size: 1.2rem; line-height: 1; display: block; margin-top: -0.12em; }
.menu-toggle.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.menu-backdrop { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 9; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; margin: 0; padding: 6px; min-width: 180px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.menu-list button { width: 100%; text-align: left; border: 0; background: none; }
.menu-list button.active { color: var(--highlight); }
.menu-nav { display: none; }
.menu-sep { height: 1px; margin: 6px 0; background: var(--border); }
.who { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.who button { padding: 6px 10px; }
.who .who-link {
  background: none; border: none; padding: 6px 2px; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--border);
}
.who .who-link:hover:not(:disabled), .who .who-link.active { text-decoration-color: var(--highlight); }
.who .who-link.active { color: var(--highlight); }
.who .who-link.active .muted { color: inherit; }

.login-page { max-width: 420px; padding-top: 10vh; }
.login-panel { padding: 28px; }
.login-title { font-size: 1.4rem; margin: 0 0 16px; text-align: center; }
.login-title span { font-weight: 400; color: var(--muted); font-size: 1rem; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form h2 { margin: 0; font-size: 1.1rem; }
.login-form label { display: flex; flex-direction: column; gap: 4px; font-size: 1rem; color: var(--muted); }
.login-form input { font-size: 1.1rem; padding: 10px 12px; }
.login-page .alert { margin: 0 0 14px; max-width: none; }

.user-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.user-actions button { padding: 6px 10px; font-size: 0.9rem; }

.form select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
}

button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

nav button.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.badge {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 6px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.8em;
  text-align: center;
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.primary:hover:not(:disabled) { filter: brightness(1.08); }

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

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--yellow);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.panel h2 { margin: 0 0 12px; font-size: 1.1rem; }
.center { text-align: center; padding: 48px 20px; }
.muted { color: var(--muted); }

.alert {
  max-width: 880px;
  margin: 0 auto 8px;
  padding: 10px 16px;
  border-radius: 8px;
  background: rgba(255, 98, 140, 0.15);
  color: var(--again);
  border: 1px solid var(--again);
  cursor: pointer;
}

/* ---------- Study ---------- */
.progress { color: var(--muted); margin: 0 0 12px; font-size: 0.9rem; }
.progress-row { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; margin-bottom: 12px; }
.progress-row .progress { margin: 0; }
.study-categories { position: relative; font-size: 0.9rem; }
.study-categories summary { cursor: pointer; color: var(--muted); list-style: none; }
.study-categories[open] summary { color: inherit; }
.study-categories-menu { position: absolute; right: 0; z-index: 5; margin-top: 4px; padding: 8px 10px; min-width: 12rem; max-height: 18rem; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px; background: var(--panel, #fff); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,.15); }
.study-categories-menu label { display: flex; align-items: center; gap: 0.5rem; white-space: nowrap; }

.flashcard {
  min-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  user-select: none;
}

.character {
  font-size: calc(5rem + 3pt);
  line-height: 1.1;
  font-family: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", serif;
}

.prompt-pinyin { font-size: 3rem; line-height: 1.2; }
.meaning-front { display: flex; flex-direction: column; gap: 8px; }
.meaning-front > div { font-size: 1.6rem; }
.meaning-front > div:first-child { font-size: 2.2rem; color: var(--text, inherit); font-weight: 600; }

.pinyin { color: var(--highlight); font-size: 1.2rem; }
.english { font-size: 1.4rem; font-weight: 600; }
.dutch, .swedish { font-size: 1.1rem; color: var(--muted); }
.example { margin-top: 8px; font-size: 1.05rem; font-style: italic; }
.comment { margin-top: 8px; font-size: 0.95rem; color: var(--muted); white-space: pre-line; }
.card-list .comment { margin-top: 2px; font-size: 0.85rem; }
.lang-options { display: flex; gap: 16px; flex-wrap: wrap; }
.lang-options .check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.hint { color: var(--muted); }

.controls { margin: 12px 0; }

.segmented { display: inline-flex; flex-wrap: wrap; gap: 0; }
.segmented button {
  border-radius: 0;
  margin-left: -1px;
  font-size: 0.9rem;
  padding: 6px 12px;
}
.segmented button:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.segmented button:last-child { border-radius: 0 8px 8px 0; }
.segmented button.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.grades {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.grades .wide { grid-column: 1 / -1; padding: 12px; font-size: 1rem; }

.grade {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 6px;
  color: var(--on-grade);
  border: none;
  font-weight: 600;
}

.next-row { display: flex; justify-content: space-between; margin-top: 12px; }

.grade small { font-weight: 400; opacity: 0.85; font-size: 0.78rem; }
.grade.again { background: var(--panel); color: var(--text); border: 1px solid var(--border); }
.grade.hard { background: var(--hard); }
.grade.good { background: var(--good); }
.grade.easy { background: var(--easy); }

/* ---------- Cards ---------- */
.form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 1rem;
  color: var(--muted);
}

.form input {
  font-size: 1.15rem;
  padding: 11px 12px;
}

.combo { position: relative; display: block; }
.combo input { padding-right: 38px; }
.combo .sparkle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  display: flex; padding: 5px; line-height: 0; border-radius: 6px; color: var(--highlight);
}
.sparkle-icon { width: 18px; height: 18px; fill: currentColor; }
.suggestions {
  position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px; list-style: none; max-height: 16rem; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}
.suggestions li { padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 1.05rem; color: var(--text); }
.suggestions li.muted { cursor: default; font-size: 0.95rem; }
.suggestions li.active { background: var(--accent); color: var(--accent-text); }
.suggestions li.muted { color: var(--muted); }
.suggestions li.meta { font-size: 0.8rem; text-align: right; padding: 2px 10px; cursor: default; }

.form .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; }

input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  width: 100%;
}

input:focus { outline: 2px solid var(--muted); outline-offset: 1px; }

.list-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.list-head input[type="search"] { width: auto; min-width: 180px; }

.card-list { list-style: none; padding: 0; margin: 0; }

.card-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.card-list li:first-child { border-top: none; }

.info { min-width: 0; }
.char { font-size: 1.3rem; margin-right: 8px; font-family: "Noto Sans SC", "PingFang SC", serif; }
.card-list .pinyin { font-size: 0.95rem; }
.meanings { margin-top: 2px; }
.meta { display: flex; gap: 8px; font-size: 0.8rem; margin-top: 4px; flex-wrap: wrap; }

.status {
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.status.reviewed { color: var(--good); }
.status.mastered { color: var(--highlight); }
.due { color: var(--highlight); font-weight: 600; }

.row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; flex-shrink: 0; }
.card-row { display: flex; justify-content: space-between; gap: 12px; }
/* Cards page: the whole row is the toggle for the study-state panel. */
.card-row.pick { justify-content: flex-start; align-items: flex-start; cursor: pointer; border-radius: 8px; padding: 4px 6px; margin: -4px -6px; }
.card-row.pick:hover, .card-row.pick[aria-expanded="true"] { background: var(--panel); }
.card-row.pick:focus-visible { outline: 2px solid var(--muted); }
input[type="checkbox"] { width: auto; flex-shrink: 0; }
.row-select { margin-top: 6px; width: 18px; height: 18px; cursor: pointer; }
.list-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.select-all-row {
  display: flex; align-items: center; gap: 12px; padding: 0 0 8px; font-size: 0.9rem;
  color: var(--muted); cursor: pointer; width: fit-content;
}
.select-all-row input { width: 18px; height: 18px; cursor: pointer; }
.row-status {
  margin-left: auto; flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end;
  gap: 4px; font-size: 0.8rem; text-align: right;
}
.card-list li { display: block; }

.state-panel {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.state-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin: 0 0 12px;
}
.state-stats dt { font-size: 0.8rem; color: var(--muted); }
.state-stats dd { margin: 0; font-weight: 600; }

.state-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.state-actions label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
.state-actions select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}
.small { font-size: 0.8rem; margin: 8px 0 0; }

@media (max-width: 560px) {
  .form { grid-template-columns: 1fr; }
  .character { font-size: calc(4rem + 3pt); }
  .prompt-pinyin { font-size: 2.4rem; }
  .meaning-front > div:first-child { font-size: 1.8rem; }
  .grades { grid-template-columns: repeat(2, 1fr); }
  .list-head input[type="search"] { width: 100%; }
}

.duplicate-warning {
  padding: 8px 12px; border: 1px solid var(--hard); border-radius: 8px;
  color: var(--hard); font-size: 0.95rem;
}
.duplicate-warning .dup-item { display: block; margin-top: 4px; color: var(--text); }
.duplicate-warning button { margin-left: 8px; padding: 2px 8px; font-size: 0.85rem; }

.flashcard { position: relative; }
.flashcard.revealed { user-select: text; cursor: auto; }
.speak-btn {
  position: absolute; top: 10px; right: 10px; padding: 6px 10px; font-size: 1.2rem; line-height: 1; border-radius: 8px;
}
button.loading { animation: speak-pulse 0.9s ease-in-out infinite; }
@keyframes speak-pulse { 50% { opacity: 0.4; } }
.tts-log { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.tts-log th, .tts-log td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--border); }
/* Card detail actions share the top menu's button look (no red delete text). */
.state-actions button, .state-actions select {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
}
.state-actions button.danger { color: var(--text); }
.list-tools button.danger { color: var(--text); }

/* Sentences */
.sentence-switch { margin: 0 0 12px; }
.sentence-text { font-size: 1.8rem; line-height: 1.5; font-family: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", serif; }
.sentence-pinyin { font-size: 1.3rem; line-height: 1.5; }
.sentence-line { font-size: 1.15rem; font-weight: 600; }

/* Inference page: stats and recent requests share one panel */
.panel-sep { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.panel h3 { margin: 0 0 8px; font-size: 1rem; }

/* Translate */
.translate-form { display: flex; gap: 8px; }
.translate-form input { flex: 1; min-width: 0; }
.translate-results { list-style: none; margin: 0; padding: 0; }
.translate-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.translate-item:last-child { border-bottom: 0; }
.translate-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.translate-head .sentence-text.small { font-size: 1.3rem; }
.translate-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.translate-actions .tag { margin-right: auto; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted, #777); }
.score { margin-left: auto; font-weight: 600; font-size: .85rem; padding: 2px 10px; border-radius: 999px; border: 1px solid currentColor; }
.score.high { color: #1a7f37; }
.score.mid { color: #b26a00; }
.score.low { color: #c62828; }
.score.unknown { color: var(--muted, #777); }
.notice { margin: 12px 0 0; font-weight: 500; }


/* Narrow screens (phones): the Words/Sentences/Translate tabs move into the hamburger menu, so the
   header stays on one line and the dropdown can't be pushed off the left edge. */
@media (max-width: 640px) {
  .topbar { flex-wrap: nowrap; }
  .topbar-right { flex-wrap: nowrap; }
  .topbar-right nav { display: none; }
  .menu-nav { display: block; }
  .menu-list { min-width: min(220px, calc(100vw - 32px)); max-width: calc(100vw - 32px); }
}

/* Stroke order */
.listen-btn { right: 58px; }
.stroke-btn { right: 10px; }
.modal-backdrop { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, 0.55); }
.modal { position: relative; min-width: min(360px, 100%); max-width: 100%; max-height: 100%; overflow: auto; padding: 68px 32px 24px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); }
.stroke-chars { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.stroke-char { border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.stroke-char svg { display: block; }
/* Ruler lines (米字格): vertical, horizontal and both diagonals, behind the transparent SVG. */
.stroke-char.with-grid {
  --g: #e0a0a0;
  background:
    linear-gradient(to right, transparent calc(50% - .5px), var(--g) calc(50% - .5px), var(--g) calc(50% + .5px), transparent calc(50% + .5px)),
    linear-gradient(to bottom, transparent calc(50% - .5px), var(--g) calc(50% - .5px), var(--g) calc(50% + .5px), transparent calc(50% + .5px)),
    linear-gradient(to top right, transparent calc(50% - .5px), var(--g) calc(50% - .5px), var(--g) calc(50% + .5px), transparent calc(50% + .5px)),
    linear-gradient(to bottom right, transparent calc(50% - .5px), var(--g) calc(50% - .5px), var(--g) calc(50% + .5px), transparent calc(50% + .5px)),
    #fff;
}
.modal-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.button-link { margin-right: auto; font-size: 0.9rem; }
.modal-close { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; padding: 0; font-size: 1.4rem; line-height: 1; border-radius: 8px; }
.translate-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.row-status .score { margin-left: 0; padding: 1px 8px; font-size: inherit; font-weight: 400; }
.history-text { font-size: 1.05rem; }
.state-actions.actions-right { justify-content: flex-end; }
.translate-item .state-panel { margin-top: 10px; }
.add-menu { position: relative; display: flex; }
.add-menu .menu-list { top: calc(100% + 6px); }
.notice a { margin-left: 6px; }

.stroke-options { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin: 8px 0; }
.stroke-options label { display: inline-flex; align-items: center; gap: 6px; }
.stroke-settings { margin: 8px 0; text-align: left; }
.stroke-settings summary { cursor: pointer; color: var(--muted, #666); font-size: .9em; }

.link-btn { padding: 0 6px; margin-left: 4px; background: none; border: none; cursor: pointer; font-size: 1rem; }
.fill-btn { display: inline-flex; align-items: center; color: var(--highlight); }
.fill-btn.loading .sparkle-icon { animation: fill-pulse 0.8s ease-in-out infinite alternate; }
@keyframes fill-pulse { from { opacity: 0.3; } to { opacity: 1; } }
.category-tag {
  display: inline-block; margin-left: 0.5rem; padding: 1px 8px; border: 1px solid var(--border);
  border-radius: 999px; font-size: 0.8rem; color: var(--muted); vertical-align: middle;
}
.category-list { list-style: none; display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0 1rem; padding: 0; }
.category-list .category-tag { margin-left: 0; }
.recent-requests > summary { cursor: pointer; list-style-position: outside; }
.recent-requests > summary h3 { display: inline; }
.category-admin { list-style: none; margin: 0.5rem 0 1rem; padding: 0; }
.category-admin li { display: flex; align-items: center; gap: 0.75rem; padding: 6px 0; border-bottom: 1px solid var(--border); }
.category-admin .category-name { font-weight: 600; }
.category-admin .category-actions { margin-left: auto; display: flex; gap: 0.4rem; }
.uncategorized-list { list-style: none; margin: 0.5rem 0; padding: 0; max-height: 20rem; overflow-y: auto; }
.uncategorized-list li { display: flex; align-items: baseline; gap: 0.75rem; padding: 4px 0; border-bottom: 1px solid var(--border); }
