/* Settings pop-up: springs in from the gear button, bottom sheet on phones. */
.settings-modal {
  width: min(700px, calc(100% - 28px));
  max-height: min(760px, calc(100dvh - 32px));
  overflow: hidden;
  border-color: var(--line);
  border-radius: 28px;
  background: var(--modal-bg);
}
.settings-modal[open] { animation: settings-pop 420ms cubic-bezier(.2, 1.1, .3, 1) both; }
.settings-card { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto; max-height: inherit; }

.settings-header { display: flex; align-items: center; gap: 14px; padding: 24px 24px 18px; }
.settings-header-icon { display: grid; place-items: center; flex: 0 0 auto; width: 46px; height: 46px; color: var(--on-accent); border-radius: 15px; background: var(--accent); font-size: 25px; box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 28%, transparent); }
.settings-modal[open] .settings-header-icon i { display: block; animation: settings-gear 900ms cubic-bezier(.2, .8, .2, 1) both; }
.settings-header > div { flex: 1; min-width: 0; }
.settings-header h2 { margin: 0; font-size: 26px; line-height: 1.1; letter-spacing: -.03em; }
.settings-header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.settings-saved { display: inline-flex; align-items: center; gap: 5px; padding: 6px 10px; color: var(--accent-text); border-radius: 999px; background: var(--accent-soft); font-size: 12px; font-weight: 800; opacity: 0; transform: translateY(-4px) scale(.9); transition: opacity 200ms ease, transform 260ms cubic-bezier(.2, 1.2, .3, 1); pointer-events: none; }
.settings-saved.visible { opacity: 1; transform: none; }
.settings-header .close-button { display: grid; place-items: center; flex: 0 0 auto; font-size: 20px; }
.settings-header .close-button:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }

.settings-tabs { position: relative; isolation: isolate; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; margin: 0 24px; padding: 4px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }
.settings-tab { position: relative; z-index: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 10px; color: var(--muted); border: 0; border-radius: 12px; background: transparent; cursor: pointer; font-size: 14px; font-weight: 750; transition: color 200ms ease, transform 120ms ease; }
.settings-tab i { font-size: 18px; }
.settings-tab:hover { color: var(--text-strong); }
.settings-tab[aria-selected="true"] { color: var(--on-accent); }
.settings-tab:active { transform: scale(.96); }
.settings-tab:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.settings-tab-marker { position: absolute; inset: 4px auto 4px 0; z-index: 0; border-radius: 12px; background: var(--accent); box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 30%, transparent); transition: transform 320ms cubic-bezier(.3, 1.25, .4, 1), width 320ms cubic-bezier(.3, 1.25, .4, 1); pointer-events: none; }

