/* Dark is the default. Light is applied either because the phone is set to
   light and the user has not overridden it, or because they picked light
   from the header button (which sets data-theme on <html>). */
:root {
  color-scheme: dark;
  --bg: #0f1420;
  --bg-soft: #171d2c;
  --card: #1b2233;
  --card-on: #1f3a2e;
  --line: #2a3348;
  --text: #e8ecf5;
  --muted: #8b97b0;
  --accent: #4ade80;
  --accent-dim: #22c55e;
  --accent-text: #06210f;
  --danger: #f87171;
  --warn-bg: #3b2a12;
  --warn-line: #7c5a1e;
  --warn-text: #fcd9a0;
  --scrim: rgba(4, 7, 14, .65);
  --shadow: 0 -8px 40px rgba(0, 0, 0, .5);
  --radius: 18px;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f6fb;
    --bg-soft: #ffffff;
    --card: #ffffff;
    --card-on: #e7f7ed;
    --line: #dfe4ee;
    --text: #16202f;
    --muted: #5c6a80;
    --accent: #15803d;
    --accent-dim: #16a34a;
    --accent-text: #ffffff;
    --danger: #dc2626;
    --warn-bg: #fef5e2;
    --warn-line: #e0b866;
    --warn-text: #7a4f10;
    --scrim: rgba(22, 32, 47, .38);
    --shadow: 0 -8px 40px rgba(22, 32, 47, .16);
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6fb;
  --bg-soft: #ffffff;
  --card: #ffffff;
  --card-on: #e7f7ed;
  --line: #dfe4ee;
  --text: #16202f;
  --muted: #5c6a80;
  --accent: #15803d;
  --accent-dim: #16a34a;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --warn-bg: #fef5e2;
  --warn-line: #e0b866;
  --warn-text: #7a4f10;
  --scrim: rgba(22, 32, 47, .38);
  --shadow: 0 -8px 40px rgba(22, 32, 47, .16);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Holding a tile opens the timer sheet, so the browser must not treat the
   same gesture as "select this text" or pop up its own callout menu. */
button {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden { display: none !important; }

/* ---------------- login ---------------- */
.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
}

.login-logo { font-size: 44px; color: var(--accent); line-height: 1; }

.login-card h1 { font-size: 22px; margin: 12px 0 24px; }

.login-card input {
  width: 100%;
  padding: 14px 16px;
  margin-bottom: 12px;
  font-size: 16px;            /* 16px stops iOS zooming on focus */
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.login-card input:focus { outline: none; border-color: var(--accent); }

.login-card button {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}

.login-hint { color: var(--muted); font-size: 13px; margin: -12px 0 18px; line-height: 1.5; }

.login-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 16px;
  font-size: 13px;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
}

.login-remember input { width: auto; margin: 0; accent-color: var(--accent); }

.login-card button:disabled { opacity: .6; cursor: default; }

.login-error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 12px 0 0; }

/* ---------------- header ---------------- */
header {
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

.header-row { display: flex; align-items: center; justify-content: space-between; }
.header-row h1 { font-size: 24px; margin: 0; }
.header-actions { display: flex; gap: 8px; }

.icon-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 10px;
  width: 38px; height: 38px;
  font-size: 16px;
  cursor: pointer;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 0;
  font-size: 13px;
  font-family: inherit;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
}

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok      { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.dot.warn    { background: #fbbf24; }
.dot.err     { background: var(--danger); }

/* ---------------- content ---------------- */
main { padding: 16px 20px 40px; max-width: 720px; margin: 0 auto; }

.quick { display: flex; gap: 10px; margin-bottom: 16px; }

.quick-btn {
  flex: 1;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}

.quick-btn:active { transform: scale(0.98); }

.scenes {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.scenes::-webkit-scrollbar { display: none; }

.scene-btn {
  flex: none;
  padding: 10px 18px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.scene-btn:active { transform: scale(0.97); }

.board + .board { margin-top: 24px; }

.board-name {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 0 0 10px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .08s;
}

.tile:active { transform: scale(0.98); }

.tile.on {
  background: var(--card-on);
  border-color: var(--accent-dim);
}

.tile.pending { opacity: .55; }

.tile-icon { font-size: 28px; line-height: 1; color: var(--muted); }
.tile.on .tile-icon { color: var(--accent); }

.tile-name {
  margin-top: 14px;
  font-size: 15px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.tile-state { margin-top: 4px; font-size: 13px; color: var(--muted); }
.tile.on .tile-state { color: var(--accent); }

footer {
  padding: 0 20px 32px;
  max-width: 720px;
  margin: 0 auto;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.banner {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 13px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  color: var(--warn-text);
}

/* ---------------- switch options sheet ---------------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--scrim);
}

.sheet-card {
  width: 100%;
  max-width: 460px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
}

.sheet-card h2 {
  margin: 0 0 18px;
  font-size: 17px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.sheet-section { margin-bottom: 20px; }

.sheet-label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

.sheet-row { display: flex; gap: 10px; }

.sheet-row input {
  flex: 1;
  min-width: 0;
  padding: 13px 14px;
  font-size: 16px;            /* 16px stops iOS zooming on focus */
  font-family: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.sheet-row input:focus { outline: none; border-color: var(--accent-dim); }

.sheet-note { margin: 8px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }

.icon-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.icon-btn-pick {
  width: 46px;
  height: 46px;
  font-size: 20px;
  font-family: inherit;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}

.icon-btn-pick.selected {
  color: var(--accent);
  border-color: var(--accent-dim);
  background: var(--card-on);
}

.sheet-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}

.sheet-btn {
  padding: 14px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}

.sheet-btn:active { transform: scale(0.98); }
.sheet-btn.wide { width: 100%; }

.sheet-btn.primary {
  flex: none;
  padding: 13px 20px;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

.sheet-close {
  width: 100%;
  padding: 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
}
