:root {
  --paper: #f4efe4;
  --surface: rgba(255, 252, 246, 0.94);
  --surface-solid: #fffdf8;
  --ink: #282821;
  --muted: #737166;
  --line: #dcd5c7;
  --line-strong: #c8bead;
  --heat: #d45d32;
  --heat-dark: #a63e20;
  --heat-soft: #f9ddd0;
  --cool: #3c7692;
  --cool-soft: #d9eaf1;
  --rest: #657162;
  --success: #3d7753;
  --warning: #a16419;
  --danger: #a53b36;
  --shadow: 0 18px 50px rgba(65, 54, 35, 0.09);
  --radius: 22px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-width: 300px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 14% -10%, rgba(213, 111, 66, 0.15), transparent 31rem),
    radial-gradient(circle at 92% 2%, rgba(80, 124, 133, 0.11), transparent 27rem),
    var(--paper);
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(60, 118, 146, 0.35);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: var(--ink);
  color: white;
  transform: translateY(-150%);
  transition: transform 120ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(1120px, calc(100% - 2rem));
  min-height: 82px;
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.72rem;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.32rem;
  line-height: 1;
  letter-spacing: -0.02em;
}

.brand small {
  margin-top: 0.26rem;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.brand-mark {
  position: relative;
  width: 30px;
  height: 42px;
  border: 2px solid var(--ink);
  border-radius: 16px;
}

.brand-mark::before {
  content: "";
  position: absolute;
  right: 6px;
  bottom: 6px;
  left: 6px;
  height: 16px;
  border-radius: 8px;
  background: var(--heat);
}

.brand-mark::after {
  content: "";
  position: absolute;
  top: -7px;
  left: 50%;
  width: 2px;
  height: 8px;
  background: var(--ink);
  transform: translateX(-50%);
}

.brand-mark span {
  position: absolute;
  z-index: 1;
  top: 10px;
  right: 7px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink);
}

.connection-button {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 42px;
  padding: 0 0.88rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.72);
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 750;
}

.connection-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #8b887d;
  box-shadow: 0 0 0 4px rgba(113, 111, 103, 0.12);
}

.connection-dot.online {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(61, 119, 83, 0.13);
}

.connection-dot.pending {
  background: var(--warning);
  box-shadow: 0 0 0 4px rgba(161, 100, 25, 0.13);
}

.connection-dot.error {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(165, 59, 54, 0.13);
}

.connection-banner {
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.65rem 1rem;
  background: #483f35;
  color: #fffdf8;
  font-size: 0.82rem;
  text-align: center;
}

.connection-banner:not([hidden]) {
  display: flex;
}

.connection-banner button {
  min-height: 32px;
  padding: 0 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  background: transparent;
  color: white;
  font-size: 0.78rem;
  font-weight: 750;
}

.app-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 0.8rem 0 1.5rem;
}

.surface {
  overflow: hidden;
  padding: 1.25rem;
  border: 1px solid rgba(191, 181, 164, 0.72);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.temperature-card {
  position: relative;
  padding: 1.4rem;
  color: #fdfaf3;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.06), transparent 38%),
    #302f29;
  box-shadow: 0 22px 55px rgba(44, 40, 31, 0.18);
}

.temperature-card::after {
  content: "";
  position: absolute;
  top: -7rem;
  right: -6rem;
  width: 17rem;
  height: 17rem;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(220, 99, 52, 0.32), rgba(220, 99, 52, 0));
  pointer-events: none;
}

.temperature-card__topline,
.output-heading,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.temperature-card .eyebrow {
  color: #bebaae;
}

.freshness {
  position: relative;
  z-index: 1;
  color: #cfcabe;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.freshness.stale {
  color: #ffd1a2;
}

.temperature-reading {
  position: relative;
  z-index: 1;
  margin: 1.15rem 0 0.9rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(4.8rem, 23vw, 7rem);
  line-height: 0.9;
  letter-spacing: -0.075em;
  font-variant-numeric: tabular-nums lining-nums;
}

.temperature-unit {
  display: inline-block;
  margin-left: 0.25rem;
  color: #d4cfc2;
  font-family: var(--font);
  font-size: 0.24em;
  font-weight: 600;
  letter-spacing: 0;
  transform: translateY(-1.9em);
}

.temperature-summary {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
  padding-bottom: 1.15rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.temperature-summary > div {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
}

.summary-label {
  color: #a9a69d;
  font-size: 0.7rem;
  font-weight: 650;
}

.temperature-summary strong {
  font-size: 1.02rem;
  font-variant-numeric: tabular-nums;
}

.mode-chip {
  grid-column: 1 / -1;
  justify-self: start;
  padding: 0.45rem 0.68rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
}

.mode-heat {
  background: rgba(233, 110, 62, 0.23);
  color: #ffc4a9;
}

.mode-cool {
  background: rgba(87, 153, 185, 0.24);
  color: #bfe9fb;
}

.mode-rest {
  background: rgba(255, 255, 255, 0.1);
  color: #d9d5ca;
}

.mode-unknown {
  background: rgba(238, 168, 77, 0.2);
  color: #ffd39d;
}

.output-block {
  position: relative;
  z-index: 1;
  margin-top: 1.15rem;
}

.output-heading {
  color: #c6c1b5;
  font-size: 0.74rem;
}

.output-heading strong {
  color: white;
  font-variant-numeric: tabular-nums;
}

.output-meter {
  overflow: hidden;
  height: 7px;
  margin-top: 0.62rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.13);
}

