:root {
  --moss: #14201a;
  --pine: #1c2c24;
  --pine-2: #22352b;
  --fern: #2f4538;
  --linen: #eae1d2;
  --oat: #a89d89;
  --gold: #f3b65c;
  --gold-soft: rgba(243, 182, 92, 0.16);
  --warn: #f0a48a;
  --radius-lg: 22px;
  --radius-sm: 12px;
  --display: "Bricolage Grotesque", ui-rounded, system-ui, sans-serif;
  --text: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { background: var(--moss); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(243, 182, 92, 0.10), transparent 60%),
    var(--moss);
  color: var(--linen);
  font: 16px/1.45 var(--text);
  -webkit-font-smoothing: antialiased;
}
main {
  max-width: 460px;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px calc(40px + env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 8px; }

/* ---------- the lamp ---------- */
.top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 6px 2px 14px; }
h1 {
  font: 600 30px/1.1 var(--display);
  letter-spacing: -0.01em;
  margin: 0;
}
.state { color: var(--oat); font-size: 14px; white-space: nowrap; }
.state.on { color: var(--gold); }

.lamp {
  position: relative;
  aspect-ratio: 2 / 1;
  border-radius: 10px;
  overflow: hidden;
  background: #0d0d0b;
  box-shadow: 0 0 0 7px #e9e5dd, 0 26px 60px -18px rgba(243, 182, 92, var(--halo, 0.35));
  margin: 7px 7px 26px;
  transition: box-shadow 0.8s ease;
}
.lamp canvas {
  position: absolute;
  inset: -6%;
  width: 112%;
  height: 112%;
  image-rendering: auto;
  filter: blur(7px) saturate(1.05);
  transition: opacity 0.6s ease;
}
/* the linen weave over the light */
.lamp::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(0deg, rgba(255, 248, 236, 0.07) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(60, 45, 30, 0.10) 0 1px, transparent 1px 3px),
    linear-gradient(rgba(235, 226, 210, 0.06), rgba(235, 226, 210, 0.06));
  mix-blend-mode: soft-light;
  pointer-events: none;
}
.lamp.finding { animation: find 1.2s ease-in-out 3; }
@keyframes find { 50% { box-shadow: 0 0 0 7px #fff6e6, 0 30px 80px -10px rgba(243, 182, 92, 0.9); } }

.other {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--oat);
  font-size: 15px;
  margin: 0 4px 26px;
}
.other .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--fern);
  flex: none;
}
.other.on .dot { background: var(--gold); box-shadow: 0 0 12px 3px rgba(243, 182, 92, 0.55); }
.other.on { color: var(--linen); }

/* ---------- notices ---------- */
.notice {
  margin: 0 2px 18px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--gold-soft);
  color: var(--linen);
  font-size: 15px;
}
.notice.error { background: rgba(240, 164, 138, 0.14); color: var(--warn); }

/* ---------- modes ---------- */
h2 {
  font: 600 19px/1.2 var(--display);
  margin: 28px 4px 10px;
}
.modes {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: 22px;
  margin: 0 -18px;
  padding: 4px 22px 10px;
  scrollbar-width: none;
}
.modes::-webkit-scrollbar { display: none; }
.mode {
  flex: none;
  width: 92px;
  scroll-snap-align: start;
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  cursor: pointer;
}
.mode .swatch {
  display: block;
  width: 92px;
  height: 46px;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  box-shadow: 0 0 0 1px var(--fern);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.mode .swatch canvas { width: 116%; height: 116%; margin: -8%; filter: blur(3px); display: block; }
.mode span.name { display: block; margin-top: 7px; font-size: 14px; color: var(--oat); }
.mode[aria-pressed="true"] .swatch { box-shadow: 0 0 0 2px var(--gold), 0 8px 24px -8px rgba(243, 182, 92, 0.6); }
.mode[aria-pressed="true"] span.name { color: var(--linen); }
.mode:active .swatch { transform: scale(0.97); }

/* ---------- grouped rows ---------- */
.group {
  background: var(--pine);
  border-radius: var(--radius-lg);
  padding: 2px 0;
}
.row {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 54px;
  padding: 10px 18px;
}
.row + .row { border-top: 1px solid var(--fern); }
.row .label { flex: 1; }
.row .sub { display: block; color: var(--oat); font-size: 13px; margin-top: 1px; }
.row .value { color: var(--oat); }
.row.stack { flex-direction: column; align-items: stretch; gap: 8px; }
.pending { color: var(--gold); font-size: 13px; margin: 8px 6px 0; }

/* switch */
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span {
  position: absolute; inset: 0; border-radius: 99px;
  background: var(--fern);
  transition: background 0.2s ease;
  pointer-events: none;
}
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%;
  background: var(--linen);
  transition: transform 0.2s ease;
}
.switch input:checked + span { background: var(--gold); }
.switch input:checked + span::after { transform: translateX(20px); background: #fff8ec; }
.switch input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 2px; }

/* slider */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 30px; background: none; margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--gold) var(--fill, 50%), var(--fern) var(--fill, 50%));
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--fern); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--gold); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; margin-top: -10px; border-radius: 50%;
  background: #fff8ec; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
input[type="range"]::-moz-range-thumb { width: 26px; height: 26px; border: 0; border-radius: 50%; background: #fff8ec; }
.range { display: flex; align-items: center; gap: 12px; }
.range svg { flex: none; color: var(--oat); }

input[type="time"], input[type="text"], input[type="password"], input[type="email"], select, .field {
  background: var(--pine-2);
  border: 1px solid var(--fern);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 38px;
}
input[type="time"] { width: 132px; text-align: center; }
input::placeholder { color: var(--oat); opacity: 0.8; }
.seg { display: inline-flex; background: var(--pine-2); border-radius: 10px; padding: 3px; border: 1px solid var(--fern); }
.seg button { border: 0; background: none; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--oat); }
.seg button[aria-pressed="true"] { background: var(--fern); color: var(--linen); }

.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; cursor: pointer;
  background: var(--gold); color: #2a1c08; font-weight: 600;
}
.btn.quiet { background: var(--pine-2); color: var(--linen); border: 1px solid var(--fern); font-weight: 500; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.wide { width: 100%; }
.link { background: none; border: 0; color: var(--gold); padding: 6px 0; cursor: pointer; }
.danger { color: var(--warn); }

.net { display: flex; align-items: center; gap: 10px; }
.net .label { flex: 1; overflow-wrap: anywhere; }
.mac {
  font: 600 20px/1.2 ui-rounded, var(--text);
  letter-spacing: 0.04em;
  user-select: all;
  -webkit-user-select: all;
}
.fineprint { color: var(--oat); font-size: 13px; margin: 10px 6px 0; }

/* ---------- sign in ---------- */
.signin { padding-top: 8vh; }
.signin .lamp { margin-bottom: 40px; }
.signin h1 { margin-bottom: 10px; }
.signin p { color: var(--oat); margin: 0 2px 22px; }
.signin form { display: grid; gap: 12px; }
.signin input { width: 100%; font-size: 17px; min-height: 50px; padding: 12px 14px; }
.signin input.code { letter-spacing: 0.4em; text-align: center; font-size: 24px; }

@media (prefers-reduced-motion: reduce) {
  .lamp.finding { animation: none; }
  * { transition: none !important; }
}
