/* ============================================================
   SOMNIA — pixel sleep OS
   ============================================================ */

:root {
  /* moonlight palette (default) */
  --bg-0:        #060818;
  --bg-1:        #0e1230;
  --bg-2:        #1a1f4a;
  --panel:       #2a2363;
  --panel-2:     #3a3380;
  --chrome:      #4b3f8a;
  --chrome-hi:   #6a5dbf;
  --line:        #8475d4;
  --ink:         #f6ecd6;
  --ink-dim:     #d7c9f2;
  --ink-faint:   #9a8bc9;
  --moon:        #ffe8a3;
  --rose:        #ff8fb8;
  --cyan:        #7de2d1;
  --violet:      #c490e4;
  --danger:      #ff5c7a;
  --success:     #82e6a4;

  --px: 4px;          /* base pixel scale */
  --font-pixel: "Press Start 2P", monospace;
  --font-mono: "VT323", monospace;
  --taskbar-h: 44px;
  --mobile-edge: 8px;
}

/* dusk palette */
[data-palette="dusk"] {
  --bg-0:   #1a0a1f;
  --bg-1:   #2b1233;
  --bg-2:   #4a1b3f;
  --panel:  #6b2548;
  --panel-2:#8a3554;
  --chrome: #b04864;
  --chrome-hi: #d9657c;
  --line:   #f0a586;
  --ink:    #fff1d6;
  --ink-dim:#ffcbb3;
  --ink-faint: #b07670;
  --moon:   #ffd56b;
  --rose:   #ff7a5c;
  --cyan:   #ffb89a;
  --violet: #ff8fb8;
}

/* gameboy palette (4 greens) */
[data-palette="gameboy"] {
  --bg-0:   #0f380f;
  --bg-1:   #1d4d1d;
  --bg-2:   #306230;
  --panel:  #306230;
  --panel-2:#5a8c4a;
  --chrome: #8bac0f;
  --chrome-hi: #9bbc0f;
  --line:   #9bbc0f;
  --ink:    #e0f8d0;
  --ink-dim:#9bbc0f;
  --ink-faint: #5a8c4a;
  --moon:   #e0f8d0;
  --rose:   #9bbc0f;
  --cyan:   #8bac0f;
  --violet: #5a8c4a;
}

/* dawn palette */
[data-palette="dawn"] {
  --bg-0:   #1a1230;
  --bg-1:   #3a2854;
  --bg-2:   #6b3e6e;
  --panel:  #8a4a72;
  --panel-2:#b8627d;
  --chrome: #e07a82;
  --chrome-hi: #ff9d8a;
  --line:   #ffd197;
  --ink:    #fff4dc;
  --ink-dim:#ffcfa8;
  --ink-faint: #a07a8a;
  --moon:   #ffe07a;
  --rose:   #ff9d8a;
  --cyan:   #ffd197;
  --violet: #c490e4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg-0);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 22px;
  line-height: 1.25;
  overflow: hidden;
  height: 100%;
  width: 100%;
  overscroll-behavior: none;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: auto;
  image-rendering: pixelated;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

img, canvas, svg { image-rendering: pixelated; }

/* CRT overlay */
.crt::before {
  content: "";
  position: fixed; inset: 0;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(0,0,0,0.1) 0,
      rgba(0,0,0,0.1) 2px,
      transparent 2px,
      transparent 4px
    );
  pointer-events: none;
  z-index: 9998;
  mix-blend-mode: multiply;
}
.crt::after {
  content: "";
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.45) 100%);
  pointer-events: none;
  z-index: 9999;
}

/* ============================================================
   DESKTOP
   ============================================================ */

.desktop {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bg-0);
  min-height: 100dvh;
}

.scene-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  image-rendering: pixelated;
}
.scene-bg svg {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

/* vignette over the scene */
.scene-bg::after {
  content: "";
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.45) 100%);
  pointer-events: none;
}

/* ============================================================
   DESKTOP ICONS
   ============================================================ */