.output-meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: #b5b1a7;
  transition: width 350ms ease, background-color 350ms ease;
}

.output-meter span.heat {
  background: #ed7649;
}

.output-meter span.cool {
  background: #69a7c4;
}

.output-meter span.unknown {
  background: repeating-linear-gradient(
    135deg,
    #c78333 0,
    #c78333 7px,
    #e0a65b 7px,
    #e0a65b 14px
  );
}

.status-message {
  min-height: 1.3em;
  margin: 0.75rem 0 0;
  color: #b9b5ab;
  font-size: 0.75rem;
  line-height: 1.45;
}

.section-heading h2,
dialog h2 {
  margin: 0.2rem 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.43rem;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.section-heading.compact h2 {
  font-size: 1.25rem;
}

.run-state,
.chart-range {
  flex: 0 0 auto;
  padding: 0.42rem 0.62rem;
  border-radius: 999px;
  background: #e8e2d7;
  color: #615e55;
  font-size: 0.68rem;
  font-weight: 800;
}

.run-state.running {
  background: #dcebdc;
  color: #366348;
}

.run-state.starting {
  background: #f6e7c9;
  color: #875914;
}

.run-state.failed {
  background: #f5deda;
  color: #8d312d;
}

.run-state.completed {
  background: #dcebdc;
  color: #366348;
}

.profile-progress {
  align-items: center;
  gap: 1.35rem;
  margin-top: 1.35rem;
}

.profile-progress:not([hidden]) {
  display: flex;
}

.progress-ring {
  --progress: 0deg;
  display: grid;
  flex: 0 0 auto;
  width: 112px;
  height: 112px;
  padding: 9px;
  border-radius: 50%;
  background: conic-gradient(var(--heat) var(--progress), #e9e2d6 0deg);
  place-items: center;
}

.progress-ring::before {
  content: "";
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--surface-solid);
}

.progress-ring div {
  z-index: 1;
  display: flex;
  grid-area: 1 / 1;
  flex-direction: column;
  align-items: center;
}

.progress-ring strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.75rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.progress-ring span {
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.62rem;
}

.progress-details {
  display: grid;
  flex: 1;
  gap: 0.55rem;
  margin: 0;
}

.progress-details div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 0.48rem;
  border-bottom: 1px solid var(--line);
}

.progress-details div:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.progress-details dt {
  color: var(--muted);
  font-size: 0.72rem;
}

.progress-details dd {
  margin: 0;
  font-size: 0.76rem;
  font-weight: 750;
  text-align: right;
}

.fixed-run,
.idle-run {
  margin-top: 1.15rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(241, 236, 226, 0.55);
}

.fixed-run p,
.idle-run p {
  margin: 0;
  font-weight: 750;
}

.fixed-run strong {
  display: block;
  margin-top: 0.45rem;
  color: var(--heat-dark);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
}

.idle-run span {
  display: block;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.idle-run.safety-warning {
  border-color: #dba8a0;
  background: #fff3f0;
}

.idle-run.safety-warning p {
  color: var(--danger);
}

.history-card {
  min-height: 272px;
}

.chart-range {
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chart-wrap {
  position: relative;
  height: 150px;
  margin-top: 1.1rem;
}

#history-chart {
  display: block;
  width: 100%;
  height: 100%;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
  place-items: center;
}

.chart-legend {
  display: flex;
  gap: 1rem;
  margin-top: 0.45rem;
  color: var(--muted);
  font-size: 0.68rem;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.chart-legend i {
  display: block;
  width: 17px;
  height: 2px;
  border-radius: 2px;
}

.legend-temperature {
  background: var(--heat);
}

.legend-target {
  border-top: 2px dashed var(--cool);
}

.controls-card {
  padding-bottom: 1.1rem;
}

.primary-cycle-button {
  display: flex;
  align-items: center;
  width: 100%;
  margin-top: 1.2rem;
  padding: 0.9rem;
  border-radius: 17px;
  background: var(--heat);
  color: white;
  text-align: left;
  transition: background-color 140ms ease, transform 140ms ease;
}

.primary-cycle-button:hover:not(:disabled) {
  background: #c8512a;
}

.primary-cycle-button:active:not(:disabled),
.primary-button:active:not(:disabled),
.secondary-button:active:not(:disabled) {
  transform: translateY(1px);
}

.cycle-symbol {
  display: grid;
  flex: 0 0 auto;
  width: 47px;
  height: 47px;
  margin-right: 0.82rem;
  border: 1px solid rgba(255, 255, 255, 0.46);
  border-radius: 50%;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.84rem;
  font-weight: 700;
  place-items: center;
}

.primary-cycle-button strong,
.primary-cycle-button small {
  display: block;
}

.primary-cycle-button strong {
  font-size: 0.88rem;
}

.primary-cycle-button small {
  margin-top: 0.27rem;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.68rem;
}

.fixed-form {
  margin-top: 1.3rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
}

.fixed-form > label,
.token-dialog label {
  display: block;
  margin-bottom: 0.55rem;
  font-size: 0.78rem;
  font-weight: 800;
}

.fixed-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.65rem;
}

.number-field {
  position: relative;
}

.number-field input,
.token-input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #fffdfa;
  color: var(--ink);
}

