:root{--theme-ink:#12213d;--theme-muted:#536780;color-scheme:light}
:root[data-theme="dark"]{--theme-ink:#e9eff9;--theme-muted:#a8b7ce;--theme-panel:#18273c;--theme-control:#25364f;--theme-line:#3b4e68;--theme-blue:#94c3ff;--theme-red:#ffb1b7;--theme-green:#a4e7c0;--theme-amber:#f2d093;--lg-ink:#e9eff9;--lg-line:#ffffff30;--lg-glass:#ffffff0c;color-scheme:dark;background:#101827}
html[data-theme] body>header{padding-bottom:18px!important}
html[data-theme] body>header #themeToggle{
  position:fixed;right:max(14px,env(safe-area-inset-right));top:max(10px,env(safe-area-inset-top));z-index:2147483647;
  display:inline-flex!important;align-items:center;justify-content:center;width:42px;height:42px;padding:9px;
  border-radius:50%;border:1px solid #ffffff90;background:#ffffff48;color:#17345d;
  backdrop-filter:blur(16px) saturate(150%);-webkit-backdrop-filter:blur(16px) saturate(150%);
  box-shadow:0 5px 20px #21395d20,inset 0 1px 0 #ffffffa0;cursor:pointer;touch-action:manipulation;
}
#themeToggle svg{width:24px;height:24px;pointer-events:none}
#themeToggle:focus-visible{outline:3px solid #4599ff;outline-offset:3px}
#themeToggle:active{scale:.94}
html[data-theme="dark"] body{
  color:var(--theme-ink)!important;
  background:radial-gradient(90% 50% at 50% 0%,#24457580,transparent 72%),radial-gradient(70% 50% at 0% 60%,#49366e45,transparent 75%),radial-gradient(70% 45% at 100% 85%,#174b4d45,transparent 75%),linear-gradient(180deg,#101827,#131d30 50%,#191b32)!important;
}
/* Scope the palette to the existing page roots, including detached dialogs. */
/* The public welcome page owns a light palette, independently of app theme. */
html[data-theme="dark"] :is(body,header,#cloudSyncBar,#home,#a,#ratings,#decks,#deckDetail,#sharedLibrary,#sharedDeckEditor,#profileModal,#authGate,#streakPage,#aiModal,#battleOverlay,#medArena) :is(h1,h2,h3,h4,p,b,strong,small,span,label,summary,li,td,th,button,a,div):not(:where(#welcome,#welcome *)){color:var(--theme-ink)!important;text-shadow:none!important}
html[data-theme="dark"] body :is(header,#cloudSyncBar,.card,.stat,.folder,.drop-root,.deck-tile,.swipe-card,.study-card,.study-session-zone,.study-session-stage,.profile-card,.auth-card,.ai-window,.streak-modal,.explain-box,.edit-card-box,.study-history-card,.study-session-bubble-panel,.more-menu,dialog,.shared-editor-footer,.battle-paused-card){
  background:linear-gradient(145deg,#1b2b43e8,#17243ae8)!important;border-color:#ffffff22!important;
  box-shadow:0 15px 42px #00000030,inset 0 1px 0 #ffffff20!important;
}
html[data-theme="dark"] :is(body,#decks,#medArena,#authGate,#profileModal) :is(input:not([type="checkbox"]):not([type="radio"]),textarea,select,.btn.alt,.icon-btn,.folder-toggle,.study-history-btn,.study-session-option,.day-dot,.streak-close,.more-menu button,.next-review,.schedule-note){background:#17263fb8!important;color:#edf3ff!important;border-color:#8aa6d046!important}
html[data-theme="dark"] :is(input,textarea)::placeholder{color:#a8b9d1!important;opacity:1}
html[data-theme="dark"] :is(body,#home,#streakPage) :is(.muted,.subtle,.stat-label,.drop-hint,.streak-calendar-label,.streak-weekday){color:var(--theme-muted)!important}
html[data-theme="dark"] :is(#authGate,#profileModal){background:#060d1c70!important}
html[data-theme="dark"] :is(body,#aiModal,#battleOverlay) :is(.modal-box,.ai-messages,.ai-bubble,.ai-welcome,.ai-form,.shared-lib-folder,.shared-lib-folder-head,.shared-lib-deck,.shared-lib-form,.shared-editor-card,.shared-editor-question,.shared-editor-footer,.study-history-total,.study-history-day,.study-history-pill,.study-history-detail,.study-history-count,.battle-picker-folder,.battle-folder-heading,.battle-manager-folder,.battle-question-editor-card,.battle-question-editor-number,.battle-question-option-field,.battle-bank-option,.battle-notice,.battle-option){background:#1b2b43e0!important;border-color:#ffffff2a!important}
html[data-theme="dark"] #battleOverlay :is(input,textarea,select){background:#17263f!important;color:#edf3ff!important;border-color:#8aa6d046!important}
html[data-theme="dark"] :is(#battleOverlay,#medArena) :is(.correct,.is-correct){background:#163e32!important;border-color:#64cda3!important}
html[data-theme="dark"] :is(#battleOverlay,#medArena) :is(.wrong,.incorrect,.is-wrong){background:#4b2632!important;border-color:#ee91a3!important}
html[data-theme="dark"] body :is(nav,#quickDock){background:linear-gradient(145deg,#263c5d70,#17263f50)!important;border-color:#ffffff2e!important}
html[data-theme="dark"] nav .tab{background:#ffffff0e!important;border-color:#ffffff24!important;box-shadow:inset 0 1px 0 #ffffff20!important}
html[data-theme="dark"] nav.glass-motion-nav .tab.active{background:transparent!important;color:#75b6ff!important}
html[data-theme="dark"] #cloudSyncBar #authUserBar :is(span,small){color:#b5c3da!important}
html[data-theme="dark"] body>nav#quickDock.glass-dock{background:linear-gradient(180deg,#ffffff14,#a7c7ff09)!important;border-color:#ffffff35!important;box-shadow:0 10px 35px #0005,inset 0 1px 0 #ffffff35!important}
html[data-theme="dark"] .glass-nav-drop{background:linear-gradient(180deg,#ffffff26,#ffffff15);border-color:#ffffff40;box-shadow:inset 0 1px 1px #ffffff70,inset 0 -1px 1px #ffffff18,0 3px 10px #0003}
html[data-theme="dark"] .glass-dock.is-holding .glass-nav-drop{background:#ffffff08;box-shadow:inset 0 1px 1px #ffffffa0,inset 1px 0 1px #80b4ff80,inset -1px 0 1px #f5a4ca50,0 8px 24px #0004}
html[data-theme="dark"] #quickDock .dock-btn:is(.active,.is-liquid-target) :is(span,small){color:#75b6ff!important}
html[data-theme="dark"] #quickDock.is-holding .dock-btn.active:not(.is-liquid-target) :is(span,small){color:#edf3ff!important}
html[data-theme="dark"] :is(#battleOverlay,.battle-fullscreen-shell,.battle-card,.battle-score-panel,.battle-recovery){background:#14223a!important;border-color:#ffffff26!important}
html[data-theme="dark"] #medArena{--ma-bg:#111a2c;--ma-panel:#1b2940;--ma-line:#42506a;--ma-ink:#edf3ff;--ma-muted:#bdc9de;--ma-mint:#b69aff;--ma-coral:#ffa878;background:var(--ma-bg)!important;color-scheme:dark}
html[data-theme="dark"] #medArena :is(.ma-setup,.ma-panel,.ma-manager-panel,.ma-dialog,.ma-question,.ma-team-card,.ma-card,.ma-stat,.ma-cat-row,.ma-qrow,.ma-note,.ma-resume,.ma-column,.ma-category,.ma-answer,.ma-chip,.ma-qpoints,.ma-awards,.ma-board-info,.ma-board-foot,.ma-form-preview,.ma-finish,.ma-team-row,.ma-status){background:#1b2940!important;border-color:#42506a!important;box-shadow:none!important}
html[data-theme="dark"] #medArena :is(.ma-header,.ma-nav,.ma-tabs,.ma-scoreboard){background:#152239!important;border-color:#42506a!important}
html[data-theme="dark"] body>header #themeToggle{background:#1b2b4378;color:#f8d478!important;border-color:#ffffff40;box-shadow:0 5px 20px #0004,inset 0 1px 0 #ffffff30}

/* Pair foreground and surface colors; white text must never inherit a light control. */
html[data-theme="dark"] body button:not(:where(#welcome *)){background:var(--theme-control)!important;border-color:var(--theme-line)!important;color:var(--theme-ink)!important;box-shadow:none!important}
html[data-theme="dark"] body button:disabled{opacity:.55}
html[data-theme="dark"] :is(body,#decks,#battleOverlay,#medArena) .btn:not(.alt):not(.danger):not(.bad):not(.warn):not(.good){background:#315fb5!important;color:#fff!important;border-color:#6388c9!important}
html[data-theme="dark"] :is(body,#decks,#battleOverlay,#medArena) :is(.btn.danger,.btn.bad){background:#432b39!important;border-color:#795062!important;color:var(--theme-red)!important}
html[data-theme="dark"] :is(body,#decks,#battleOverlay,#medArena) :is(.btn.good,.study-pause-btn[aria-pressed="true"]){background:#1e3b32!important;border-color:#426d59!important;color:var(--theme-green)!important}
html[data-theme="dark"] :is(body,#decks,#battleOverlay,#medArena) .btn.warn{background:#403723!important;border-color:#75613d!important;color:var(--theme-amber)!important}
html[data-theme="dark"] :is(body,#decks,#battleOverlay,#medArena) :is(.btn,.study-pause-btn,.folder-action,.deck-action) :is(span,small,b){color:inherit!important}
html[data-theme="dark"] #decks :is(.folder-action,.deck-action,.study-pause-btn){background:var(--theme-control)!important;border:1px solid var(--theme-line)!important;color:var(--theme-ink)!important}
html[data-theme="dark"] #decks :is(.folder-action,.deck-action){font-size:12px!important}
html[data-theme="dark"] #decks :is(.folder-action,.deck-action)[data-action="rename"]{font-size:18px!important}
html[data-theme="dark"] #decks .deck-metrics{font-size:11px!important;line-height:1.6}
html[data-theme="dark"] #decks :is(.folder-action,.deck-action)[data-action="delete"]{background:#432b39!important;color:var(--theme-red)!important;border-color:#795062!important}
html[data-theme="dark"] #decks .deck-action[data-action="study"]{background:#203d67!important;color:#b4d5ff!important;border-color:#496b9b!important}
html[data-theme="dark"] #decks .study-pause-btn[aria-pressed="true"]{background:#1e3b32!important;color:var(--theme-green)!important;border-color:#426d59!important}
html[data-theme="dark"] #decks .deck-metrics>span{background:#26364e!important;color:#cbd7e9!important;border:1px solid #3b4c65}
html[data-theme="dark"] #decks .deck-metrics>.has-due{background:#203b62!important;color:#b3d5ff!important;border-color:#47658b}
html[data-theme="dark"] #decks .deck-metrics>:is(.deck-weak,.deck-difficulty){background:#3b3326!important;color:#f1d29a!important;border-color:#68583c}
html[data-theme="dark"] #decks .deck-tile>.row>.actions{border-top-color:#3b4e68!important}
html[data-theme="dark"] #decks :is(.folder-symbol,.folder-color-picker){background:#25364f!important;border-color:#3b4e68!important;box-shadow:none!important}
html[data-theme="dark"] #decks .folder.folder-colored{background:#18273c!important;background:color-mix(in srgb,var(--folder-accent) 12%,#18273c)!important;border-color:color-mix(in srgb,var(--folder-accent) 55%,#3b4e68)!important}
html[data-theme="dark"] #decks .folder-color-button .folder-color-indicator{color:var(--folder-accent)!important}
html[data-theme="dark"] #decks .folder-color-options>.folder-color-swatch{background:var(--swatch)!important;border-color:#18273c!important;color:#fff!important}
html[data-theme="dark"] #decks :is(.deck-paused-label,.folder-end,.deck-location,.drop-hint){color:var(--theme-muted)!important}
html[data-theme="dark"] #decks :is(.deck-tile,.folder).study-paused{background:#1b302d!important;border-color:#426454!important}
html[data-theme="dark"] #decks .deck-tile:hover{border-color:#58769e!important;box-shadow:none!important}
html[data-theme="dark"] #decks .folder-colored>.folder-head .folder-symbol{background:#25364f!important;box-shadow:none!important}
html[data-theme="dark"] #cloudSyncBar #authUserBar button{background:#25364f!important;color:#e9eff9!important;border-color:#4b6283!important;box-shadow:none!important}
html[data-theme="dark"] #cloudSyncBar #authUserBar #authLogoutBtn{background:#432b39!important;color:#ffb1b7!important;border-color:#795062!important}
html[data-theme="dark"] :is(input,textarea):-webkit-autofill{-webkit-text-fill-color:#e9eff9!important;box-shadow:inset 0 0 0 1000px #17263f!important}
html[data-theme="dark"] #battleOverlay :is(.battle-library-manage-entry,.battle-library-admin,.battle-library-item,.battle-panel,.battle-question-card,.battle-state-card,.battle-player,.battle-choice,.battle-choice-letter,.battle-status-pill,.battle-room-code){background:var(--theme-panel)!important;color:var(--theme-ink)!important;border-color:var(--theme-line)!important;box-shadow:none!important}
html[data-theme="dark"] #battleOverlay :is(.battle-secondary-btn,.battle-control-btn,.battle-bank-option,.battle-folder-toggle){background:var(--theme-control)!important;color:var(--theme-ink)!important;border-color:var(--theme-line)!important}
html[data-theme="dark"] #battleOverlay .battle-primary-btn{background:#315fb5!important;color:#fff!important;border-color:#6388c9!important}
html[data-theme="dark"] #battleOverlay .battle-library-manage-entry :is(span,p){color:var(--theme-muted)!important}
html[data-theme="dark"] :is(body,#aiModal,#sharedLibrary,#sharedDeckEditor) :is(.rich-editor,.rich-toolbar,.make-card-item,.preview-explain,.admin-user-card,.shared-lib-empty,.profile-row,.profile-field){background:var(--theme-panel)!important;border-color:var(--theme-line)!important}
html[data-theme="dark"] :is(body,#sharedLibrary,#sharedDeckEditor) :is(.shared-lib-add-dock,.shared-lib-coming,.shared-lib-readonly,.shared-lib-cards,.shared-lib-card,.shared-lib-card-index,.shared-deck-editor,.shared-deck-editor-meta,.shared-editor-card-summary,.shared-new-card,.shared-lib-deck-icon,.shared-lib-deck-count,.shared-add-tab){background:var(--theme-panel)!important;border-color:var(--theme-line)!important}
html[data-theme="dark"] :is(body,#sharedLibrary,#sharedDeckEditor) .shared-add-tab.active{background:#203d67!important;color:#b4d5ff!important;border-color:#496b9b!important}
html[data-theme="dark"] #aiModal .ai-msg.user .ai-bubble{background:#244875!important;border-color:#52749f!important}
html[data-theme="dark"] #profileModal .profile-primary{background:#315fb5!important;color:#fff!important;border-color:#6388c9!important}
html[data-theme="dark"] #authGate :is(#passkeyLogin,#authSubmitBtn){background:var(--theme-control)!important;color:var(--theme-ink)!important;border-color:var(--theme-line)!important}
html[data-theme="dark"] #authGate #authSubmitBtn{background:#315fb5!important;color:#fff!important;border-color:#6388c9!important}
html[data-theme="dark"] #authGate #authSwitchBtn{background:transparent!important;color:#94c3ff!important}
html[data-theme="dark"] :is(body,#battleOverlay,#medArena,#decks,#authGate) input[type="checkbox"]{appearance:none;-webkit-appearance:none;width:20px;height:20px;min-width:20px;padding:0!important;display:inline-block;vertical-align:middle;border:1.5px solid #7e94b2!important;border-radius:6px;background:#142238!important;cursor:pointer}
html[data-theme="dark"] :is(body,#battleOverlay,#medArena,#decks,#authGate) input[type="checkbox"]:checked{border-color:#6aa8fa!important;background:#3974c6 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='m4 10 4 4 8-9' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/18px no-repeat!important}
html[data-theme="dark"] :is(body,#battleOverlay,#medArena,#decks,#authGate) input[type="checkbox"]:focus-visible{outline:3px solid #75b6ff;outline-offset:3px}
/* Keep navigation transparent and preserve the selected glass lens. */
html[data-theme="dark"] #quickDock .dock-btn{background:transparent!important;border-color:transparent!important;box-shadow:none!important}
html[data-theme="dark"] nav.glass-motion-nav .tab{background:#ffffff06!important;border-color:#ffffff22!important}
html[data-theme="dark"] nav.glass-motion-nav .tab.active{background:transparent!important}
html[data-theme="dark"] body>header #themeToggle{background:#1e304acc!important;border-color:#4b6283!important;color:#f2d093!important;box-shadow:0 4px 16px #0003!important}


/* Header controls share the streak height and scroll with the header. */
html[data-theme] body>header .header-tools{display:grid;grid-template-rows:minmax(0,1fr) minmax(0,1fr);gap:3px;flex:0 0 40px;width:40px;height:var(--header-tools-height,54px);align-self:center}
html[data-theme] body>header .header-tools>.ai-head-btn,
html[data-theme] body>header .header-tools>#themeToggle{position:static!important;inset:auto!important;width:40px!important;height:100%!important;min-width:0!important;min-height:0!important;max-height:none!important;margin:0!important;padding:2px 3px!important;border-radius:10px!important;display:flex!important;align-items:center;justify-content:center;gap:2px;font-size:10px!important;line-height:1!important;transform:none!important;z-index:auto!important}
html[data-theme] body>header #themeToggle svg{width:17px;height:17px}
html[data-theme] body{min-height:100vh;min-height:100dvh}
html[data-theme="dark"]{background:#191b32!important}
html[data-theme="dark"] body{background-attachment:scroll!important}
html[data-theme="dark"] body::before{background:none!important}
@media(max-width:700px){html[data-theme] body>header{padding-bottom:15px!important}}

html[data-theme="light"]{background:#dbe8ff!important}
html[data-theme="dark"]{background:#101827!important}
html[data-theme] body{margin-top:0!important;display:flow-root}

/* Extend the page behind the iPhone status area while protecting content. */
html[data-theme] body{padding-top:env(safe-area-inset-top,0px)!important;padding-left:env(safe-area-inset-left,0px);padding-right:env(safe-area-inset-right,0px)}

/* Keep the dock at its original bottom gap after enabling edge-to-edge iPhone layout. */
html[data-theme] body>nav#quickDock.glass-dock{position:fixed!important;top:auto!important;bottom:9px!important}
html[data-theme] body>#studySessionFloat{bottom:91px!important}

/* The resting lens must identify the current destination over any page content. */
html[data-theme="light"] #quickDock:not(.is-holding) .glass-nav-drop{
 background:linear-gradient(155deg,rgba(255,255,255,.76),rgba(130,184,255,.48))!important;
 border:1px solid rgba(255,255,255,.95)!important;
 box-shadow:inset 0 1px 2px #fff,inset 0 -1px 1px #5284c859,0 0 0 1px #3974c638,0 3px 12px #315d8f30!important;
 backdrop-filter:blur(10px) saturate(155%);-webkit-backdrop-filter:blur(10px) saturate(155%);
}
html[data-theme="light"] #quickDock .dock-btn.active :is(span,small){color:#075cb7!important}
html[data-theme="dark"] #quickDock:not(.is-holding) .glass-nav-drop{
 background:linear-gradient(155deg,#a3ccff55,#408bdf45)!important;
 border:1px solid #b5d8ff8c!important;
 box-shadow:inset 0 1px 2px #ffffff70,inset 0 -1px 1px #b5d8ff40,0 0 0 1px #10182750,0 3px 12px #0004!important;
 backdrop-filter:blur(10px) saturate(155%);-webkit-backdrop-filter:blur(10px) saturate(155%);
}
html[data-theme="light"] #quickDock.is-holding .dock-btn.active:not(.is-liquid-target) :is(span,small){color:#405575!important}

/* Android PWA: one native scrolling root, without a nested body scrollport or
   repainting a viewport-fixed gradient through every repeated blurred panel. */
html[data-platform="android"]{overflow-x:clip;overflow-y:auto;overscroll-behavior-y:auto}
html[data-platform="android"] body{overflow-x:clip!important;overflow-y:visible!important;background-attachment:scroll!important}
html[data-platform="android"] :is(.deck-tile,.folder,.stat){backdrop-filter:none!important;-webkit-backdrop-filter:none!important}
html[data-platform="android"].streak-modal-active{overflow:hidden!important}