.desktop-icons {
  position: absolute;
  top: 32px; left: 32px;
  display: grid;
  grid-template-columns: repeat(2, 96px);
  gap: 18px 28px;
  z-index: 5;
}

.dicon {
  width: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 6px;
  background: transparent;
  border: none;
  user-select: none;
}

.dicon-art {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  position: relative;
  background: rgba(42, 35, 99, 0.92);
  box-shadow:
    inset 0 0 0 2px var(--chrome-hi),
    0 0 0 2px var(--bg-0),
    0 0 0 4px var(--chrome);
  transition: transform 0.1s steps(2);
}

.dicon:hover .dicon-art {
  transform: translate(-1px, -1px);
  box-shadow:
    inset 0 0 0 2px var(--moon),
    0 0 0 2px var(--bg-0),
    0 0 0 4px var(--chrome-hi);
}

.dicon-art svg { width: 32px; height: 32px; display: block; }

.dicon-label {
  font-family: var(--font-pixel);
  font-size: 9px;
  text-align: center;
  color: var(--ink);
  text-shadow:
    1px 1px 0 var(--bg-0),
    -1px 0 0 var(--bg-0),
    1px 0 0 var(--bg-0),
    0 1px 0 var(--bg-0),
    0 -1px 0 var(--bg-0);
  line-height: 1.5;
  letter-spacing: 0.02em;
  background: rgba(6, 8, 24, 0.5);
  padding: 2px 6px;
}

/* ============================================================
   WINDOWS
   ============================================================ */

.window {
  position: absolute;
  background: var(--panel);
  box-shadow:
    0 0 0 2px var(--chrome-hi),
    0 0 0 4px var(--bg-0),
    0 0 0 6px var(--chrome),
    0 8px 0 0 rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  min-width: 320px;
  min-height: 240px;
}

.window-resize {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: nwse-resize;
  z-index: 3;
}

.window-resize::before {
  content: "";
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 14px;
  height: 14px;
  background:
    linear-gradient(var(--chrome-hi), var(--chrome-hi)) 10px 10px / 4px 4px no-repeat,
    linear-gradient(var(--chrome-hi), var(--chrome-hi)) 4px 10px / 4px 4px no-repeat,
    linear-gradient(var(--chrome-hi), var(--chrome-hi)) 10px 4px / 4px 4px no-repeat;
}

.window-resize:hover::before {
  background:
    linear-gradient(var(--moon), var(--moon)) 10px 10px / 4px 4px no-repeat,
    linear-gradient(var(--moon), var(--moon)) 4px 10px / 4px 4px no-repeat,
    linear-gradient(var(--moon), var(--moon)) 10px 4px / 4px 4px no-repeat;
}

.window-title {
  height: 28px;
  background:
    repeating-linear-gradient(
      to bottom,
      var(--chrome) 0px,
      var(--chrome) 2px,
      var(--chrome-hi) 2px,
      var(--chrome-hi) 4px
    );
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px 0 10px;
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--ink);
  text-shadow: 1px 1px 0 var(--bg-0);
  cursor: move;
  user-select: none;
  flex-shrink: 0;
}

.window-title-text {
  background: var(--panel);
  padding: 4px 8px;
  letter-spacing: 0.05em;
}

.window-controls {
  display: flex;
  gap: 4px;
}

.wbtn {
  width: 20px; height: 18px;
  background: var(--panel-2);
  border: none;
  cursor: pointer;
  display: grid; place-items: center;
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--chrome-hi);
  padding: 0;
}
.wbtn:hover { background: var(--moon); color: var(--bg-0); }
.wbtn.close:hover { background: var(--danger); color: var(--ink); }

.window-body {
  flex: 1;
  overflow: auto;
  background:
    linear-gradient(180deg, rgba(6, 8, 24, 0.42), rgba(6, 8, 24, 0.2)),
    var(--bg-1);
  color: var(--ink);
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--chrome) var(--bg-0);
  position: relative;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-overflow-scrolling: touch;
}

