/* =============================================================================
 *  ui/settings.css
 *  The Settings page (html.ns): one column of cards with a short list of
 *  sections beside it on computers, and a Save bar that stays in view while
 *  the settings above it are changed. Loaded after rekhyt-ui.css.
 *
 *  The voice, dictionary download, word reset and bug report parts are added
 *  by their own scripts with their own small styles; the names below
 *  (--panel, --border, --theme-*) let those styles pick up this look, and the
 *  rules at the end bring their dialogs in line.
 * ========================================================================== */
html.ns {
  --bg: var(--page); --panel: var(--surface); --border: var(--line); --selected: var(--brand); --matrix: var(--brand);
  --theme-text: var(--ink); --theme-surface: var(--surface); --theme-border: var(--line); --theme-accent: var(--focus);
  --danger: #A3362F; --danger-soft: #FBEDEB; --danger-strong: #A3362F; --danger-ink: #FFFFFF;
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236B6480' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
html.ns[data-style="night"] {
  --danger: #FF9C94; --danger-soft: rgba(255, 156, 148, .12); --danger-strong: #FF9C94; --danger-ink: #17112B;
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23A99FC6' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* ---------- page ---------- */
.ns-main { padding: 34px 0 80px; }
.ns-head { margin: 0 0 28px; }
.ns-head .back {
  display: inline-flex; align-items: center; min-height: 36px; color: var(--muted);
  font: 500 15px/1.2 var(--ui); text-decoration: none;
}
.ns-head .back:hover { color: var(--brand); }
.ns-head h1 { margin: 4px 0 8px; color: var(--ink); font: 700 34px/1.1 var(--ui); letter-spacing: -.02em; }
.ns-lead { max-width: 640px; margin: 0; color: var(--muted); font-size: 16px; line-height: 1.6; }

.ns-grid { display: grid; grid-template-columns: 196px minmax(0, 1fr); gap: 40px; align-items: start; }
.ns-nav { position: sticky; top: 96px; display: flex; flex-direction: column; gap: 2px; }
.ns-nav a { padding: 9px 12px; border-radius: 10px; color: var(--text); font: 500 15px/1.3 var(--ui); text-decoration: none; }
.ns-nav a:hover { background: var(--surface-2); color: var(--ink); }
.ns-nav a.is-here { background: var(--brand-soft); color: var(--brand); }

/* ---------- cards ---------- */
.panel { display: flex; flex-direction: column; gap: 20px; max-width: 780px; min-width: 0; }
.panel > section {
  margin: 0; padding: 26px 28px 28px; scroll-margin-top: 92px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 6px; color: var(--ink); font: 600 20px/1.3 var(--ui); letter-spacing: -.01em; text-transform: none; }
.panel h3 { margin: 26px 0 6px; padding-top: 22px; border-top: 1px solid var(--line); color: var(--ink); font: 600 16.5px/1.3 var(--ui); }
.panel .intro, .panel > section > p { margin: 0 0 18px; color: var(--muted); font-size: 15px; line-height: 1.55; }

/* ---------- controls (the same pattern the voice settings use) ---------- */
.controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 32px; }
.controls label {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px 12px; min-width: 0;
  color: var(--ink); font: 500 15px/1.35 var(--ui);
}
.controls label.ns-wide { grid-column: 1 / -1; max-width: calc(50% - 16px); }
.controls .value { color: var(--muted); font: 500 14px/1 var(--ui); font-variant-numeric: tabular-nums; white-space: nowrap; }
.controls .hint { grid-column: 1 / -1; margin: -8px 0 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
html.ns input[type="range"] {
  grid-column: 1 / -1; width: 100%; height: 28px; margin: 0; accent-color: var(--brand); cursor: pointer; background: transparent;
}
html.ns select {
  min-width: 0; max-width: 210px; height: 42px; padding: 0 36px 0 12px;
  border: 1px solid var(--line); border-radius: 10px; color: var(--ink);
  background: var(--page) var(--select-arrow) no-repeat right 13px center;
  font: 400 16px/1 var(--ui); -webkit-appearance: none; appearance: none; cursor: pointer;
}
html.ns[data-style="night"] select { background-color: var(--surface-2); }
html.ns select:hover { border-color: rgba(var(--brand-rgb), .55); border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); }
html.ns select option { background: var(--surface); color: var(--ink); }
html.ns input[type="color"] {
  width: 52px; height: 38px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer;
}

/* buttons: the settings scripts use .action and .action.primary */
html.ns button.action {
  display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink);
  font: 600 14.5px/1 var(--ui); letter-spacing: 0; text-transform: none; cursor: pointer; transition: border-color .15s, color .15s, background-color .15s;
}
html.ns button.action:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
html.ns button.action:disabled { opacity: .5; cursor: default; }
html.ns button.action.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
html.ns button.action.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: var(--brand-ink); }

