:root {
  color-scheme: dark;
  --bg: #090b0d;
  --bg-2: #11151a;
  --card: rgba(22, 27, 33, 0.88);
  --line: rgba(255, 255, 255, 0.08);
  --text: #f4efe6;
  --muted: #9aa3ad;
  --teal: #3dffd4;
  --amber: #ffc857;
  --rose: #ff6b6b;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  --line-strong: rgba(255, 255, 255, 0.16);
  --ok-bg: rgba(61, 255, 212, 0.06);
  --wait-bg: rgba(255, 200, 87, 0.06);
  --fail-bg: rgba(255, 107, 107, 0.06);
  font-family: "Instrument Sans", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(61, 255, 212, 0.12), transparent 55%),
    radial-gradient(900px 500px at 110% 0%, rgba(255, 200, 87, 0.1), transparent 50%),
    var(--bg);
  color: var(--text);
}

body {
  padding: calc(28px + env(safe-area-inset-top)) 18px calc(40px + env(safe-area-inset-bottom));
}

.app {
  width: min(430px, 100%);
  margin: 0 auto;
}

.top {
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--teal);
  font-weight: 600;
}

h1 {
  margin: 0;
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 2.35rem;
  font-weight: 400;
  letter-spacing: -0.03em;
}

.lede {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.sheet,
.history {
  display: grid;
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 18px 16px 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.card-head h2,
.history h2 {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hint,
.toggle-copy {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.4;
  font-size: 0.95rem;
}

.energy-readout {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 16px 0 14px;
}

#energy-value {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 3.4rem;
  line-height: 0.8;
  min-width: 0.7em;
}

.energy-label {
  color: var(--muted);
  font-size: 0.92rem;
}

.energy-scale {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.energy-scale button {
  appearance: none;
  border: 1px solid var(--line);
  background: #0e1216;
  color: var(--text);
  border-radius: 14px;
  min-height: 52px;
  font: inherit;
  font-weight: 600;
  font-size: 1.05rem;
}

.energy-scale button[aria-checked="true"] {
  background: color-mix(in srgb, var(--pick, var(--teal)) 22%, #10151a);
  border-color: var(--pick, var(--teal));
  color: white;
  box-shadow: inset 0 0 0 1px var(--pick, var(--teal));
}

textarea {
  width: 100%;
  margin-top: 14px;
  resize: vertical;
  min-height: 110px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #0e1216;
  color: var(--text);
  font: inherit;
  padding: 12px 13px;
  outline: none;
}

textarea:focus {
  border-color: color-mix(in srgb, var(--teal) 55%, white);
}

.toggle-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
  cursor: pointer;
}

.toggle-title {
  display: block;
  font-weight: 600;
}

.toggle-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch {
  width: 52px;
  height: 32px;
  border-radius: 999px;
  background: #2a3138;
  position: relative;
  transition: background 160ms ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: white;
  transition: transform 160ms ease;
}

.toggle-row input:checked + .switch {
  background: var(--rose);
}

.toggle-row input:checked + .switch::after {
  transform: translateX(20px);
}

.toggle-row input:focus-visible + .switch {
  outline: 2px solid var(--teal);
  outline-offset: 3px;
}

.save {
  appearance: none;
  border: 0;
  border-radius: 999px;
  min-height: 54px;
  background: var(--text);
  color: #111;
  font: inherit;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.save:active {
  transform: scale(0.985);
}

.status {
  min-height: 1.2em;
  margin: 0;
  text-align: center;
  color: var(--teal);
  font-size: 0.92rem;
}

.history {
  margin-top: 28px;
}

.history ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.history li {
  display: block;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(14, 18, 22, 0.7);
  color: var(--muted);
  font-size: 0.92rem;
}

.history strong {
  color: var(--text);
  font-weight: 600;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (hover: hover) {
  .energy-scale button:hover,
  .save:hover,
  .ghost:hover,
  .note-remove:hover,
  .history summary:hover {
    cursor: pointer;
  }
}

/* ---------- metrics view ---------- */

.view[hidden] {
  display: none;
}

.today-strip {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.strip-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.strip-value {
  margin: 4px 0 0;
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 2.1rem;
  line-height: 1;
}

.strip-unit {
  color: var(--muted);
  font-size: 1.1rem;
}

.strip-word {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.ghost {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  min-height: 44px;
  padding: 0 16px;
}

.ghost:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

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

.metric {
  padding: 16px 14px 14px;
  border-radius: 20px;
  /* Tone is carried by a left rule, never by the number's colour alone. */
  border-left: 3px solid var(--line);
}

.metric[data-tone="good"] {
  border-left-color: var(--teal);
}

.metric[data-tone="mid"] {
  border-left-color: var(--amber);
}

.metric[data-tone="low"] {
  border-left-color: var(--rose);
}

.metric-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
}

.metric-value {
  margin: 8px 0 0;
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 2rem;
  line-height: 1;
  letter-spacing: -0.02em;
}

.metric-value.is-empty {
  color: var(--muted);
}

.metric-unit {
  font-family: "Instrument Sans", system-ui, sans-serif;
  font-size: 0.9rem;
  color: var(--muted);
  margin-left: 2px;
}

.metric-note {
  margin: 8px 0 0;
  min-height: 1.1em;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.sync-note[data-state="stale"] {
  color: var(--amber);
}

.sync-note {
  margin: 14px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  min-height: 1.1em;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
}

.empty-state h2 {
  margin: 0 0 6px;
  font-size: 1.05rem;
}

.empty-state p {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.45;
}

.empty-state code {
  display: block;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  overflow-x: auto;
}

@media (prefers-reduced-motion: reduce) {
  /* Covers animation too — a skeleton pulse or spinner would otherwise run
     for someone who explicitly asked it not to. */
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- notes through the day ---------- */

.notes-card {
  margin-top: 14px;
}

.note-add {
  display: grid;
  gap: 10px;
}

.note-add .ghost {
  justify-self: end;
}

.note-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.note {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
}

.note-time {
  color: var(--muted);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.note-text {
  margin: 0;
  line-height: 1.45;
  font-size: 0.94rem;
  overflow-wrap: anywhere;
}

.note-empty {
  color: var(--muted);
  font-size: 0.88rem;
  padding: 4px 2px;
}

.note-remove {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  /* 44px target, without pushing the row taller. */
  min-width: 44px;
  min-height: 44px;
  margin: -14px -8px -14px 0;
}

.note-remove:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: -6px;
  border-radius: 10px;
}

/* ---------- history, expandable ---------- */

.history-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: baseline;
  gap: 10px;
}

.history summary {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: baseline;
  gap: 10px;
  list-style: none;
  min-height: 24px;
}

.history summary::-webkit-details-marker {
  display: none;
}

.history summary::after {
  content: "▾";
  color: var(--muted);
  font-size: 0.7rem;
  transition: transform 160ms ease;
}

.history details[open] summary::after {
  transform: rotate(180deg);
}

.history summary:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 4px;
  border-radius: 8px;
}

.history-detail {
  color: var(--muted);
}

.history-count {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.history-body {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.history-note {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  margin: 0;
  align-items: baseline;
  color: var(--text);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

/* ---------- system line ---------- */

.sysline {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  margin: 0 0 18px;
  padding: 10px 12px 10px 13px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: 16px;
  background: rgba(14, 18, 22, 0.7);
  font-size: 0.88rem;
  line-height: 1.35;
}

.sysline[hidden] {
  display: none;
}

.sysline-mark {
  font-size: 0.8rem;
  color: var(--muted);
}

.sysline-action {
  min-height: 44px;
  padding: 0 14px;
  font-size: 0.84rem;
}

.sysline[data-tone="ok"] { border-left-color: var(--teal); background: var(--ok-bg); }
.sysline[data-tone="wait"] { border-left-color: var(--amber); background: var(--wait-bg); }
.sysline[data-tone="fail"] { border-left-color: var(--rose); background: var(--fail-bg); }
.sysline[data-tone="ok"] .sysline-mark { color: var(--teal); }
.sysline[data-tone="wait"] .sysline-mark { color: var(--amber); }
.sysline[data-tone="fail"] .sysline-mark { color: var(--rose); }

/* ---------- sign-in ---------- */

#email {
  width: 100%;
  min-height: 54px;
  padding: 0 16px;
  margin-bottom: 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  font: inherit;
}

#email:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.link-button {
  display: block;
  width: 100%;
  margin: 18px 0 0;
  padding: 12px;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  min-height: 44px;
}

.link-button:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
  border-radius: 12px;
}

.hint.centered {
  text-align: center;
  margin: 6px 0 0;
  font-size: 0.82rem;
}

/* ---------- sign-in sheet ---------- */

.sheet-scrim {
  position: fixed;
  inset: 0;
  background: rgba(3, 5, 7, 0.72);
  backdrop-filter: blur(6px);
  z-index: 10;
}

.sheet-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 11;
  width: min(430px, 100%);
  margin: 0 auto;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
  animation: sheet-in 240ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

.sheet-scrim[hidden],
.sheet-panel[hidden] {
  display: none;
}

@keyframes sheet-in {
  from { transform: translateY(12px); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet-panel { animation: none; }
}

.sheet-grabber {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--line-strong);
  margin: 0 auto 14px;
}

.sheet-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: -0.01em;
}

.sheet-close {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
}

.sheet-close:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: -4px;
}

.sheet-panel .hint {
  margin: 4px 0 16px;
}

.sheet-panel #sheet-email {
  width: 100%;
  min-height: 54px;
  padding: 0 16px;
  margin-bottom: 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  font: inherit;
}

.sheet-panel #sheet-email:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.sheet-panel .save {
  width: 100%;
}
