:root {
  --green: #2e7d32;
  --green-dark: #1b5e20;
  --green-pale: #e8f5e9;
  --bg: #f4f7f2;
  --ink: #1c2b1e;
  --muted: #6b7a6d;
  --red: #c62828;
  --amber: #ef6c00;
  --card-radius: 14px;
}

* { box-sizing: border-box; }

/* Several elements below (.pin-screen, .modal) set an unconditional
   `display: flex` for when they're visible — since that's an author-
   stylesheet rule, it silently overrides the browser's default
   `[hidden] { display: none }` UA rule regardless of specificity (origin
   beats specificity in the cascade). Without this, they'd render even
   while the `hidden` attribute is set. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: 40px;
}

h1, h2, h3 { margin: 0 0 12px; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.05rem; color: var(--green-dark); }
.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--red); font-weight: 600; min-height: 1.2em; }

/* PIN screen */
.pin-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
}
.pin-screen form { display: flex; gap: 8px; margin-top: 12px; }
.pin-screen input {
  font-size: 1.4rem;
  padding: 12px 16px;
  border-radius: 10px;
  border: 2px solid var(--green);
  width: 140px;
  text-align: center;
  letter-spacing: 4px;
}
.pin-screen button {
  font-size: 1rem;
  padding: 12px 20px;
  border-radius: 10px;
  border: none;
  background: var(--green);
  color: white;
  font-weight: 600;
}

/* App shell */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 8px;
}
header h1 { cursor: pointer; user-select: none; }

main { max-width: 480px; margin: 0 auto; padding: 0 12px; }

.card {
  background: white;
  border-radius: var(--card-radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #eef1ec;
  font-size: 0.95rem;
}
.status-row:last-of-type { border-bottom: none; }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: #eee;
  color: #555;
}
.pill-on { background: var(--green-pale); color: var(--green-dark); }
.pill-off { background: #eceeec; color: var(--muted); }
.pill-ok { background: var(--green-pale); color: var(--green-dark); }
.pill-warn { background: #fff3e0; color: var(--amber); }

label { display: block; font-size: 0.85rem; color: var(--muted); margin: 10px 0 4px; }
input[type="range"] { width: 100%; }
input[type="time"], input[type="number"] {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #d7ddd5;
  font-size: 1rem;
}

.button-row { display: flex; gap: 10px; margin-top: 12px; }

button {
  font-size: 1rem;
  font-weight: 600;
  padding: 12px 16px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  min-height: 44px; /* outdoor-friendly tap target */
}
.primary-btn { background: var(--green); color: white; flex: 1; }
.danger-btn { background: var(--red); color: white; flex: 1; }
.secondary-btn { background: var(--green-pale); color: var(--green-dark); width: 100%; margin-top: 8px; }
.secondary-btn.full, .primary-btn.full { width: 100%; }
.link-btn { background: none; border: none; color: var(--muted); font-size: 0.85rem; padding: 6px; }

.history-list { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; }
.history-item { display: flex; flex-direction: column; padding: 8px 0; border-bottom: 1px solid #eef1ec; font-size: 0.85rem; }
.history-time { color: var(--muted); font-size: 0.75rem; }
.history-out .history-text { color: var(--green-dark); font-weight: 600; }
.history-in .history-text { color: var(--ink); }

.raw-log { max-height: 200px; overflow-y: auto; font-family: monospace; font-size: 0.7rem; background: #f0f0f0; padding: 8px; border-radius: 8px; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-box { background: white; border-radius: var(--card-radius); padding: 20px; max-width: 360px; width: