/* ============================================================
   SmartOS — desktop shell
   An original macOS-inspired desktop: menu bar, dock, draggable
   glass windows. No Apple artwork is used; every icon, wallpaper
   and control here is drawn from scratch in CSS/SVG.
   ============================================================ */

:root {
  --mb-h: 28px;              /* menu bar height */
  --dock-h: 74px;
  --win-radius: 12px;
  --sf: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", Inter, system-ui, sans-serif;
  --sf-mono: "SF Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --glass: rgba(255,255,255,.62);
  --glass-thick: rgba(255,255,255,.80);
  --glass-chrome: rgba(246,246,248,.72);
  --hairline: rgba(0,0,0,.12);
  --hairline-soft: rgba(0,0,0,.07);
  --ink: #1d1d1f;
  --ink-2: #4b4b52;
  --ink-3: #86868b;
  --accent: #0a6cff;
  --ok: #28a745; --warn: #d68b00; --bad: #e0453a;
  --blur-win: saturate(180%) blur(24px);
  --blur-chrome: saturate(200%) blur(30px);
  --shadow-win: 0 0 0 .5px rgba(0,0,0,.18), 0 18px 50px rgba(0,0,0,.28), 0 4px 12px rgba(0,0,0,.14);
  --shadow-win-inactive: 0 0 0 .5px rgba(0,0,0,.12), 0 8px 24px rgba(0,0,0,.16);
}