.settings-viewport { min-height: 0; height: min(500px, calc(100dvh - 300px)); overflow: hidden; }
.settings-panel { height: 100%; overflow-y: auto; padding: 20px 24px 24px; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.settings-panel.entering .settings-section, .settings-panel.entering .settings-empty { animation: settings-section-in 420ms cubic-bezier(.2, .8, .25, 1) both; animation-delay: calc(var(--i, 0) * 55ms); }
.settings-section + .settings-section { margin-top: 24px; }
.settings-section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.settings-section-head h3 { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--text-2); font-size: 13px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.settings-section-head h3 i { color: var(--accent-ink); font-size: 17px; }
.settings-pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; color: var(--accent-text); border-radius: 999px; background: var(--accent-soft); font-size: 12px; font-weight: 800; }
.settings-hint { display: flex; align-items: flex-start; gap: 8px; margin: 12px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.settings-hint i { flex: 0 0 auto; margin-top: 2px; color: var(--accent-ink); font-size: 15px; }

/* Theme cards with a live miniature of the app in that theme. */
.theme-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.theme-options.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.theme-option { display: grid; gap: 10px; padding: 8px 8px 12px; color: var(--text); text-align: left; border: 2px solid var(--line); border-radius: 20px; background: var(--surface-2); cursor: pointer; transition: border-color 200ms ease, transform 200ms cubic-bezier(.2, 1.2, .3, 1), box-shadow 200ms ease; }
.theme-option:hover { border-color: var(--line-strong); transform: translateY(-2px); }
.theme-option:active { transform: scale(.97); }
.theme-option[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.theme-option:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 3px; }
.theme-option-label { display: flex; align-items: center; gap: 7px; padding: 0 4px; font-size: 14px; font-weight: 800; }
.theme-option-label > i { color: var(--muted); font-size: 17px; }
.theme-check { display: grid; place-items: center; width: 22px; height: 22px; margin-left: auto; color: var(--on-accent); border: 2px solid var(--line-strong); border-radius: 50%; font-size: 13px; transition: background-color 200ms ease, border-color 200ms ease; }
.theme-check i { opacity: 0; transform: scale(.4); transition: opacity 160ms ease, transform 260ms cubic-bezier(.2, 1.4, .3, 1); }
.theme-option[aria-checked="true"] .theme-check { border-color: var(--accent); background: var(--accent); }
.theme-option[aria-checked="true"] .theme-check i { opacity: 1; transform: none; }

.theme-preview { position: relative; display: grid; grid-template-rows: auto auto 1fr; gap: 6px; height: 112px; padding: 10px; overflow: hidden; color: var(--text); border-radius: 13px; background: radial-gradient(circle at 90% 0%, var(--bg-glow) 0, transparent 70%), var(--bg); box-shadow: inset 0 0 0 1px var(--line); }
.tp-top { display: flex; align-items: center; justify-content: space-between; }
.tp-top b { width: 38%; height: 8px; border-radius: 4px; background: var(--text); opacity: .85; }
.tp-top span { width: 22%; height: 10px; border-radius: 6px; background: var(--control); box-shadow: inset 0 0 0 1px var(--line); }
.tp-tabs { display: flex; gap: 4px; }
.tp-tabs b, .tp-tabs span { width: 26%; height: 9px; border-radius: 4px; background: var(--control); }
.tp-tabs b { background: var(--accent); }
.tp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 8px; background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); }
.tp-grid i { border-left: 3px solid var(--c); border-radius: 4px; background: var(--surface-high); }
.theme-preview[data-theme="karneval"]::before, .theme-preview[data-theme="weihnachten"]::before { content: ""; position: absolute; inset: 0 0 auto; height: 4px; }
.theme-preview[data-theme="karneval"]::before { background: repeating-linear-gradient(90deg, var(--karneval-red) 0 10px, #fff 10px 20px); }
.theme-preview[data-theme="weihnachten"]::before { background: repeating-linear-gradient(90deg, var(--xmas-red) 0 8px, var(--accent) 8px 16px, var(--xmas-green) 16px 24px); }

/* Accent swatches. */
.accent-options { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.accent-option { display: grid; justify-items: center; gap: 8px; padding: 12px 6px 10px; color: var(--text-2); border: 2px solid transparent; border-radius: 18px; background: transparent; cursor: pointer; font-size: 13px; font-weight: 750; transition: background-color 180ms ease, border-color 180ms ease, transform 120ms ease; }
.accent-option:hover { background: var(--surface-2); }
.accent-option:active { transform: scale(.95); }
.accent-option:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.accent-option[aria-checked="true"] { color: var(--text-strong); border-color: var(--line); background: var(--surface-2); }
.accent-swatch { display: grid; place-items: center; width: 46px; height: 46px; color: var(--on-accent); border-radius: 50%; background: var(--accent); box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent), inset 0 -3px 0 rgba(0, 0, 0, .12); font-size: 21px; transition: transform 300ms cubic-bezier(.2, 1.4, .3, 1), box-shadow 200ms ease; }
.accent-swatch i { opacity: 0; transform: scale(.3) rotate(-30deg); transition: opacity 160ms ease, transform 300ms cubic-bezier(.2, 1.4, .3, 1); }
.accent-option:hover .accent-swatch { transform: scale(1.06); }
.accent-option[aria-checked="true"] .accent-swatch { transform: scale(1.1); box-shadow: 0 0 0 4px var(--modal-bg), 0 0 0 6px var(--accent), 0 8px 22px color-mix(in srgb, var(--accent) 40%, transparent); }
.accent-option[aria-checked="true"] .accent-swatch i { opacity: 1; transform: none; }

/* Subject choices. */
.subject-choices { display: flex; flex-wrap: wrap; gap: 8px; }
.subject-choices.described { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.subject-choice { display: grid; align-content: center; gap: 2px; min-height: 42px; padding: 9px 14px; color: var(--text-2); text-align: left; border: 1px solid var(--line-strong); border-radius: 13px; background: var(--surface-2); cursor: pointer; font-size: 14px; transition: color 160ms ease, background-color 160ms ease, border-color 160ms ease, transform 120ms ease, box-shadow 160ms ease; }
.subject-choice strong { font-weight: 750; }
.subject-choice small { color: var(--muted); font-size: 12px; font-weight: 600; }
.subject-choice:hover { color: var(--text-strong); border-color: var(--accent-line); }
.subject-choice:active { transform: scale(.97); }
.subject-choice:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.subject-choice[aria-checked="true"] { color: var(--text-strong); border-color: var(--accent); background: var(--accent-surface); box-shadow: 0 0 0 3px var(--accent-soft); animation: settings-choice-pop 320ms cubic-bezier(.2, 1.3, .3, 1); }
.subject-choice[aria-checked="true"] small { color: var(--text-2); }

.course-rows { display: grid; gap: 8px; }
.course-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 8px 8px 8px 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-2); }
.course-row > span { display: inline-flex; align-items: center; gap: 9px; font-size: 15px; font-weight: 750; }
.course-row > span i { color: var(--muted); font-size: 19px; }
.segmented { display: inline-grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 3px; padding: 3px; border-radius: 12px; background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); }
.segmented .subject-choice { min-height: 38px; min-width: 88px; padding: 0 12px; text-align: center; border: 0; border-radius: 10px; background: transparent; box-shadow: none; animation: none; }
.segmented .subject-choice[aria-checked="true"] { color: var(--on-accent); background: var(--accent); box-shadow: 0 3px 10px color-mix(in srgb, var(--accent) 30%, transparent); }