.window-body::-webkit-scrollbar { width: 14px; }
.window-body::-webkit-scrollbar-track { background: var(--bg-0); }
.window-body::-webkit-scrollbar-thumb {
  background: var(--chrome);
  box-shadow: inset 0 0 0 2px var(--chrome-hi);
}

.window-inner {
  padding: 22px 26px;
}

/* ============================================================
   TASKBAR
   ============================================================ */

.taskbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 44px;
  background: var(--chrome);
  box-shadow:
    inset 0 2px 0 var(--chrome-hi),
    inset 0 -2px 0 var(--bg-0);
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 8px;
  z-index: 100;
  font-family: var(--font-pixel);
  font-size: 9px;
}

.startbtn {
  height: 32px;
  padding: 0 12px;
  background: var(--panel);
  border: none;
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: inset 0 0 0 2px var(--chrome-hi);
  letter-spacing: 0.05em;
}
.startbtn:hover { background: var(--panel-2); }
.startbtn .logo-z {
  color: var(--moon);
  font-size: 14px;
  text-shadow: 1px 1px 0 var(--bg-0);
}
.startbtn img {
  flex-shrink: 0;
}

.taskbar-tasks {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow: hidden;
}

.taskbar-task {
  height: 28px;
  padding: 0 10px;
  background: var(--panel-2);
  border: none;
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: inset 0 0 0 1px var(--chrome-hi);
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.taskbar-task.active {
  background: var(--bg-1);
  box-shadow: inset 0 0 0 1px var(--moon);
}

.tray {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  background: var(--panel);
  height: 32px;
  box-shadow: inset 0 0 0 2px var(--chrome-hi);
}

.tray-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--ink);
}

.tray-volume {
  gap: 6px;
}
.tray-mute-btn {
  width: 18px; height: 18px;
  background: var(--panel-2);
  border: none;
  color: var(--moon);
  font-size: 12px;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px var(--chrome-hi);
  padding: 0;
  display: grid; place-items: center;
  line-height: 1;
}
.tray-mute-btn:hover { background: var(--moon); color: var(--bg-0); }

.tray-volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 70px;
  height: 4px;
  background: var(--bg-0);
  box-shadow: inset 0 0 0 1px var(--chrome);
  cursor: pointer;
  outline: none;
}
.tray-volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 8px;
  height: 14px;
  background: var(--moon);
  cursor: pointer;
  border: 1px solid var(--bg-0);
}
.tray-volume-slider::-moz-range-thumb {
  width: 8px;
  height: 14px;
  background: var(--moon);
  border: 1px solid var(--bg-0);
  cursor: pointer;
}
.tray-volume-slider:disabled { opacity: 0.4; cursor: not-allowed; }
.tray-volume-slider:disabled::-webkit-slider-thumb { background: var(--ink-faint); }

.start-menu {
  position: fixed;
  bottom: 44px;
  left: 8px;
  background: var(--panel);
  box-shadow:
    inset 0 0 0 2px var(--chrome-hi),
    0 0 0 2px var(--bg-0);
  padding: 6px;
  z-index: 99;
  min-width: 220px;
}
.start-menu-head {
  background: var(--chrome);
  padding: 8px 10px;
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--moon);
  margin-bottom: 6px;
  letter-spacing: 0.08em;
}
.start-menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  padding: 8px 10px;
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--ink);
  cursor: pointer;
  letter-spacing: 0.05em;
  text-align: left;
}
.start-menu-item:hover { background: var(--panel-2); }

.tray-zzz {
  color: var(--moon);
  animation: blink 1.5s steps(2) infinite;
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0.3; }
}

.tray-clock {
  font-variant-numeric: tabular-nums;
  color: var(--moon);
}

/* ============================================================
   DROWSY POPUP (bottom-right notification)
   ============================================================ */

.drowsy-popup {
  position: fixed;
  bottom: 68px;
  right: 16px;
  width: 200px;
  background: var(--panel);
  color: var(--ink);
  padding: 14px 16px 12px;
  font-family: var(--font-pixel);
  z-index: 200;
  box-shadow:
    0 0 0 2px var(--chrome-hi),
    0 4px 20px rgba(0,0,0,0.5);
  cursor: pointer;
  text-align: center;
  animation: popup-slide-in 0.35s ease-out;
}

