/* Dormir 2.0 base: element defaults and the shared control kit.
   Self-hosted Archivo (SIL Open Font License), so the app works without internet. */
@font-face {
  font-family: "Archivo";
  font-style: normal;
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
  src: url("fonts/archivo-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Archivo";
  font-style: normal;
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
  src: url("fonts/archivo-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; scrollbar-color: #2c3346 transparent; scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2c3346; border: 3px solid transparent; border-radius: 10px; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: #3b4460; }
::-webkit-scrollbar-track { background: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 var(--font);
  font-stretch: 100%;
  -webkit-font-smoothing: antialiased;
  caret-color: var(--violet);
}

::selection { color: var(--text); background: color-mix(in srgb, var(--violet) 55%, transparent); }

a { color: var(--text); text-decoration-color: color-mix(in srgb, var(--violet) 70%, transparent); text-underline-offset: 3px; transition: text-decoration-color var(--med); }
a:hover { text-decoration-color: var(--text); }
h1, h2, h3 { font-family: var(--display); text-wrap: balance; }
p { text-wrap: pretty; }
h2 { font-weight: 620; letter-spacing: -0.015em; }

h3 {
  margin: 20px 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

:focus-visible { outline: 2px solid var(--violet-ink); outline-offset: 2px; }

input[type="text"], input[type="search"], input[type="number"], input[type="url"], input[type="email"], input[type="password"], select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  color: var(--text);
  background: var(--well);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  transition: border-color var(--fast), background var(--fast), box-shadow var(--fast);
}

input[type="text"]:hover, input[type="search"]:hover, input[type="number"]:hover, input[type="url"]:hover, input[type="email"]:hover, input[type="password"]:hover, select:hover, textarea:hover { border-color: var(--edge-strong); }
input[type="text"]:focus, input[type="search"]:focus, input[type="number"]:focus, input[type="url"]:focus, input[type="email"]:focus, input[type="password"]:focus, select:focus, textarea:focus {
  background: rgba(3, 5, 10, 0.6);
  border-color: var(--violet);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--violet) 22%, transparent);
  outline: none;
}
input:disabled, select:disabled, textarea:disabled { opacity: 0.5; cursor: not-allowed; }

select {
  padding-right: 34px;
  appearance: none;
  background-image: 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='%23949cb0' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

select option { color: var(--text); background: var(--elevated); }
input::placeholder, textarea::placeholder { color: var(--faint); opacity: 1; }
input[type="color"] { width: 36px; height: 36px; padding: 0; background: none; border: 0; border-radius: var(--r-xs); cursor: pointer; }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 1px solid var(--edge-strong); border-radius: var(--r-xs); }
input[type="color"]::-moz-color-swatch { border: 1px solid var(--edge-strong); border-radius: var(--r-xs); }

/* Buttons. Primary is violet; ghost and tool are quiet glass; danger is red ink. */
.primary, .ghost, .danger, .tool, .mini, .chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  font-weight: 550;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  transition: background var(--fast), border-color var(--fast), color var(--fast), box-shadow var(--med), transform var(--fast) var(--ease);
}

.primary:active:not(:disabled), .ghost:active:not(:disabled), .danger:active:not(:disabled), .tool:active:not(:disabled), .mini:active:not(:disabled), .chip:active:not(:disabled) { transform: scale(0.97); }
.primary:disabled, .ghost:disabled, .danger:disabled, .tool:disabled, .mini:disabled, .chip:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.primary {
  color: #fff;
  font-weight: 620;
  background: var(--violet);
  border-color: color-mix(in srgb, var(--violet) 60%, #fff);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 6px 16px -8px rgba(0, 0, 0, 0.7);
}
.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--violet) 88%, #fff); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 8px 20px -8px rgba(0, 0, 0, 0.75); }
.ghost, .tool { background: var(--surface); }
.ghost:hover:not(:disabled), .tool:hover:not(:disabled), .mini:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--edge-strong); }
.danger { color: var(--bad-ink); background: rgba(255, 107, 125, 0.1); border-color: rgba(255, 107, 125, 0.34); }
.danger:hover:not(:disabled) { background: rgba(255, 107, 125, 0.18); border-color: rgba(255, 107, 125, 0.55); }
.small { min-height: 32px; padding: 0 12px; font-size: 0.82rem; }

.mini {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.78rem;
  background: var(--surface);
  border-radius: var(--r-xs);
}

.chip {
  min-height: 32px;
  padding: 0 13px;
  font-size: 0.82rem;
  background: var(--surface);
  border-radius: 999px;
}