/* Switch rows. */
.switch-list { display: grid; gap: 8px; }
.switch-row { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; align-items: center; gap: 14px; width: 100%; padding: 14px 16px 14px 14px; color: var(--text); text-align: left; border: 1px solid var(--line); border-radius: 18px; background: var(--surface-2); cursor: pointer; transition: border-color 180ms ease, background-color 180ms ease, transform 120ms ease; }
.switch-row:hover { border-color: var(--line-strong); }
.switch-row:active { transform: scale(.99); }
.switch-row:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.switch-icon { display: grid; place-items: center; width: 42px; height: 42px; color: var(--muted); border-radius: 13px; background: var(--control); font-size: 21px; transition: color 200ms ease, background-color 200ms ease; }
.switch-row[aria-checked="true"] .switch-icon { color: var(--accent-ink); background: var(--accent-soft); }
.switch-copy { display: grid; gap: 3px; min-width: 0; }
.switch-copy strong { font-size: 15px; }
.switch-copy small { color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.switch-track { position: relative; width: 50px; height: 30px; border-radius: 999px; background: var(--line-strong); transition: background-color 220ms ease; }
.switch-thumb { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .3); transition: transform 300ms cubic-bezier(.3, 1.4, .4, 1), width 160ms ease; }
.switch-row:active .switch-thumb { width: 28px; }
.switch-row[aria-checked="true"] .switch-track { background: var(--accent); }
.switch-row[aria-checked="true"] .switch-thumb { transform: translateX(20px); }
.switch-row[aria-checked="true"]:active .switch-thumb { transform: translateX(16px); }