.drowsy-popup:hover {
  box-shadow:
    0 0 0 2px var(--moon),
    0 4px 24px rgba(0,0,0,0.6);
}

.drowsy-popup.red-alert {
  box-shadow:
    0 0 0 2px var(--danger),
    0 4px 20px rgba(255,92,122,0.4);
  animation: popup-slide-in 0.35s ease-out, popup-pulse 2s ease-in-out 0.35s infinite;
}

.drowsy-popup.red-alert:hover {
  box-shadow:
    0 0 0 2px var(--danger),
    0 4px 24px rgba(255,92,122,0.6);
}

@keyframes popup-slide-in {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes popup-pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--danger), 0 4px 20px rgba(255,92,122,0.4); }
  50%      { box-shadow: 0 0 0 3px var(--danger), 0 4px 28px rgba(255,92,122,0.65); }
}

.drowsy-popup-close {
  position: absolute;
  top: 4px;
  right: 6px;
  background: none;
  border: none;
  color: var(--ink-faint);
  font-family: var(--font-pixel);
  font-size: 8px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
}
.drowsy-popup-close:hover { color: var(--ink); }

.drowsy-popup-icon {
  margin-bottom: 6px;
  display: flex;
  justify-content: center;
}

.drowsy-popup-label {
  font-size: 9px;
  letter-spacing: 1px;
  color: var(--ink-dim);
  margin-bottom: 2px;
}

.drowsy-popup.red-alert .drowsy-popup-label {
  color: var(--danger);
}

.drowsy-popup-value {
  font-size: 20px;
  font-family: var(--font-pixel);
  color: var(--moon);
  margin-bottom: 6px;
}

.drowsy-popup.red-alert .drowsy-popup-value {
  color: var(--danger);
}

.drowsy-popup-msg {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-dim);
  line-height: 1.4;
}

.tracker-red-alert,
.red-alert-hero {
  background: color-mix(in srgb, var(--danger) 26%, var(--bg-0));
  box-shadow:
    inset 0 0 0 2px var(--danger),
    0 0 0 2px var(--bg-0),
    0 0 18px rgba(255, 92, 122, 0.28);
}

.red-alert-hero {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 16px 18px;
  margin-bottom: 16px;
}

.red-alert-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

/* ============================================================
   GENERIC UI
   ============================================================ */

h1, h2, h3, h4 {
  font-family: var(--font-pixel);
  letter-spacing: 0.04em;
  margin: 0;
  color: var(--ink);
  text-shadow: 1px 1px 0 var(--bg-0);
}
h1 { font-size: 18px; line-height: 1.4; }
h2 { font-size: 14px; line-height: 1.5; }
h3 { font-size: 11px; line-height: 1.6; }
h4 { font-size: 10px; color: var(--moon); }

p, li {
  font-family: var(--font-mono);
  font-size: 20px;
  line-height: 1.55;
  letter-spacing: 0.015em;
  color: var(--ink);
}

.muted { color: var(--ink-dim); }
.accent-moon { color: var(--moon); }
.accent-rose { color: var(--rose); }
.accent-cyan { color: var(--cyan); }
.accent-violet { color: var(--violet); }

.pixel-card {
  background: var(--panel-2);
  background: color-mix(in srgb, var(--panel-2) 78%, var(--bg-0));
  box-shadow: inset 0 0 0 2px var(--chrome-hi);
  padding: 16px 18px;
  margin-bottom: 16px;
}

.pixel-divider {
  height: 4px;
  background:
    repeating-linear-gradient(
      to right,
      var(--chrome) 0,
      var(--chrome) 4px,
      transparent 4px,
      transparent 8px
    );
  margin: 14px 0;
}