/* Account > Invite a classmate (ui/invite.js); a link to #invite lands below the top bar */
#invite { scroll-margin-top: 92px; }
.invite-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.invite-row input {
  flex: 1 1 260px; min-width: 0; height: 42px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); color: var(--ink);
  font: 500 15px/1 var(--ui);
}
.invite-row input:focus { outline: 2px solid var(--focus); outline-offset: 0; }
.invite-box .invite-count { margin: 12px 0 0; color: var(--text); font-size: 15px; }
.invite-box .invite-done { color: var(--brand); font-weight: 600; }

/* ---------- Look: Daylight or Night ---------- */
.ns-looks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.ns-look {
  position: relative; display: flex; flex-direction: column; gap: 2px; padding: 12px 12px 14px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--page); cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
html.ns[data-style="night"] .ns-look { background: var(--surface-2); }
.ns-look:hover { border-color: var(--brand); }
.ns-look input { position: absolute; top: 18px; right: 18px; width: 1px; height: 1px; margin: 0; opacity: 0; }
.ns-look.is-on { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); background: var(--brand-soft); }
html.ns[data-style="night"] .ns-look.is-on { background: var(--brand-soft); }
.ns-look:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.ns-look-pic {
  display: flex; flex-direction: column; gap: 7px; height: 92px; margin-bottom: 10px; padding: 16px;
  border-radius: 10px; border: 1px solid rgba(36, 27, 61, .10);
}
.ns-look-pic.is-day { background: #FAF8F3; }
.ns-look-pic.is-night { background: #17112B; border-color: rgba(255, 255, 255, .12); }
.ns-look-pic i { display: block; height: 7px; border-radius: 4px; background: #241B3D; opacity: .8; }
.ns-look-pic.is-night i { background: #F4F0FF; opacity: .75; }
.ns-look-pic i:nth-child(2) { width: 88%; }
.ns-look-pic i:nth-child(3) { width: 62%; }
.ns-look-pic b { width: 58px; height: 16px; margin-top: auto; border-radius: 6px; background: #6B52B3; }
.ns-look-pic.is-night b { background: #B9A6FF; }
.ns-look-name { display: flex; align-items: center; justify-content: space-between; color: var(--ink); font: 600 16px/1.3 var(--ui); }
.ns-look.is-on .ns-look-name::after {
  content: ""; width: 9px; height: 15px; margin: 0 6px 4px 0; border: solid var(--brand); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg);
}
.ns-look-sub { color: var(--muted); font-size: 14px; line-height: 1.4; }

/* ---------- Reading: a live sample ---------- */
.ns-sample {
  max-height: 260px; overflow: auto; margin: 0 0 24px; padding: 22px 24px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--page); color: var(--ink);
  font-family: var(--s-font, var(--read)); font-size: var(--s-size, 19px); line-height: var(--s-line, 1.8); font-style: var(--s-style, normal);
}
html.ns[data-style="night"] .ns-sample { background: var(--surface-2); }
.ns-sample p { margin: 0; }

/* ---------- Practice colours ---------- */
.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; margin: 0 0 16px; }
.preset {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px; min-height: 78px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--page); color: var(--ink);
  font: 600 15px/1.2 var(--ui); text-align: left; cursor: pointer; transition: border-color .15s;
}
html.ns[data-style="night"] .preset { background: var(--surface-2); }
.preset:hover { border-color: var(--brand); }
.preset.active { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
html.ns .preset.active { background: var(--brand-soft); }
.preset .swatches { display: flex; gap: 6px; }
.preset .swatches i { display: block; width: 20px; height: 20px; border-radius: 50%; border: 1px solid rgba(128, 128, 128, .5); }

.ns-preview {
  position: relative; height: 176px; margin: 0 0 20px; overflow: hidden;
  border: 1px solid var(--line); border-radius: 12px; background: var(--pv-bg, #000);
}
.ns-preview canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.pv-card {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(300px, calc(100% - 32px));
  padding: 16px 18px; border: 1px solid var(--pv-line); border-radius: 10px;
  background: var(--pv-panel); color: var(--pv-text); font-family: var(--pv-font);
}
.pv-kicker { color: var(--pv-text); opacity: .7; font-size: 11.5px; letter-spacing: .14em; text-transform: uppercase; }
.pv-word { margin: 4px 0 0; font-size: 22px; font-weight: 600; line-height: 1.25; }
.pv-mean { margin: 0 0 10px; opacity: .8; font-size: 14px; }
.pv-pick { display: inline-block; padding: 3px 10px; border: 1px solid var(--pv-selected); border-radius: 999px; color: var(--pv-selected); font-size: 13px; }

.ns-more { margin-top: 20px; border-top: 1px solid var(--line); }
.ns-more > summary {
  display: flex; align-items: center; justify-content: space-between; min-height: 52px; list-style: none;
  color: var(--ink); font: 600 15.5px/1.3 var(--ui); cursor: pointer;
}
.ns-more > summary::-webkit-details-marker { display: none; }
.ns-more > summary::after {
  content: ""; width: 9px; height: 9px; margin: 0 6px 4px 0; border: solid var(--muted); border-width: 0 2px 2px 0;
  transform: rotate(45deg); transition: transform .15s;
}
.ns-more[open] > summary::after { transform: rotate(-135deg); margin-bottom: -4px; }
.ns-more > summary:hover { color: var(--brand); }
.ns-more > .controls { padding: 4px 0 6px; }
.ns-more + .ns-more { margin-top: 0; }

/* ---------- the Save bar ---------- */
.panel > .actions {
  position: sticky; bottom: 14px; z-index: 5; display: flex; align-items: center; gap: 10px; margin: 0;
  padding: 12px 12px 12px 20px; border: 1px solid var(--line); border-radius: 14px;
  background: rgba(var(--surface-rgb), .94);
  background: color-mix(in srgb, var(--surface) 94%, transparent); box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
#status { flex: 1; min-width: 0; margin: 0; color: var(--muted); font: 500 14.5px/1.3 var(--ui); }
#status.is-dirty { color: var(--ink); }
#status.is-dirty::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; background: var(--brand); vertical-align: 1px; }

/* ---------- Account ---------- */
.settings-links { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.settings-links [data-dictionary-downloads] { display: contents; }
.settings-links a, .settings-links button {
  display: inline-flex; align-items: center; max-width: 100%; min-height: 42px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink);
  font: 600 14.5px/1.2 var(--ui); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
}
.settings-links a:hover, .settings-links button:hover { border-color: var(--brand); color: var(--brand); }

/* ---------- parts added by the other settings scripts ---------- */
html.ns .voice-settings-box { padding: 0; border: 0; border-radius: 0; background: none; }
html.ns .voice-settings-actions { margin-top: 22px; gap: 10px; }
html.ns .voice-settings-actions .voice-status { color: var(--muted); font: 500 14px/1.3 var(--ui); }

html.ns #saved-word-reset { margin: 0; border: 1px solid var(--line); }
html.ns #saved-word-reset .action { border-color: var(--danger); border-color: color-mix(in srgb, var(--danger) 55%, var(--line)); color: var(--danger); }
html.ns #saved-word-reset .action:hover:not(:disabled) { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
html.ns #word-reset-result { margin: 12px 0 0; color: var(--ink); font-size: 15px; }
html.ns #word-reset-result a { color: var(--brand); font-weight: 600; }

html.ns #rekhyt-settings-support { margin: 0; padding: 26px 28px 28px; border: 1px solid var(--line); }
html.ns #rekhyt-settings-support p { margin: 0 0 18px; color: var(--muted); font-size: 15px; line-height: 1.55; }
html.ns #rekhyt-bug-launch {
  min-height: 42px; padding: 0 16px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); font: 600 14.5px/1 var(--ui);
}
html.ns #rekhyt-bug-launch:hover { border-color: var(--brand); color: var(--brand); }
html.ns #rekhyt-bug-launch:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* dialogs: dictionary downloads, word reset, bug report */
html.ns #dictionary-downloads-dialog, html.ns #word-reset-dialog, html.ns #rekhyt-bug-report {
  padding: 26px; border: 1px solid var(--line); border-radius: 16px;
  background: var(--surface); color: var(--text); box-shadow: 0 24px 70px rgba(23, 17, 43, .28);
  font: 400 15px/1.6 var(--ui);
}
html.ns #dictionary-downloads-dialog::backdrop, html.ns #word-reset-dialog::backdrop, html.ns #rekhyt-bug-report::backdrop { background: rgba(23, 17, 43, .55); }
html.ns #dictionary-downloads-dialog h2, html.ns #word-reset-dialog h2, html.ns #rekhyt-bug-report h2 {
  margin: 0 0 8px; color: var(--ink); font: 600 20px/1.3 var(--ui);
}
html.ns #dictionary-downloads-dialog button, html.ns #word-reset-dialog button, html.ns #rekhyt-bug-report button {
  min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); font: 600 14.5px/1 var(--ui); cursor: pointer;
}
html.ns #dictionary-downloads-dialog button:hover:not(:disabled), html.ns #word-reset-dialog button:hover:not(:disabled), html.ns #rekhyt-bug-report button:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
html.ns #dictionary-downloads-dialog :focus-visible, html.ns #word-reset-dialog :focus-visible, html.ns #rekhyt-bug-report :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
html.ns #dictionary-downloads-dialog .download-dict-danger { border-color: var(--danger) !important; border-color: color-mix(in srgb, var(--danger) 55%, var(--line)) !important; color: var(--danger); }
html.ns #word-reset-dialog .destructive, html.ns #word-reset-dialog .destructive:hover:not(:disabled) { border-color: var(--danger-strong); background: var(--danger-strong); color: var(--danger-ink); }
html.ns #word-reset-dialog { border-color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
html.ns #word-reset-dialog input[type="text"], html.ns #rekhyt-bug-report input:not([type="checkbox"]), html.ns #rekhyt-bug-report textarea {
  width: 100%; margin-top: 7px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--page); color: var(--ink); font: 400 16px/1.4 var(--ui);
}
html.ns[data-style="night"] #word-reset-dialog input[type="text"], html.ns[data-style="night"] #rekhyt-bug-report input:not([type="checkbox"]), html.ns[data-style="night"] #rekhyt-bug-report textarea { background: var(--surface-2); }
html.ns #word-reset-dialog input[type="checkbox"], html.ns #rekhyt-bug-report input[type="checkbox"] { accent-color: var(--brand); width: 17px; height: 17px; vertical-align: -3px; }
html.ns #rekhyt-bug-report label { color: var(--ink); font-weight: 500; }
html.ns #rekhyt-bug-report small, html.ns #word-reset-dialog small { color: var(--muted); }
html.ns #rekhyt-bug-report a { color: var(--brand); }
html.ns #rekhyt-bug-report button[type="submit"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
html.ns #rekhyt-bug-report button[type="submit"]:hover:not(:disabled) { background: var(--brand-hover); color: var(--brand-ink); }
html.ns #dictionary-downloads-list .download-dict-row { border-top-color: var(--line); }