.chip:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--edge-strong); }
.chip[aria-pressed="true"], .chip[aria-pressed="true"]:hover:not(:disabled) {
  color: var(--text);
  font-weight: 600;
  background: color-mix(in srgb, var(--violet) 22%, transparent);
  border-color: color-mix(in srgb, var(--violet) 60%, transparent);
}

/* Layout helpers */
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; margin-block: 10px; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.row.center { justify-content: center; }
.block { display: block; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 0.92em; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 0.82rem; line-height: 1.45; }
.empty-note { padding: 10px 0; color: var(--muted); font-size: 0.86rem; }
.wrap { width: min(1120px, 100%); margin-inline: auto; padding-inline: 24px; }
.wrap.row { padding-inline: 0; }

/* Sliders: a slim track filled in violet to the value, a white knob */
.slider {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 8px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.82rem;
}

.slider-value { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }

input[type="range"] {
  --p: 50%;
  --fill: var(--violet);
  grid-column: 1 / -1;
  width: 100%;
  height: 26px;
  margin: 2px 0 0;
  background: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: linear-gradient(90deg, var(--fill) 0 var(--p), rgba(255, 255, 255, 0.1) var(--p));
  border-radius: 3px;
}

input[type="range"]::-moz-range-track { height: 6px; background: rgba(255, 255, 255, 0.1); border-radius: 3px; }
input[type="range"]::-moz-range-progress { height: 6px; background: var(--fill); border-radius: 3px; }

input[type="range"]::-webkit-slider-thumb {
  width: 20px;
  height: 20px;
  margin-top: -7px;
  background: #fff;
  border: 0;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(0, 0, 0, 0.1);
  transition: box-shadow var(--med), transform var(--fast) var(--ease);
  -webkit-appearance: none;
}

input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; background: #fff; border: 0; border-radius: 50%; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5); }
input[type="range"]:hover::-webkit-slider-thumb { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 0 6px color-mix(in srgb, var(--fill) 22%, transparent); }
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.1); }
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--violet-ink); }
input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--violet-ink); }
input[type="range"]:disabled { opacity: 0.45; cursor: not-allowed; }

.field { display: block; margin-top: 12px; color: var(--muted); font-size: 0.82rem; }
.field > select, .field > input { margin-top: 5px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Switches */
.toggle { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 36px; font-size: 0.9rem; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }

.toggle i {
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 13px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.35);
  transition: background var(--med);
}

.toggle i::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
  transition: transform var(--med) var(--spring);
}

.toggle input:checked + i { background: var(--violet); }
.toggle input:checked + i::after { transform: translateX(18px); }
.toggle input:focus-visible + i { outline: 2px solid var(--violet-ink); outline-offset: 2px; }
.toggle input:disabled + i { opacity: 0.45; }

.fold { margin-top: 10px; border-top: 1px solid var(--line); }
.fold summary { padding: 10px 0; color: var(--muted); font-size: 0.84rem; cursor: pointer; }
.fold summary:hover { color: var(--text); }

/* Disclosure rows get a drawn chevron instead of the browser's triangle */
summary { display: flex; align-items: center; gap: 9px; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  border-right: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor;
  transform: rotate(-45deg);
  transition: transform var(--med) var(--ease);
}
details[open] > summary::before { transform: translate(1px, -2px) rotate(45deg); }

/* The drawn line icons, shared with the LED editor */
.primary .ed-icon, .ghost .ed-icon, .chip .ed-icon, .mini .ed-icon { width: 15px; height: 15px; }

.toasts {
  position: fixed;
  z-index: 50;
  right: 20px;
  bottom: 20px;
  display: grid;
  gap: 8px;
  width: min(380px, calc(100vw - 32px));
}

.toast {
  padding: 12px 16px 12px 40px;
  position: relative;
  font-size: 0.88rem;
  background: var(--glass-strong);
  border: 1px solid var(--edge);
  border-radius: var(--r-md);
  box-shadow: var(--sheen), var(--lift);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  animation: rise var(--med) var(--ease);
}

.toast::before { content: ""; position: absolute; left: 16px; top: 18px; width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); }
.toast.error { border-color: rgba(255, 107, 125, 0.45); }
.toast.error::before { background: var(--bad); }

@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(0.98); } }

.boot-note {
  position: fixed;
  z-index: 100;
  inset: auto 16px 16px;
  margin: 0;
  padding: 14px 18px;
  color: var(--text);
  font-weight: 600;
  text-align: center;
  background: var(--elevated);
  border: 1px solid var(--edge-strong);
  border-radius: var(--r-md);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