.pbtn {
  background: var(--panel);
  color: var(--ink);
  border: none;
  padding: 8px 14px;
  font-family: var(--font-pixel);
  font-size: 10px;
  cursor: pointer;
  box-shadow: inset 0 0 0 2px var(--chrome-hi), 0 4px 0 var(--bg-0);
  position: relative;
  transition: transform 0.05s, box-shadow 0.05s;
  letter-spacing: 0.05em;
}
.pbtn:hover { background: var(--panel-2); }
.pbtn:active {
  transform: translateY(2px);
  box-shadow: inset 0 0 0 2px var(--chrome-hi), 0 2px 0 var(--bg-0);
}
.pbtn.primary { background: var(--moon); color: var(--bg-0); }
.pbtn.primary:hover { background: var(--rose); color: var(--ink); }
.pbtn.ghost { background: transparent; box-shadow: inset 0 0 0 2px var(--chrome-hi); }

.pinput, .pselect, .ptextarea {
  background: var(--bg-0);
  color: var(--ink);
  border: none;
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 20px;
  box-shadow: inset 0 0 0 2px var(--chrome);
  width: 100%;
}
.pinput:focus, .pselect:focus, .ptextarea:focus {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--moon);
}

.row { display: flex; gap: 12px; }
.col { display: flex; flex-direction: column; gap: 12px; }
.between { justify-content: space-between; }
.center { align-items: center; }
.grow { flex: 1; }

.tag {
  display: inline-block;
  padding: 3px 8px;
  font-family: var(--font-pixel);
  font-size: 8px;
  letter-spacing: 0.05em;
  background: var(--panel-2);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--chrome-hi);
  margin-right: 4px;
}
.tag.moon { background: var(--moon); color: var(--bg-0); }
.tag.rose { background: var(--rose); color: var(--bg-0); }
.tag.cyan { background: var(--cyan); color: var(--bg-0); }
.tag.violet { background: var(--violet); color: var(--bg-0); }

/* progress bar */
.pbar {
  height: 16px;
  background: var(--bg-0);
  box-shadow: inset 0 0 0 2px var(--chrome);
  position: relative;
  overflow: hidden;
}
.pbar-fill {
  height: 100%;
  background:
    repeating-linear-gradient(
      to right,
      var(--moon) 0,
      var(--moon) 4px,
      var(--rose) 4px,
      var(--rose) 8px
    );
}

/* tabs */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 14px;
  border-bottom: 2px solid var(--chrome);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent;
  border: none;
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--ink-dim);
  padding: 8px 12px;
  cursor: pointer;
  letter-spacing: 0.04em;
  flex: 0 0 auto;
}
.tab.active {
  background: var(--panel-2);
  color: var(--moon);
  box-shadow: inset 0 0 0 2px var(--chrome-hi);
}

/* sheep — walk right-to-left across the desktop taskbar strip */
.sheep-lane {
  position: absolute;
  bottom: 70px;
  left: 0;
  right: 0;
  height: 74px;
  overflow: hidden;
  pointer-events: none;
  z-index: 2;
}

.sheep-walker {
  position: absolute;
  left: 0;
  bottom: 0;
  image-rendering: pixelated;
  will-change: transform;
}

.sheep-lane .sheep-walker:nth-child(2) {
  bottom: 10px;
}

.sheep-hopper {
  will-change: transform;
}

.sheep {
  position: absolute;
  width: 28px; height: 22px;
  image-rendering: pixelated;
}

/* ambience pixel scene */
.scene {
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--bg-0);
  box-shadow: inset 0 0 0 2px var(--chrome);
  position: relative;
  overflow: hidden;
  cursor: pointer;
}
.scene svg { width: 100%; height: 100%; display: block; }

.scene-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
@media (min-width: 760px) {
  .scene-grid { grid-template-columns: repeat(2, 1fr); }
}

