:root {
  color-scheme: light;
  --bg: #f5f1e8;
  --panel: #ffffff;
  --ink: #050505;
  --muted: #56534d;
  --line: #050505;
  --strike: #e81616;
  --strike-ink: #ffffff;
  --sighting: #ffd400;
  --success: #00c853;
  --warning: #ff7a00;
  --test: #1268d8;
  --line-soft: rgb(5 5 5 / 24%);
  --control-line: rgb(5 5 5 / 44%);
  --focus-inner: #050505;
  --focus-outer: #ffffff;
  --control-height: 56px;
  --control-radius: 10px;
  --space-related: 8px;
  --space-group: 16px;
  --space-section: 24px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

:root[data-theme="night"] {
  color-scheme: dark;
  --bg: #000000;
  --panel: #121212;
  --ink: #ffffff;
  --muted: #bdbdbd;
  --line: #ffffff;
  --line-soft: rgb(255 255 255 / 28%);
  --control-line: rgb(255 255 255 / 44%);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  overscroll-behavior: none;
}

button,
input,
select {
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--focus-inner);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--focus-outer);
}

.topbar {
  min-height: calc(62px + env(safe-area-inset-top));
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #fff;
  background: #050505;
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: clamp(0.9rem, 4vw, 1.05rem);
  font-weight: 1000;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.brand-mark {
  width: 30px;
  height: 30px;
  display: block;
}

.status-pill {
  min-height: 44px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 13px;
  color: #fff;
  background: #1d1d1d;
  border: 1px solid rgb(255 255 255 / 72%);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 1000;
  letter-spacing: 0.05em;
}

.status-dot {
  width: 11px;
  height: 11px;
  background: var(--success);
  border-radius: 50%;
}

.status-pill[data-state="offline"] .status-dot,
.status-pill[data-state="queued"] .status-dot {
  background: var(--warning);
}

.status-pill[data-state="auth"] .status-dot {
  background: var(--strike);
}

.app-shell {
  width: min(100%, 900px);
  min-height: calc(100dvh - 65px - env(safe-area-inset-top));
  margin: 0 auto;
  padding: 14px max(14px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 14px;
}

.tracking-card {
  min-height: 88px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
}

.tracking-card > div {
  min-width: 0;
  flex: 1 1 auto;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.72rem;
  font-weight: 1000;
  letter-spacing: 0.13em;
}

.tracking-card h1 {
  margin: 0;
  font-size: clamp(1.05rem, 3vw, 1.35rem);
  line-height: 1.08;
}

.tracking-card p:last-child {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.storage-alert {
  min-height: 58px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #050505;
  background: var(--sighting);
  border-radius: 10px;
}

.storage-alert > div {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.storage-alert strong {
  font-size: 0.72rem;
  font-weight: 1000;
  letter-spacing: 0.06em;
}

.storage-alert span {
  font-size: 0.72rem;
  font-weight: 750;
}

.storage-alert button {
  min-height: 42px;
  padding: 0 14px;
  color: #fff;
  background: #050505;
  border: 0;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 1000;
}

.switch {
  min-width: 82px;
  flex: 0 0 82px;
  display: grid;
  justify-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 1000;
}

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

.switch-track {
  width: 66px;
  height: 38px;
  padding: 4px;
  display: block;
  background: #6e6e6e;
  border: 2px solid var(--line);
  border-radius: 999px;
}

.switch-thumb {
  width: 24px;
  height: 24px;
  display: block;
  background: #fff;
  border: 2px solid #050505;
  border-radius: 50%;
  transition: transform 140ms ease;
}

.switch input:checked + .switch-track {
  background: var(--success);
}

.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(28px);
}

.switch input:focus-visible + .switch-track {
  outline: 3px solid var(--focus-inner);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--focus-outer);
}

.primary-actions {
  min-height: 420px;
  display: grid;
  grid-template-rows: 1fr 0.82fr;
  gap: 12px;
}

.action-button {
  position: relative;
  min-width: 0;
  min-height: 180px;
  padding: 22px;
  overflow: hidden;
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  color: #050505;
  border: 0;
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px rgb(5 5 5 / 20%);
  text-align: left;
  cursor: pointer;
}

.action-button:active {
  transform: scale(0.992);
}

.action-button.strike {
  color: var(--strike-ink);
  background: var(--strike);
}

.action-button.sighting {
  background: var(--sighting);
}

.action-kicker,
.action-hint {
  font-size: clamp(0.78rem, 2vw, 0.95rem);
  font-weight: 1000;
  letter-spacing: 0.12em;
}

.action-name {
  font-size: clamp(3.4rem, 14vw, 7rem);
  font-size: clamp(3.4rem, 17cqi, 7rem);
  font-weight: 1000;
  letter-spacing: -0.06em;
  line-height: 0.9;
  white-space: nowrap;
}

.sighting .action-name {
  font-size: clamp(2.8rem, 11vw, 6rem);
  font-size: clamp(2.8rem, 13.5cqi, 6rem);
}

.action-hint {
  margin-top: 10px;
  letter-spacing: 0.03em;
}

.bottom-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.utility-button {
  min-height: 60px;
  padding: 8px;
  display: grid;
  gap: 3px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--control-line);
  border-radius: 8px;
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

body[data-trip-mode="test"] #trip-button {
  color: #fff;
  background: var(--test);
  border-color: transparent;
}

.utility-button strong {
  font-size: 0.74rem;
}

.feedback {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #050505;
  background: var(--success);
  opacity: 0;
  pointer-events: none;
  transform: scale(1.04);
  transition: opacity 120ms linear, transform 120ms ease;
}

.feedback[data-kind="offline"] {
  background: var(--sighting);
}

.feedback[data-kind="discarded"] {
  color: #fff;
  background: #292929;
}

.feedback[data-kind="error"] {
  color: #fff;
  background: #b81010;
}

.feedback.show {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.feedback strong {
  font-size: clamp(4rem, 16vw, 8rem);
  font-weight: 1000;
  letter-spacing: -0.06em;
}

.feedback span {
  padding: 0 24px;
  font-size: 1.05rem;
  font-weight: 900;
  text-align: center;
}

.feedback-actions {
  width: min(calc(100% - 32px), 520px);
  margin-top: 18px;
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 10px;
}

.feedback-actions button {
  min-height: 56px;
  padding: 12px;
  color: #050505;
  background: #fff;
  border: 2px solid #050505;
  border-radius: var(--control-radius);
  font-weight: 1000;
}

.feedback[data-kind="error"] .feedback-actions button {
  color: #050505;
  border-color: #fff;
}

.feedback-actions button:only-child {
  grid-column: 1 / -1;
}

.update-banner {
  position: fixed;
  z-index: 40;
  right: 12px;
  bottom: calc(86px + env(safe-area-inset-bottom));
  left: 12px;
  max-width: 600px;
  margin: auto;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #fff;
  background: #050505;
  border: 1px solid rgb(255 255 255 / 70%);
  border-radius: 8px;
}

.update-banner button {
  padding: 10px;
  color: #050505;
  background: var(--sighting);
  border: 0;
  font-weight: 1000;
}

dialog {
  color: var(--ink);
}

dialog::backdrop {
  background: rgb(0 0 0 / 78%);
}

.sheet {
  width: min(calc(100% - 20px), 620px);
  max-height: calc(100dvh - 20px);
  margin: auto auto 10px;
  padding: 0;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  box-shadow: 0 18px 60px rgb(0 0 0 / 28%);
}

.sheet[open] {
  animation: sheet-in 150ms ease-out;
}

.sheet form {
  padding: clamp(18px, 4vw, 24px);
}

.sheet h2 {
  margin: 0 0 20px;
  font-size: clamp(2rem, 8vw, 3.2rem);
  letter-spacing: -0.05em;
  line-height: 1;
}

.sheet label,
.sheet legend {
  display: grid;
  gap: var(--space-related);
  font-size: 0.78rem;
  font-weight: 1000;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.field-heading {
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.field-heading small {
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.sheet input,
.sheet select {
  width: 100%;
  min-height: var(--control-height);
  padding: 10px 14px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--control-line);
  border-radius: var(--control-radius);
  font-size: 1.15rem;
  font-weight: 800;
}

.sheet input::placeholder {
  color: var(--muted);
  font-weight: 650;
  opacity: 1;
}

.sheet input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

.sheet input[type="number"]::-webkit-inner-spin-button,
.sheet input[type="number"]::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.select-field {
  position: relative;
}

.sheet select {
  appearance: none;
  padding-right: 48px;
}

.select-field::after {
  content: "";
  width: 9px;
  height: 9px;
  position: absolute;
  right: 18px;
  bottom: 22px;
  pointer-events: none;
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  transform: rotate(45deg);
}

.sheet form > label {
  margin-top: var(--space-group);
}

.sheet form > h2 + label,
.sheet form > .dialog-heading + label {
  margin-top: 0;
}

.sheet form > .field-row,
.sheet form > fieldset {
  margin-top: var(--space-group);
}

.field-row,
.export-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field-row {
  align-items: start;
}

.field-row > label,
.segmented > label {
  margin: 0;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.choice-grid {
  display: grid;
  gap: 10px;
}

.choice {
  min-height: 64px;
  padding: 12px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--control-line);
  border-radius: var(--control-radius);
  font-size: 1.05rem;
  font-weight: 1000;
}

.choice.positive,
.primary {
  color: #050505;
  background: var(--success);
  border-color: transparent;
}

.choice.subtle,
.secondary {
  color: var(--ink);
  background: var(--panel);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--control-line);
  border-radius: var(--control-radius);
}

.segmented label {
  position: relative;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented span {
  min-height: var(--control-height);
  padding: 10px;
  display: grid;
  place-items: center;
  border: 0;
}

.segmented label + label {
  border-left: 1px solid var(--control-line);
}

.segmented input:checked + span {
  color: #050505;
  background: var(--sighting);
}

.segmented input:focus-visible + span {
  outline: 3px solid var(--focus-inner);
  outline-offset: -3px;
  position: relative;
  z-index: 1;
  box-shadow: inset 0 0 0 5px var(--focus-outer);
}

.dialog-actions {
  margin-top: var(--space-section);
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 10px;
}

.dialog-actions.stacked {
  grid-template-columns: 1fr;
}

.dialog-actions button,
.primary.full-width,
.export-grid button,
.test-actions button {
  min-height: 58px;
  padding: 12px;
  border: 1px solid var(--control-line);
  border-radius: var(--control-radius);
  font-weight: 1000;
}

.dialog-actions .primary,
.primary.full-width {
  border-color: transparent;
}

.full-width {
  width: 100%;
  margin-top: var(--space-group);
}

.temperature-input {
  position: relative;
}

.temperature-input input {
  min-height: 90px;
  padding-right: 72px;
  font-size: 2.6rem;
}

.temperature-input span {
  position: absolute;
  right: 16px;
  bottom: 20px;
  font-size: 1.7rem;
}

.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.icon-button {
  width: 50px;
  height: 50px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--control-line);
  border-radius: 50%;
  font-size: 2rem;
  font-weight: 900;
}

.help {
  margin: var(--space-related) 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 650;
  line-height: 1.4;
}

.storage-panel {
  padding: var(--space-group);
  display: grid;
  gap: var(--space-group);
  background: var(--bg);
  border-radius: var(--control-radius);
}

.storage-panel h3 {
  margin: 0;
  font-size: 1.25rem;
}

.storage-panel button {
  min-height: var(--control-height);
  border: 1px solid var(--control-line);
  border-radius: var(--control-radius);
  font-weight: 1000;
}

.row-toggle {
  margin-top: var(--space-group);
  display: flex !important;
  align-items: center;
  justify-content: space-between;
}

.row-toggle input {
  width: 52px;
  min-height: 30px;
  height: 30px;
  flex: 0 0 52px;
  position: relative;
  appearance: none;
  padding: 0;
  background: var(--muted);
  border: 1px solid var(--control-line);
  border-radius: 999px;
}

.row-toggle input::after {
  content: "";
  width: 24px;
  height: 24px;
  position: absolute;
  top: 2px;
  left: 2px;
  background: var(--panel);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgb(0 0 0 / 28%);
  transition: transform 120ms ease;
}

.row-toggle input:checked {
  background: var(--success);
}

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

.sheet hr {
  margin: var(--space-section) 0;
  border: 0;
  border-top: 1px solid var(--line-soft);
}

.test-panel h3 {
  margin: 0 0 var(--space-related);
  font-size: 1.35rem;
}

.test-actions {
  margin-top: var(--space-group);
  display: grid;
  gap: 10px;
}

.danger {
  color: #fff;
  background: #b81010;
  border-color: transparent !important;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

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

.history-overview {
  margin-bottom: 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.history-overview > div {
  min-width: 0;
  padding: 10px;
  display: grid;
  gap: 3px;
  background: var(--bg);
  border: 1px solid var(--line-soft);
  border-radius: var(--control-radius);
}

.history-overview strong {
  overflow: hidden;
  font-size: 1.2rem;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-overview span {
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.history-note {
  margin: 6px 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.4;
}

#history-source {
  margin-bottom: 14px;
}

.history-list li {
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--control-line);
  border-radius: var(--control-radius);
}

.history-list .history-empty {
  padding: 14px;
  color: var(--muted);
  font-weight: 750;
}

.history-entry > summary {
  min-height: 86px;
  padding: 13px 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 18px;
  grid-template-rows: auto auto auto;
  align-items: center;
  gap: 3px 10px;
  cursor: pointer;
  list-style: none;
}

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

.history-entry > summary::after {
  content: "";
  width: 8px;
  height: 8px;
  grid-column: 3;
  grid-row: 1 / 4;
  justify-self: center;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 120ms ease;
}

.history-entry[open] > summary::after {
  transform: rotate(225deg);
}

.history-entry > summary:focus-visible {
  outline: 3px solid var(--focus-inner);
  outline-offset: -3px;
  box-shadow: inset 0 0 0 5px var(--focus-outer);
}

.history-entry summary strong {
  min-width: 0;
  grid-column: 1;
  grid-row: 1;
  font-size: 1rem;
  line-height: 1.2;
}

.history-brief {
  min-width: 0;
  overflow: hidden;
  grid-column: 1 / 3;
  grid-row: 2;
  color: var(--ink);
  font-size: 0.79rem;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-state {
  grid-column: 2;
  grid-row: 1;
  align-self: center;
  padding: 6px 8px;
  color: #050505;
  background: var(--sighting);
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 1000;
  letter-spacing: 0.04em;
}

.history-state[data-state="synced"] {
  background: var(--success);
}

.history-state[data-state="rejected"] {
  color: #fff;
  background: #b81010;
}

.history-entry time {
  grid-column: 1 / 3;
  grid-row: 3;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
}

#history-title {
  font-size: clamp(2rem, 7vw, 2.7rem);
}

.history-details {
  padding: var(--space-group);
  background: var(--panel);
  border-top: 1px solid var(--line-soft);
}

.history-details section + section {
  margin-top: var(--space-section);
}

.history-details h3 {
  margin: 0 0 var(--space-related);
  font-size: 0.7rem;
  font-weight: 1000;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.history-details dl {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(105px, 0.7fr) minmax(0, 1.3fr);
  gap: var(--space-related) 12px;
}

.history-details dt,
.history-details dd {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.35;
}

.history-details dt {
  color: var(--muted);
  font-weight: 750;
}

.history-details dd {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.history-details dd[data-tone="good"] {
  color: #087735;
}

:root[data-theme="night"] .history-details dd[data-tone="good"] {
  color: #53e88e;
}

.history-details dd[data-tone="warning"] {
  color: #9a4b00;
}

:root[data-theme="night"] .history-details dd[data-tone="warning"] {
  color: #ffad5c;
}

.history-details dd[data-tone="danger"] {
  color: #b81010;
}

:root[data-theme="night"] .history-details dd[data-tone="danger"] {
  color: #ff7373;
}

.history-details dd[data-tone="code"] {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 650;
}

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

@media (min-width: 700px) and (orientation: landscape) {
  .app-shell {
    grid-template-rows: auto auto minmax(0, 1fr) auto;
  }

  .primary-actions {
    min-height: 330px;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
    grid-template-rows: 1fr;
  }

  .sighting .action-name {
    font-size: clamp(2.8rem, 13.5cqi, 4.25rem);
  }
}

@media (max-height: 700px) {
  .tracking-card {
    min-height: 74px;
  }

  .primary-actions {
    min-height: 320px;
  }

  .action-button {
    min-height: 140px;
  }
}

@media (max-width: 480px) {
  .topbar {
    gap: 8px;
  }

  .brand {
    gap: 7px;
    font-size: 0.86rem;
    letter-spacing: 0.04em;
  }

  .brand-mark {
    width: 26px;
    height: 26px;
  }

  .status-pill {
    gap: 6px;
    padding: 0 10px;
    font-size: 0.65rem;
  }

  .status-dot {
    width: 9px;
    height: 9px;
  }

  .tracking-card {
    padding: 13px 14px;
    gap: 10px;
  }

  .tracking-card h1 {
    font-size: 1.05rem;
  }

  .tracking-card p:last-child {
    font-size: 0.72rem;
  }

  .storage-alert {
    align-items: flex-start;
  }

  .storage-alert button {
    align-self: center;
  }

  .switch {
    min-width: 72px;
    flex-basis: 72px;
  }

  .sheet h2 {
    font-size: clamp(2rem, 12vw, 3rem);
  }

  .field-row,
  .export-grid {
    grid-template-columns: 1fr;
  }

  .feedback-actions {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