.settings-empty { display: grid; justify-items: center; gap: 10px; padding: 34px 16px; text-align: center; }
.settings-empty-icon { display: grid; place-items: center; width: 64px; height: 64px; color: var(--accent-ink); border-radius: 20px; background: var(--accent-soft); font-size: 30px; }
.settings-empty h3 { margin: 6px 0 0; font-size: 20px; }
.settings-empty p { max-width: 360px; margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.settings-primary { display: inline-flex; align-items: center; gap: 9px; min-height: 48px; margin-top: 8px; padding: 0 20px; color: var(--on-accent); border: 0; border-radius: 14px; background: var(--accent); cursor: pointer; font-size: 15px; font-weight: 800; transition: background-color 160ms ease, transform 120ms ease; }
.settings-primary:hover { background: var(--accent-hover); }
.settings-primary:active { transform: scale(.97); }
.settings-primary:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 3px; }

.settings-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px max(16px, env(safe-area-inset-bottom)); color: var(--faint); border-top: 1px solid var(--line); font-size: 12px; }
.settings-footer button { padding: 4px; color: var(--muted); border: 0; background: none; cursor: pointer; font: inherit; font-weight: 700; text-decoration: underline; }
.settings-footer button:hover { color: var(--text-strong); }
.settings-footer button:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }

@keyframes settings-pop { from { opacity: 0; transform: translateY(18px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes settings-gear { from { transform: rotate(-120deg) scale(.6); } to { transform: none; } }
@keyframes settings-section-in { from { opacity: 0; transform: translate(var(--from, 0), 10px); } to { opacity: 1; transform: none; } }
@keyframes settings-choice-pop { 0% { transform: scale(.96); } 60% { transform: scale(1.03); } 100% { transform: none; } }
@keyframes settings-sheet { from { transform: translateY(100%); } to { transform: none; } }

@media (max-width: 600px) {
  .settings-modal { inset: auto 0 0; width: 100%; max-width: 100%; max-height: 92dvh; margin: 0; border-width: 1px 0 0; border-radius: 26px 26px 0 0; }
  .settings-modal[open] { animation: settings-sheet 380ms cubic-bezier(.2, .9, .25, 1) both; }
  .settings-card::before { content: ""; justify-self: center; width: 40px; height: 5px; margin-top: 8px; border-radius: 3px; background: var(--line-strong); }
  .settings-card { grid-template-rows: auto auto auto minmax(0, 1fr) auto; }
  .settings-header { padding: 12px 18px 14px; }
  .settings-header-icon { width: 40px; height: 40px; font-size: 22px; border-radius: 13px; }
  .settings-header h2 { font-size: 22px; }
  .settings-header p { display: none; }
  .settings-tabs { margin: 0 18px; }
  .settings-tab { flex-direction: column; gap: 2px; min-height: 52px; font-size: 12px; }
  .settings-viewport { height: min(560px, calc(92dvh - 240px)); }
  .settings-panel { padding: 18px 18px 22px; }
  .theme-options, .theme-options.three { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
  .theme-preview { height: 88px; padding: 8px; }
  .theme-option { padding: 6px 6px 10px; border-radius: 17px; }
  .theme-option-label { font-size: 13px; gap: 5px; }
  .theme-option-label > i { display: none; }
  .accent-options { gap: 4px; }
  .subject-choices.described { grid-template-columns: 1fr; }
  .course-row { padding-left: 12px; }
  .segmented .subject-choice { min-width: 74px; }
  .settings-footer { padding-inline: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .settings-modal[open], .settings-panel.entering .settings-section, .settings-modal[open] .settings-header-icon i { animation: none; }
}