.scene-card {
  background: var(--panel-2);
  padding: 10px;
  box-shadow: inset 0 0 0 2px var(--chrome-hi);
  cursor: pointer;
  border: none;
  color: var(--ink);
  text-align: left;
  font-family: inherit;
  font-size: inherit;
  display: block;
  width: 100%;
}
.scene-card:hover {
  box-shadow: inset 0 0 0 2px var(--chrome-hi), 0 0 0 1px var(--moon);
}
.scene-card.active {
  box-shadow: inset 0 0 0 2px var(--moon);
}
.scene-card .scene-label {
  font-family: var(--font-pixel);
  font-size: 9px;
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* chart */
.chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 140px;
  padding: 8px;
  background: var(--bg-0);
  box-shadow: inset 0 0 0 2px var(--chrome);
}
.chart-bar {
  flex: 1;
  background:
    repeating-linear-gradient(
      to top,
      var(--moon) 0,
      var(--moon) 4px,
      var(--rose) 4px,
      var(--rose) 8px
    );
  position: relative;
  min-height: 4px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.chart-bar.bad { background: repeating-linear-gradient(to top, var(--danger) 0, var(--danger) 4px, var(--rose) 4px, var(--rose) 8px); }
.chart-bar.good { background: repeating-linear-gradient(to top, var(--success) 0, var(--success) 4px, var(--cyan) 4px, var(--cyan) 8px); }
.chart-bar-label {
  font-family: var(--font-pixel);
  font-size: 7px;
  color: var(--ink);
  position: absolute;
  top: -14px;
}
.chart-axis {
  display: flex;
  justify-content: space-around;
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--ink-dim);
  margin-top: 4px;
}

.pixel-block-chart {
  display: grid;
  grid-template-columns: repeat(7, minmax(34px, 1fr));
  align-items: end;
  gap: 8px;
  min-height: 164px;
  padding: 10px;
  background: var(--bg-0);
  box-shadow: inset 0 0 0 2px var(--chrome);
}

.pixel-block-column {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.pixel-block-stack {
  display: flex;
  flex-direction: column-reverse;
  gap: 2px;
  width: 100%;
  max-width: 34px;
  min-height: 18px;
}

.sleep-block {
  display: block;
  height: 7px;
  box-shadow: inset 0 0 0 1px var(--bg-0);
}

.sleep-block.bad { background: var(--danger); }
.sleep-block.warn { background: var(--moon); }
.sleep-block.good { background: var(--success); }

.pixel-block-hours {
  font-family: var(--font-pixel);
  font-size: 7px;
  color: var(--ink);
  min-height: 11px;
}

/* stat tiles */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}
.stat {
  background: var(--panel-2);
  padding: 10px 12px;
  box-shadow: inset 0 0 0 2px var(--chrome-hi);
}
.stat-label { font-family: var(--font-pixel); font-size: 8px; color: var(--ink-dim); letter-spacing: 0.05em; }
.stat-value { font-family: var(--font-pixel); font-size: 18px; color: var(--moon); margin-top: 6px; text-shadow: 2px 2px 0 var(--bg-0); }
.stat-sub { font-family: var(--font-mono); font-size: 17px; color: var(--ink-dim); margin-top: 3px; line-height: 1.35; }

/* fact list */
.factlist { list-style: none; padding: 0; margin: 0; }
.factlist li {
  padding: 10px 12px;
  background: var(--bg-2);
  margin-bottom: 6px;
  box-shadow: inset 4px 0 0 var(--moon);
  font-size: 20px;
  line-height: 1.5;
}
.factlist li.myth { box-shadow: inset 4px 0 0 var(--danger); }
.factlist li.truth { box-shadow: inset 4px 0 0 var(--success); }

/* boot screen */
.boot {
  position: fixed;
  inset: 0;
  background: var(--bg-0);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 30px;
  font-family: var(--font-pixel);
}
.boot-logo {
  font-size: 42px;
  color: var(--moon);
  text-shadow: 4px 4px 0 var(--rose), 8px 8px 0 var(--bg-2);
  letter-spacing: 0.1em;
  animation: bootglow 2s ease-in-out infinite;
}
@keyframes bootglow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}
.boot-bar {
  width: 300px; height: 16px;
  background: var(--bg-1);
  box-shadow: inset 0 0 0 2px var(--chrome);
  overflow: hidden;
}
.boot-bar-fill {
  display: block;
  height: 100%;
  background:
    repeating-linear-gradient(
      to right,
      var(--moon) 0, var(--moon) 4px,
      var(--rose) 4px, var(--rose) 8px
    );
  width: 0%;
  transition: width 0.48s linear;
}
.boot-msg {
  font-size: 10px;
  color: var(--ink-dim);
  letter-spacing: 0.1em;
}