.number-field input {
  padding: 0 3.1rem 0 0.85rem;
  font-size: 1.08rem;
  font-variant-numeric: tabular-nums;
}

.number-field span {
  position: absolute;
  top: 50%;
  right: 0.9rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  transform: translateY(-50%);
}

.secondary-button,
.primary-button,
.quiet-button,
.danger-button {
  min-height: 46px;
  padding: 0 1rem;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 800;
}

.secondary-button,
.primary-button {
  background: var(--ink);
  color: white;
}

.field-help,
.field-error {
  margin: 0.48rem 0 0;
  font-size: 0.68rem;
  line-height: 1.4;
}

.field-help {
  color: var(--muted);
}

.field-error {
  min-height: 1em;
  color: var(--danger);
  font-weight: 700;
}

.process-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-top: 1.15rem;
  padding-top: 1.15rem;
  border-top: 1px solid var(--line);
}

.quiet-button {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink);
}

.danger-button {
  border: 1px solid #dfb7b2;
  background: #fff7f5;
  color: var(--danger);
}

footer {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 0.7rem 0 calc(1.2rem + env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 0.65rem;
  text-align: center;
}

dialog {
  width: min(420px, calc(100% - 2rem));
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  padding: 0;
  overflow-y: auto;
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  color: var(--ink);
  background: var(--surface-solid);
  box-shadow: 0 28px 80px rgba(34, 30, 24, 0.3);
}

dialog::backdrop {
  background: rgba(39, 37, 31, 0.68);
  backdrop-filter: blur(5px);
}

dialog form {
  position: relative;
  padding: 1.5rem;
}

.dialog-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 42px;
  min-height: 42px;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
}

.dialog-copy,
.confirm-dialog p:not(.eyebrow) {
  margin: 0.7rem 0 1.2rem;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.55;
}

.token-input {
  padding: 0 0.85rem;
}

.token-dialog .primary-button {
  width: 100%;
  margin-top: 0.6rem;
}

.text-button {
  display: block;
  margin: 0.6rem auto -0.5rem;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-top: 1.35rem;
}

.toast {
  position: fixed;
  z-index: 90;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  left: 1rem;
  max-width: 430px;
  margin: auto;
  padding: 0.85rem 1rem;
  border-radius: 13px;
  background: #302f29;
  color: white;
  box-shadow: 0 14px 38px rgba(39, 35, 27, 0.24);
  font-size: 0.78rem;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transform: translateY(1rem);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: var(--danger);
}

.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;
}

[hidden] {
  display: none !important;
}

@media (min-width: 520px) {
  .surface {
    padding: 1.5rem;
  }

  .temperature-card {
    padding: 1.65rem;
  }

  .temperature-summary {
    grid-template-columns: 1fr 1fr auto;
    align-items: end;
  }

  .mode-chip {
    grid-column: auto;
    justify-self: end;
  }

  .fixed-input-row {
    grid-template-columns: minmax(120px, 0.72fr) minmax(150px, 1fr);
  }
}

@media (min-width: 820px) {
  .site-header {
    min-height: 96px;
  }

  .app-layout {
    grid-template-columns: minmax(0, 1.08fr) minmax(320px, 0.92fr);
    gap: 1.25rem;
    padding-top: 1.1rem;
  }

  .temperature-card {
    min-height: 410px;
  }

  .temperature-reading {
    margin-top: 2rem;
    font-size: 7.6rem;
  }

  .history-card {
    min-height: 318px;
  }

  .chart-wrap {
    height: 184px;
  }

  .controls-card {
    grid-column: 1 / -1;
  }

  .controls-card .primary-cycle-button,
  .controls-card .fixed-form {
    width: calc(50% - 0.62rem);
  }

  .controls-card .primary-cycle-button {
    float: left;
    min-height: 104px;
  }

  .controls-card .fixed-form {
    float: right;
    min-height: 104px;
    margin-top: 1.2rem;
    padding-top: 0;
    padding-left: 1.25rem;
    border-top: 0;
    border-left: 1px solid var(--line);
  }

  .process-actions {
    clear: both;
  }
}

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