html[data-appearance="dark"] {
  --glass: rgba(42,42,46,.66);
  --glass-thick: rgba(38,38,42,.86);
  --glass-chrome: rgba(30,30,34,.72);
  --hairline: rgba(255,255,255,.16);
  --hairline-soft: rgba(255,255,255,.08);
  --ink: #f5f5f7; --ink-2: #c7c7cc; --ink-3: #8e8e93;
  --accent: #3b8bff;
  --shadow-win: 0 0 0 .5px rgba(255,255,255,.10), 0 18px 50px rgba(0,0,0,.6), 0 4px 12px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body.smartos {
  margin: 0; font-family: var(--sf); color: var(--ink);
  font-size: 13.5px; -webkit-font-smoothing: antialiased;
  overflow: hidden; user-select: none;
}
/* Signed-out / full-page screens scroll normally and select normally. */
body.smartos.page { overflow: auto; height: auto; min-height: 100%; user-select: text; }

/* ---------------- Wallpaper (original gradient mesh) ---------------- */
.wallpaper {
  position: fixed; inset: 0; z-index: -1;   /* always behind content */
  background:
    radial-gradient(120vh 90vh at 18% 8%,  #4a86ff 0%, transparent 55%),
    radial-gradient(110vh 80vh at 88% 18%, #9b5cf0 0%, transparent 55%),
    radial-gradient(120vh 90vh at 72% 88%, #14b8c4 0%, transparent 58%),
    radial-gradient(100vh 80vh at 8%  92%, #2a3d8f 0%, transparent 55%),
    linear-gradient(160deg, #1b2a6b 0%, #2d1b5e 55%, #0f2f4f 100%);
}
html[data-appearance="dark"] .wallpaper { filter: brightness(.66) saturate(1.1); }
.wallpaper::after {           /* subtle grain so gradients don't band */
  content: ""; position: absolute; inset: 0; opacity: .16; mix-blend-mode: overlay;
  background-image: radial-gradient(rgba(255,255,255,.5) .5px, transparent .5px);
  background-size: 3px 3px;
}

/* ---------------- Menu bar ---------------- */
.menubar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--mb-h); z-index: 900;
  display: flex; align-items: center; gap: 18px; padding: 0 12px;
  background: rgba(255,255,255,.28);
  -webkit-backdrop-filter: var(--blur-chrome); backdrop-filter: var(--blur-chrome);
  border-bottom: .5px solid rgba(255,255,255,.22);
  color: #fff; font-size: 12.5px; font-weight: 500;
  text-shadow: 0 0 6px rgba(0,0,0,.25);
}
html[data-appearance="dark"] .menubar { background: rgba(0,0,0,.35); }
.mb-logo { width: 15px; height: 15px; flex: none; }
.mb-item { padding: 2px 8px; border-radius: 5px; cursor: default; white-space: nowrap; }
.mb-item.strong { font-weight: 650; }
.mb-item:hover, .mb-item[aria-expanded="true"] { background: rgba(255,255,255,.24); }
.mb-right { margin-left: auto; display: flex; align-items: center; gap: 14px; font-variant-numeric: tabular-nums; }
.mb-pill { display: inline-flex; align-items: center; gap: 5px; }
.mb-dot { width: 7px; height: 7px; border-radius: 50%; background: #46d160; box-shadow: 0 0 6px #46d160aa; }

/* dropdown menus */
.mb-menu {
  position: fixed; top: calc(var(--mb-h) - 2px); min-width: 220px; z-index: 950;
  background: var(--glass-thick);
  -webkit-backdrop-filter: var(--blur-chrome); backdrop-filter: var(--blur-chrome);
  border: .5px solid var(--hairline); border-radius: 9px;
  box-shadow: 0 12px 32px rgba(0,0,0,.28); padding: 5px; color: var(--ink);
  text-shadow: none; font-weight: 400;
}
.mb-menu button, .mb-menu a {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  width: 100%; text-align: left; font: inherit; color: inherit;
  background: none; border: 0; padding: 5px 10px; border-radius: 5px; cursor: pointer; text-decoration: none;
}
.mb-menu button:hover, .mb-menu a:hover { background: var(--accent); color: #fff; }
.mb-menu hr { border: 0; border-top: .5px solid var(--hairline); margin: 5px 8px; }
.mb-menu .key { color: var(--ink-3); font-size: 11.5px; }
.mb-menu button:hover .key, .mb-menu a:hover .key { color: rgba(255,255,255,.75); }

/* ---------------- Desktop ---------------- */
.desktop { position: fixed; inset: var(--mb-h) 0 0 0; z-index: 1; }

/* ---------------- Windows ---------------- */
.win {
  position: absolute; display: flex; flex-direction: column;
  min-width: 380px; min-height: 240px;
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur-win); backdrop-filter: var(--blur-win);
  border-radius: var(--win-radius); box-shadow: var(--shadow-win-inactive);
  overflow: hidden; opacity: 0; transform: scale(.97);
  animation: winIn .18s cubic-bezier(.2,.9,.3,1) forwards;
}
@keyframes winIn { to { opacity: 1; transform: scale(1); } }
.win.active { box-shadow: var(--shadow-win); }
.win.minimised { display: none; }
.win.zoomed { border-radius: 0; }

.win-bar {
  height: 38px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: var(--glass-chrome);
  -webkit-backdrop-filter: var(--blur-chrome); backdrop-filter: var(--blur-chrome);
  border-bottom: .5px solid var(--hairline-soft); cursor: grab;
}
.win-bar:active { cursor: grabbing; }
.lights { display: flex; gap: 8px; flex: none; }
.light {
  width: 12px; height: 12px; border-radius: 50%; border: .5px solid rgba(0,0,0,.16);
  padding: 0; cursor: pointer; position: relative; display: grid; place-items: center;
}
.light svg { opacity: 0; width: 7px; height: 7px; }
.lights:hover .light svg { opacity: .55; }
.light-close { background: #ff5f57; }
.light-min   { background: #febc2e; }
.light-zoom  { background: #28c840; }
.win:not(.active) .light { background: #d6d6d8; border-color: rgba(0,0,0,.10); }
html[data-appearance="dark"] .win:not(.active) .light { background: #4a4a4e; }
.win-title {
  flex: 1; text-align: center; font-size: 13px; font-weight: 600; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-left: -56px; pointer-events: none;
}
.win-tools { flex: none; display: flex; gap: 6px; }
.win-tool {
  width: 26px; height: 22px; border-radius: 5px; border: 0; background: transparent;
  color: var(--ink-2); cursor: pointer; display: grid; place-items: center;
}
.win-tool:hover { background: var(--hairline-soft); }

.win-body {
  flex: 1; overflow: auto; padding: 18px 22px; background: rgba(255,255,255,.55);
  user-select: text; -webkit-overflow-scrolling: touch;
}
html[data-appearance="dark"] .win-body { background: rgba(28,28,32,.5); }
.win-body.plain { background: var(--glass-thick); }   /* opaque-ish for reading */
.win-resize {
  position: absolute; right: 0; bottom: 0; width: 16px; height: 16px;
  cursor: nwse-resize; z-index: 3;
}

/* ---------------- Dock ---------------- */
.dock-wrap { position: fixed; left: 0; right: 0; bottom: 6px; z-index: 800; display: flex; justify-content: center; pointer-events: none; }
.dock {
  pointer-events: auto; display: flex; align-items: flex-end; gap: 6px; padding: 6px 8px;
  background: rgba(255,255,255,.30);
  -webkit-backdrop-filter: var(--blur-chrome); backdrop-filter: var(--blur-chrome);
  border: .5px solid rgba(255,255,255,.32); border-radius: 18px;
  box-shadow: 0 10px 34px rgba(0,0,0,.30);
}
html[data-appearance="dark"] .dock { background: rgba(0,0,0,.34); border-color: rgba(255,255,255,.12); }
.dock-sep { width: .5px; align-self: stretch; margin: 6px 4px; background: rgba(255,255,255,.35); }
.dock-item {
  position: relative; width: 52px; height: 52px; border: 0; padding: 0; background: none;
  cursor: pointer; border-radius: 13px; transition: transform .14s cubic-bezier(.2,.9,.3,1);
  transform-origin: bottom center;
}
.dock-item:hover { transform: scale(1.28) translateY(-6px); }
.dock-item:hover + .dock-item, .dock-item:has(+ .dock-item:hover) { transform: scale(1.12) translateY(-2px); }
.dock-item svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 3px 6px rgba(0,0,0,.28)); border-radius: 13px; }
.dock-item .runner {
  position: absolute; bottom: -4px; left: 50%; transform: translateX(-50%);
  width: 4px; height: 4px; border-radius: 50%; background: rgba(255,255,255,.9); opacity: 0;
}
.dock-item.running .runner { opacity: 1; }
.dock-tip {
  position: absolute; bottom: 62px; left: 50%; transform: translateX(-50%);
  background: var(--glass-thick); -webkit-backdrop-filter: var(--blur-chrome); backdrop-filter: var(--blur-chrome);
  color: var(--ink); border: .5px solid var(--hairline); border-radius: 7px;
  padding: 3px 9px; font-size: 12px; white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity .12s; box-shadow: 0 6px 18px rgba(0,0,0,.2);
}
.dock-item:hover .dock-tip { opacity: 1; }

/* ---------------- Content styling inside windows ---------------- */
.win-body h1 { font-size: 1.45rem; font-weight: 700; letter-spacing: -.02em; margin: 0 0 .4em; }
.win-body h2 { font-size: 1.08rem; font-weight: 650; letter-spacing: -.01em; margin: 1.2em 0 .5em; }
.win-body h2:first-child, .win-body h1:first-child { margin-top: 0; }
.win-body h3 { font-size: .96rem; font-weight: 620; margin: 1em 0 .4em; }
.win-body p { margin: 0 0 .9em; line-height: 1.5; }
.win-body a { color: var(--accent); text-decoration: none; }
.win-body a:hover { text-decoration: underline; }

.card {
  background: rgba(255,255,255,.72); border: .5px solid var(--hairline-soft);
  border-radius: 11px; padding: 15px 17px; margin-bottom: 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
html[data-appearance="dark"] .card { background: rgba(255,255,255,.06); }
.grid { display: grid; gap: 14px; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

.stat .stat-label { color: var(--ink-3); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat .stat-value { font-size: 1.75rem; font-weight: 700; letter-spacing: -.03em; margin-top: 1px; }
.stat .stat-sub { color: var(--ink-2); font-size: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: 12.5px; font-weight: 550; padding: 5px 13px;
  border-radius: 7px; border: .5px solid var(--hairline); cursor: pointer;
  background: linear-gradient(180deg, rgba(255,255,255,.95), rgba(246,246,248,.92));
  color: var(--ink); box-shadow: 0 1px 1px rgba(0,0,0,.05);
}
html[data-appearance="dark"] .btn { background: linear-gradient(180deg, rgba(88,88,94,.9), rgba(70,70,76,.9)); }
.btn:hover { filter: brightness(.98); text-decoration: none; }
.btn:active { filter: brightness(.94); }
.btn-primary { background: linear-gradient(180deg, #3d8bff, var(--accent)); border-color: transparent; color: #fff; box-shadow: 0 1px 2px rgba(10,108,255,.4); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-danger { background: linear-gradient(180deg, #f0685e, var(--bad)); border-color: transparent; color: #fff; }
.btn-lg { font-size: 14px; padding: 8px 18px; border-radius: 9px; }
.btn-sm { font-size: 11.5px; padding: 3px 9px; border-radius: 6px; }
.btn-ghost { background: none; border-color: transparent; box-shadow: none; color: var(--ink-2); }
.btn-ghost:hover { background: var(--hairline-soft); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin: 12px 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], select, textarea {
  font: inherit; font-size: 13px; width: 100%; padding: 6px 9px; border-radius: 7px;
  border: .5px solid var(--hairline); background: rgba(255,255,255,.9); color: var(--ink);
  box-shadow: inset 0 1px 1px rgba(0,0,0,.04);
}
html[data-appearance="dark"] input, html[data-appearance="dark"] select, html[data-appearance="dark"] textarea { background: rgba(0,0,0,.28); }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(10,108,255,.28); }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row > div { flex: 1; min-width: 150px; }
.help { color: var(--ink-3); font-size: 11.5px; margin-top: 3px; }
.checkline { display: flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 500; margin: 6px 0; }
.checkline input { width: auto; }

table.data { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data th { text-align: left; font-weight: 620; color: var(--ink-3); padding: 6px 8px; border-bottom: .5px solid var(--hairline); white-space: nowrap; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; }
table.data td { padding: 6px 8px; border-bottom: .5px solid var(--hairline-soft); }
table.data tr:hover td { background: rgba(0,0,0,.03); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 11px; font-weight: 620; border: .5px solid var(--hairline); color: var(--ink-2); }
.badge-ok { color: #157f2c; background: rgba(40,167,69,.12); border-color: rgba(40,167,69,.35); }
.badge-warn { color: #9a6400; background: rgba(214,139,0,.12); border-color: rgba(214,139,0,.35); }
.badge-bad { color: #b5271d; background: rgba(224,69,58,.12); border-color: rgba(224,69,58,.35); }
.badge-accent { color: var(--accent); background: rgba(10,108,255,.10); border-color: rgba(10,108,255,.3); }

.progressbar { height: 6px; border-radius: 20px; background: rgba(0,0,0,.10); overflow: hidden; }
.progressbar > span { display: block; height: 100%; border-radius: 20px; background: linear-gradient(90deg, #3d8bff, var(--accent)); }
.tasklist { list-style: none; margin: 0; padding: 0; }
.tasklist li { display: flex; align-items: center; gap: 9px; padding: 7px 0; border-bottom: .5px solid var(--hairline-soft); font-size: 12.5px; }
.tasklist li:last-child { border-bottom: 0; }
.alert { padding: 9px 13px; border-radius: 9px; margin-bottom: 12px; font-size: 12.5px; border: .5px solid; }
.alert-info { background: rgba(10,108,255,.08); border-color: rgba(10,108,255,.3); color: var(--accent); }
.alert-ok { background: rgba(40,167,69,.09); border-color: rgba(40,167,69,.35); color: #157f2c; }
.alert-error { background: rgba(224,69,58,.09); border-color: rgba(224,69,58,.35); color: #b5271d; }
.muted { color: var(--ink-3); } .small { font-size: 11.5px; } .mb0 { margin-bottom: 0; } .mt0 { margin-top: 0; }
.inline { display: inline; }
.chart-svg { width: 100%; height: auto; display: block; }
.tutor { background: rgba(10,108,255,.06); border: .5px solid rgba(10,108,255,.22); border-radius: 9px; padding: 10px 13px; margin-top: 9px; }
.tutor h4 { margin: 0 0 4px; color: var(--accent); font-size: 12px; font-weight: 650; }
.result-q { background: rgba(255,255,255,.7); border: .5px solid var(--hairline-soft); border-radius: 10px; padding: 13px 15px; margin-bottom: 12px; }
html[data-appearance="dark"] .result-q { background: rgba(255,255,255,.05); }
.result-q.correct { border-left: 3px solid var(--ok); }
.result-q.partial { border-left: 3px solid var(--warn); }
.result-q.wrong { border-left: 3px solid var(--bad); }
details.explain summary { cursor: pointer; font-weight: 600; color: var(--accent); font-size: 12.5px; margin-top: 6px; }

.spinner { width: 22px; height: 22px; border: 2.5px solid var(--hairline); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Login / boot screen */
.boot {
  position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center;
}
.boot-card {
  width: 340px; text-align: center; padding: 30px 28px 26px;
  background: var(--glass-thick); -webkit-backdrop-filter: var(--blur-win); backdrop-filter: var(--blur-win);
  border: .5px solid var(--hairline); border-radius: 16px; box-shadow: 0 24px 60px rgba(0,0,0,.4);
}
.boot-avatar { width: 74px; height: 74px; margin: 0 auto 12px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(150deg, #4a86ff, #9b5cf0); box-shadow: 0 6px 18px rgba(0,0,0,.3); color: #fff; font-size: 30px; font-weight: 600; }
.boot-card h1 { font-size: 17px; font-weight: 620; margin: 0 0 2px; }
.boot-card .sub { color: var(--ink-3); font-size: 12.5px; margin-bottom: 16px; }
.boot-card input { text-align: center; }
.boot-foot { position: fixed; bottom: 18px; left: 0; right: 0; text-align: center; color: rgba(255,255,255,.72); font-size: 11px; padding: 0 20px; text-shadow: 0 0 6px rgba(0,0,0,.4); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Small screens: windows go full-bleed, dock shrinks */
@media (max-width: 820px) {
  .win { left: 0 !important; top: 0 !important; width: 100% !important; height: 100% !important; border-radius: 0; }
  .dock-item { width: 44px; height: 44px; }
  .win-title { margin-left: 0; }
}