/* sleep cycle diagram */
.cycle-diagram {
  position: relative;
  width: 100%;
  height: 240px;
  background: var(--bg-0);
  box-shadow: inset 0 0 0 2px var(--chrome);
  padding: 12px;
}

/* dream journal */
.dream-entry {
  background: var(--bg-2);
  padding: 12px;
  margin-bottom: 10px;
  box-shadow: inset 2px 0 0 var(--violet);
}
.dream-entry .dream-date {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--moon);
  margin-bottom: 6px;
}
.dream-entry .dream-text {
  font-family: var(--font-mono);
  font-size: 20px;
  line-height: 1.5;
  font-style: italic;
}

/* responsive */
@media (max-width: 760px) {
  :root {
    --px: 3px;
    --taskbar-h: 52px;
    --mobile-edge: 8px;
  }

  html,
  body {
    height: 100dvh;
    font-size: 20px;
  }

  .crt::before { opacity: 0.45; }
  .crt::after { opacity: 0.65; }

  .desktop-icons {
    top: max(14px, calc(env(safe-area-inset-top) + 10px));
    left: 12px;
    grid-template-columns: repeat(3, 72px);
    gap: 12px 8px;
  }

  .dicon {
    width: 72px;
    gap: 6px;
    padding: 8px 4px;
    touch-action: manipulation;
  }

  .dicon-art {
    width: 42px;
    height: 42px;
  }

  .dicon-art svg {
    width: 28px;
    height: 28px;
  }

  .dicon-label {
    max-width: 70px;
    font-size: 7px;
    line-height: 1.4;
    padding: 2px 4px;
  }

  .window {
    left: max(var(--mobile-edge), env(safe-area-inset-left)) !important;
    top: max(var(--mobile-edge), env(safe-area-inset-top)) !important;
    width: calc(100vw - (var(--mobile-edge) * 2)) !important;
    height: calc(100dvh - var(--taskbar-h) - env(safe-area-inset-bottom) - (var(--mobile-edge) * 2)) !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: calc(100vw - (var(--mobile-edge) * 2)) !important;
    max-height: calc(100dvh - var(--taskbar-h) - env(safe-area-inset-bottom) - (var(--mobile-edge) * 2)) !important;
    box-shadow:
      0 0 0 2px var(--chrome-hi),
      0 0 0 4px var(--bg-0),
      0 4px 0 0 rgba(0,0,0,0.35);
  }

  .window-title {
    height: 36px;
    padding: 0 6px 0 8px;
    font-size: 8px;
    cursor: default;
    touch-action: none;
  }

  .window-title-text {
    max-width: 100%;
    padding: 4px 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .window-controls { gap: 6px; }

  .wbtn {
    width: 30px;
    height: 28px;
    font-size: 9px;
  }

  .window-inner {
    padding: 16px 14px 18px;
  }

  h1 { font-size: 14px; }
  h2 { font-size: 12px; }
  h3 { font-size: 10px; }
  h4 { font-size: 9px; }

  p,
  li {
    font-size: 18px;
    line-height: 1.45;
  }

  .pixel-card {
    padding: 12px;
    margin-bottom: 12px;
  }

  .pbtn {
    min-height: 36px;
    padding: 8px 10px;
    font-size: 8px;
    touch-action: manipulation;
  }

  .pinput,
  .pselect,
  .ptextarea {
    min-height: 40px;
    font-size: 18px;
  }

  .row {
    flex-direction: column;
    gap: 10px;
  }

  .tabs {
    margin: 0 -14px 14px;
    padding: 0 14px 8px;
    scroll-snap-type: x proximity;
  }

  .tab {
    min-height: 36px;
    padding: 9px 10px;
    font-size: 8px;
    scroll-snap-align: start;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .stat {
    padding: 9px 10px;
  }

  .stat-label { font-size: 7px; }
  .stat-value { font-size: 15px; }
  .stat-sub { font-size: 15px; }

  .chart {
    height: 112px;
    gap: 5px;
    padding: 18px 6px 8px;
  }

  .chart-bar-label {
    top: -12px;
    font-size: 6px;
  }

  .chart-axis { font-size: 7px; }

  .scene-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .scene-card {
    padding: 8px;
  }

  .scene-card .scene-label {
    font-size: 8px;
  }

  .ambience-controls {
    flex-wrap: wrap;
  }

  .ambience-controls input[type="range"] {
    flex: 1 0 100% !important;
    min-width: 100%;
  }

  .cycle-diagram {
    padding: 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .cycle-diagram svg {
    min-width: 360px;
  }

  .stage-grid,
  .circadian-grid,
  .measure-grid,
  .cycle-slots {
    grid-template-columns: 1fr !important;
  }

  .circadian-grid svg {
    justify-self: center;
    max-width: 260px !important;
  }

  .factlist li {
    padding: 10px;
  }

  .factlist li > div {
    flex-wrap: wrap;
  }

  .taskbar {
    height: calc(var(--taskbar-h) + env(safe-area-inset-bottom));
    padding: 0 8px env(safe-area-inset-bottom);
    gap: 6px;
  }

  .startbtn {
    width: 44px;
    height: 34px;
    justify-content: center;
    padding: 0;
    font-size: 0;
    flex: 0 0 auto;
  }

  .startbtn img {
    width: 20px;
    height: 20px;
  }

  .taskbar-tasks {
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .taskbar-tasks::-webkit-scrollbar { display: none; }

  .taskbar-task {
    flex: 0 0 auto;
    min-width: 36px;
    max-width: 40px;
    height: 32px;
    justify-content: center;
    padding: 0 8px;
    font-size: 0;
  }

  .taskbar-task > div {
    width: 16px !important;
    height: 16px !important;
  }

  .tray {
    height: 34px;
    padding: 0 7px;
    gap: 6px;
    flex-shrink: 0;
  }

  .tray-volume,
  .tray > div[style],
  .tray > .tray-item[title="Active scene"] {
    display: none !important;
  }

  .tray-item {
    gap: 4px;
    font-size: 8px;
  }

  .tray .tray-item:last-child .muted {
    display: none;
  }

  .start-menu {
    left: 8px;
    right: 8px;
    bottom: calc(var(--taskbar-h) + env(safe-area-inset-bottom));
    min-width: 0;
    max-height: calc(100dvh - var(--taskbar-h) - 24px);
    overflow-y: auto;
  }

  .start-menu-item {
    min-height: 42px;
  }

  .drowsy-popup {
    right: 8px;
    bottom: calc(var(--taskbar-h) + env(safe-area-inset-bottom) + 8px);
    width: 170px;
    padding: 12px 12px 10px;
  }

  .drowsy-popup-value { font-size: 16px; }
  .drowsy-popup-msg { font-size: 11px; }

  .boot-logo {
    font-size: 28px;
    text-shadow: 3px 3px 0 var(--rose), 6px 6px 0 var(--bg-2);
  }

  .boot-bar {
    width: calc(100vw - 48px);
    max-width: 300px;
  }
}

@media (max-width: 430px) {
  .desktop-icons {
    grid-template-columns: repeat(2, 72px);
  }

  .stats {
    grid-template-columns: 1fr;
  }

  .cycle-diagram svg {
    min-width: 330px;
  }
}

@media (prefers-reduced-motion: reduce) {
  :where(:not(.sheep-lane):not(.sheep-lane *):not(.boot):not(.boot *)),
  :where(:not(.sheep-lane):not(.sheep-lane *):not(.boot):not(.boot *))::before,
  :where(:not(.sheep-lane):not(.sheep-lane *):not(.boot):not(.boot *))::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