/* ---------- inside the reader or the library (opened in a frame) ---------- */
html.ns-framed .topbar { display: none; }
html.ns-framed .ns-main { padding-top: 20px; }
html.ns-framed .ns-head .back {
  min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); font-weight: 600;
}
html.ns-framed .ns-head .back:hover { border-color: var(--brand); color: var(--brand); }
html.ns-framed .ns-nav { top: 20px; }

/* ---------- phones and small windows ---------- */
@media (max-width: 900px) {
  .ns-grid { grid-template-columns: minmax(0, 1fr); }
  .ns-nav { display: none; }
  .panel { max-width: none; }
}
@media (max-width: 640px) {
  .ns-main { padding: 22px 0 56px; }
  .ns-head { margin-bottom: 20px; }
  .ns-head h1 { font-size: 28px; }
  .ns-lead { font-size: 15px; }
  .panel { gap: 16px; }
  .panel > section, html.ns #rekhyt-settings-support { padding: 20px 18px 22px; }
  .controls { grid-template-columns: minmax(0, 1fr); gap: 18px; }
  .controls label.ns-wide { max-width: none; }
  .controls .hint { margin-top: -10px; }
  .ns-looks { gap: 10px; }
  .ns-look-pic { height: 72px; padding: 12px; }
  .ns-look-sub { font-size: 13.5px; }
  .presets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ns-sample { padding: 18px; }
  .panel > .actions { bottom: 10px; flex-wrap: wrap; padding: 10px; }
  .panel > .actions .action { flex: 1 1 0; }
  #status { flex-basis: 100%; padding: 2px 4px 0; }
  #status:empty { display: none; }
  html.ns #dictionary-downloads-dialog, html.ns #word-reset-dialog, html.ns #rekhyt-bug-report { padding: 20px 18px; }
}
