/* Sweet Spot: the R30 frame, polished.
   Peach body, lime title and rails, green edge strip, heavy black outlines,
   one hover color per tile. The glucose tile in the top-right corner is the
   only element that changes color on its own. */

:root {
  --peach: #FCE4D6;
  --backdrop: #F3CDB6;
  --lime: #92D050;
  --green: #00B050;
  --ink: #000;
  --ink-soft: #4B3A30;
  --paper: #fff;
  --danger: #D40000;
  --display: "Arial Black", "Segoe UI Black", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --body: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --line: 3px;
  --bar: 68px;
  --strip: 22px;
  --rail: 64px;
  --side: calc(var(--strip) + var(--rail) + var(--line));
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--backdrop);
  color: var(--ink);
  font: 16px/1.5 var(--body);
}
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

/* ---------- Frame ---------- */

.frame {
  display: grid;
  grid-template-rows: var(--bar) 1fr;
  max-width: 1000px;
  min-height: min(680px, calc(100dvh - 64px));
  margin: 32px auto;
  background: var(--peach);
  border: var(--line) solid var(--ink);
}

.bar {
  display: grid;
  grid-template-columns: var(--side) 1fr auto;
  border-bottom: var(--line) solid var(--ink);
}
.corner {
  display: grid;
  place-items: center;
  background: var(--green);
  border-right: var(--line) solid var(--ink);
  color: var(--ink);
}
.corner svg { width: 38px; height: 38px; }
a.corner[href]:hover { background: #009a46; }
.title {
  margin: 0;
  display: grid;
  place-items: center;
  background: var(--lime);
  font: 900 30px/1 var(--display);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

/* The live glucose tile (where R30 had _ and X). */
.reading {
  display: grid;
  align-content: center;
  justify-items: center;
  min-width: 156px;
  padding: 0 16px;
  border-left: var(--line) solid var(--ink);
  background: var(--c, var(--green));
  color: var(--ink, #000);
  transition: background-color 1.2s linear, color 1.2s linear;
}
.reading.idle { background: var(--green); color: #000; }
.reading-value { font: 900 30px/1 var(--display); display: flex; align-items: baseline; gap: 6px; }
.reading-trend { font-size: 24px; }
.reading-meta { font-size: 12px; font-weight: 700; line-height: 1.2; margin-top: 3px; }

.view { display: grid; min-height: 0; }
.loading { margin: auto; font-weight: 700; }

/* ---------- Menu ---------- */

.menu, .layout {
  display: grid;
  grid-template-columns: var(--strip) var(--rail) 1fr;
}
.menu { grid-template-rows: 1fr 1fr; }
.strip {
  grid-row: 1 / -1;
  background: var(--green);
  border-right: var(--line) solid var(--ink);
}
.rail {
  display: grid;
  place-items: center;
  background: var(--lime);
  border-right: var(--line) solid var(--ink);
}
.rail span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font: 900 28px/1 var(--display);
  letter-spacing: 0.06em;
}
.rail-bottom, .tiles-bottom { border-top: var(--line) solid var(--ink); }

.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-content: center;
  align-items: start;
  justify-items: center;
  padding: 20px 12px;
}
.tile {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 6px;
  color: var(--ink);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.tile-icon {
  display: grid;
  place-items: center;
  width: 144px;
  height: 116px;
  transition: background-color 120ms ease-out;
}
.tile-icon svg { width: 92px; height: 92px; }
.tile:hover .tile-icon,
.tile:focus-visible .tile-icon,
.tile:active .tile-icon { background: var(--tile); }
.tile:focus-visible { outline: none; }
.tile:focus-visible .tile-icon { outline: 3px solid var(--ink); outline-offset: 3px; }
.tile-label { font: 900 17px/1.1 var(--display); }
.tile-note { font-size: 13px; font-weight: 600; color: var(--ink-soft); line-height: 1.2; min-height: 1.2em; text-align: center; }
.tile-note.warn { color: var(--danger); }

/* ---------- Pages ---------- */

.layout { min-height: 0; }
.layout .rail { grid-row: 1; }
.scroll { overflow-y: auto; min-height: 0; max-height: calc(100dvh - 64px - var(--bar) - 2 * var(--line)); }

.page { padding: 28px 36px 48px; max-width: 680px; }
.page h2 { font: 900 30px/1.1 var(--display); margin: 0 0 8px; }
.lead { font-size: 17px; margin: 0 0 8px; max-width: 58ch; }
.section { margin-top: 32px; }
.section h3 { font: 900 19px/1.2 var(--display); margin: 0 0 12px; }
.section p { margin: 0 0 12px; max-width: 62ch; }
.help { font-size: 14px; color: var(--ink-soft); line-height: 1.45; }
.spaced { margin-top: 20px; }
.stack { display: grid; gap: 4px; }

.field { display: grid; gap: 6px; margin-bottom: 14px; max-width: 420px; }
.field-label { font-weight: 700; font-size: 14px; }

input[type="text"], input[type="password"], input[type="number"] {
  font: 16px var(--body);
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 0;
}
input:disabled { background: #F6EAE2; color: var(--ink-soft); }
input:focus-visible { outline: 3px solid var(--green); outline-offset: 0; }

.btn {
  font: 900 15px/1 var(--display);
  min-height: 46px;
  padding: 0 20px;
  color: var(--ink);
  background: var(--green);
  border: 2px solid var(--ink);
  border-radius: 0;
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
}
.btn:hover { background: #00C95C; }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn:disabled { cursor: progress; opacity: 0.6; }
.btn.quiet { background: var(--paper); }
.btn.quiet:hover { background: #FFF6F0; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { min-height: 38px; padding: 0 14px; font-size: 13px; }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.row > input { flex: 1 1 220px; max-width: 320px; }

.message {
  margin: 16px 0 0;
  padding: 12px 14px;
  max-width: 62ch;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-left-width: 10px;
  font-size: 15px;
}
.message.ok { border-left-color: var(--green); }
.message.error { border-left-color: var(--danger); }

.notes { margin: 16px 0 0; padding-left: 20px; max-width: 62ch; font-size: 14px; color: var(--ink-soft); }
.notes li + li { margin-top: 6px; }

.segmented { display: grid; grid-template-columns: repeat(3, auto); justify-content: start; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: block;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 14px;
  background: var(--paper);
  border: 2px solid var(--ink);
  margin-right: -2px;
}
.segmented input:checked + span { background: var(--lime); }
.segmented input:focus-visible + span { outline: 3px solid var(--ink); outline-offset: 2px; position: relative; z-index: 1; }

/* Lists: lights, devices */
.list { list-style: none; margin: 0; padding: 0; max-width: 620px; }
.list-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  background: var(--paper);
  border: 2px solid var(--ink);
}
.list-row + .list-row { margin-top: -2px; }
.row-main { display: grid; flex: 1; min-width: 0; }
.row-title { font-weight: 700; overflow-wrap: anywhere; }
.row-sub { font-size: 14px; color: var(--ink-soft); }
.check { display: flex; align-items: center; gap: 14px; flex: 1; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--green); flex: none; }
.check.solo { max-width: 560px; padding: 10px 0; }

.swatch {
  flex: none;
  width: 30px;
  height: 30px;
  background: var(--c);
  border: 2px solid var(--ink);
}
.swatch.empty { background: repeating-linear-gradient(45deg, #fff 0 5px, #E7D6CB 5px 10px); }
.status-line { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.status-line .swatch { width: 18px; height: 18px; }

/* Glucose page */
.colors { display: flex; flex-wrap: wrap; gap: 18px 28px; }
.color-field { display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; column-gap: 12px; align-items: center; cursor: pointer; }
.color-field input {
  grid-row: 1 / 3;
  width: 64px;
  height: 56px;
  padding: 0;
  border: 2px solid var(--ink);
  background: none;
  cursor: pointer;
}
.color-field input::-webkit-color-swatch-wrapper { padding: 0; }
.color-field input::-webkit-color-swatch { border: none; }
.color-field input::-moz-color-swatch { border: none; }
.hex { font-size: 14px; color: var(--ink-soft); }

.ranges { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; max-width: 620px; }
.ranges.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ranges .field { margin: 0; }

.scale-wrap { position: relative; max-width: 620px; margin: 22px 0 36px; }
.scale { height: 42px; border: 2px solid var(--ink); }
.scale-pointer {
  position: absolute;
  top: -8px;
  left: var(--x);
  width: 4px;
  height: 58px;
  margin-left: -2px;
  background: var(--ink);
  pointer-events: none;
}
.scale-marks { position: absolute; inset: 0; pointer-events: none; }
.mark {
  position: absolute;
  top: 44px;
  left: var(--x);
  transform: translateX(-50%);
  padding-top: 8px;
  font-size: 12px;
  font-weight: 700;
}
.mark::before {
  content: "";
  position: absolute;
  top: -44px;
  left: 50%;
  width: 2px;
  height: 50px;
  margin-left: -1px;
  background: rgba(0, 0, 0, 0.55);
}

.preview { display: flex; align-items: center; gap: 20px; max-width: 620px; }
.preview-swatch { flex: none; width: 96px; height: 96px; background: var(--c); border: var(--line) solid var(--ink); }
.preview-controls { flex: 1; display: grid; gap: 6px; }
.preview-controls input[type="range"] { width: 100%; accent-color: var(--ink); }
.preview-text { margin: 0; font-weight: 700; }

/* Screen page */
.screen-preview {
  display: grid;
  place-items: end;
  height: 200px;
  max-width: 620px;
  margin-top: 20px;
  padding: 16px 20px;
  background: var(--c);
  color: var(--ink);
  border: var(--line) solid #000;
  transition: background-color 1.2s linear;
}
.screen-preview-value { font: 900 44px/1 var(--display); }

/* ---------- Full-screen color ---------- */

.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: max(4vmin, env(safe-area-inset-bottom)) max(5vmin, env(safe-area-inset-right));
  background: var(--c, #000);
  color: var(--ink, #fff);
  transition: background-color var(--fade, 15s) linear, color var(--fade, 15s) linear;
  cursor: none;
  outline: none;
}
.fullscreen.show-cursor { cursor: default; }
.fs-value { font: 900 clamp(40px, 11vmin, 160px)/1 var(--display); opacity: 0.8; }
.fs-hint {
  position: absolute;
  top: max(3vmin, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  font-weight: 700;
  font-size: 14px;
  color: #000;
  background: rgba(255, 255, 255, 0.85);
  border: 2px solid #000;
  opacity: 0;
  transition: opacity 300ms;
}
.fullscreen.show-cursor .fs-hint { opacity: 1; }

/* ---------- Small screens: same frame, tighter ---------- */

@media (max-width: 720px) {
  :root { --bar: 58px; --strip: 10px; --rail: 44px; }
  .frame { margin: 0; min-height: 100dvh; border-width: 0; }
  .bar { padding-top: env(safe-area-inset-top); height: calc(var(--bar) + env(safe-area-inset-top)); }
  .frame { grid-template-rows: auto 1fr; }
  .title { font-size: clamp(17px, 5.4vw, 26px); }
  .reading { min-width: 104px; padding: 0 10px; }
  .reading-value { font-size: 24px; }
  .reading-trend { font-size: 19px; }
  .corner svg { width: 30px; height: 30px; }
  .rail span { font-size: 19px; }
  .tiles { padding: 10px 2px; }
  .tile-icon { width: 100px; height: 88px; }
  .tile-icon svg { width: 66px; height: 66px; }
  .tile-label { font-size: 14px; }
  .tile-note { font-size: 11.5px; }
  .scroll { max-height: calc(100dvh - var(--bar) - env(safe-area-inset-top) - var(--line)); }
  .page { padding: 22px 18px calc(40px + env(safe-area-inset-bottom)); }
  .page h2 { font-size: 26px; }
  .ranges { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ranges.two { grid-template-columns: 1fr; }
  .segmented { grid-template-columns: repeat(3, 1fr); }
  .segmented span { padding: 10px 8px; text-align: center; font-size: 13px; height: 100%; }
  .preview-swatch { width: 72px; height: 72px; }
}

@media (prefers-reduced-motion: reduce) {
  .tile-icon, .reading, .screen-preview { transition: none; }
  .btn:active { transform: none; }
}
