/* metal: blackberry's control page. Metal heats up when it's on: awake is
   ember orange, asleep cool steel blue. Dark only, like the design. */
:root {
  color-scheme: dark;
  --bg: #0e0f12;
  --surface: #17191d;
  --raised: #23262c;
  --line: #2a2e35;
  --line-strong: #3a3f47;
  --text: #eef0f3;
  --text-2: #b4bac2;
  --muted: #9aa0a8;
  --steel: #c9cdd3;
  --ember: #ff6b2c;
  --ember-ink: #1a0e06;
  --cool: #8db3d6;
  --live: #3dd68c;
  --idle: #5c626c;
  --danger: #ff8a7a;
  --state: var(--idle);
  font-family: 'Space Grotesk', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 440px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

[data-state='awake'] {
  --state: var(--ember);
}
[data-state='asleep'] {
  --state: var(--cool);
}

button {
  font: inherit;
  cursor: pointer;
}
button:disabled {
  cursor: default;
  opacity: 0.5;
}
:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 2px;
}

.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.brand svg {
  width: 28px;
  height: 28px;
}
.seam {
  stroke: var(--idle);
  transition: stroke 0.4s;
}
[data-state='awake'] .seam {
  stroke: var(--ember);
}
.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--steel);
  display: grid;
  place-items: center;
}
.icon-button[aria-busy='true'] .icon {
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.status {
  border-radius: 20px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.state {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}
.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--state);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--state) 18%, transparent);
  flex: none;
}
.subtitle {
  margin: 0;
  font-size: 15px;
  color: var(--text-2);
}
.countdown {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.countdown-label {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}
.countdown-label span:first-child {
  color: var(--muted);
}
.bar {
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}
.bar > div {
  height: 100%;
  border-radius: 3px;
  background: var(--ember);
  transition: width 0.4s;
}

.primary {
  height: 56px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 600;
  border: 1px solid var(--line-strong);
  background: var(--raised);
  color: var(--text);
}
.primary.wake {
  height: 60px;
  border: 0;
  background: var(--ember);
  color: var(--ember-ink);
  font-size: 18px;
  font-weight: 700;
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.stat {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat span:first-child {
  font-size: 13px;
  color: var(--muted);
}
.stat span:last-child {
  font-size: 20px;
  font-weight: 600;
}

/* Sections */
section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
h2 {
  margin: 4px 4px 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}
.list {
  display: flex;
  flex-direction: column;
  padding: 0;
  margin: 0;
  list-style: none;
}
.list > * + * {
  border-top: 1px solid var(--line);
}
.stacks {
  gap: 8px;
}
.stacks > * + * {
  border-top: 0;
}
.stack {
  min-height: 52px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
}
.stack .dot {
  width: 8px;
  height: 8px;
  box-shadow: none;
  background: var(--cool);
}
[data-state='awake'] .stack .dot {
  background: var(--live);
}
.stack-name {
  flex: 1;
  font-size: 16px;
}
.stack-meta {
  font-size: 13px;
  color: var(--muted);
}
.stack .icon {
  width: 18px;
  height: 18px;
  color: var(--muted);
}

.switch {
  min-height: 52px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 16px;
}
.switch input {
  width: 22px;
  height: 22px;
  accent-color: var(--ember);
}

.events li {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  font-size: 15px;
}
.events time {
  color: var(--muted);
  width: 44px;
  font-variant-numeric: tabular-nums;
}
.events .woke {
  color: var(--ember);
}
.events .suspended {
  color: var(--cool);
}
.empty {
  padding: 14px 16px;
  margin: 0;
  font-size: 15px;
  color: var(--muted);
}

#action-error {
  margin: 0;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  color: var(--danger);
  font-size: 14px;
}

footer {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

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