/* Shared look for parent, tile and login. Safari 15.8 (iPad Air 2): no :has(), nesting, color-mix() or dvh. */
:root {
  color-scheme: dark;
  --bg: #111; --bg-tile: #000; --surface: #1b1b1b; --surface-2: #242424;
  --line: #333; --line-strong: #555;
  --text: #e6e6e6; --muted: #8a8a8a; --faint: #555;
  --accent: #f5f5f5; --on-accent: #111; --accent-press: #d4d4d4;
  --alert: #e5484d; --alert-bg: rgba(229,72,77,.12);
  --overlay: rgba(0,0,0,.6); --press: rgba(255,255,255,.08); --edge: rgba(255,255,255,.22);
  --ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
  --radius: 3px; --radius-lg: 6px; /* controls and pills; dialogs */
  --font: -apple-system, system-ui, sans-serif;
}
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px var(--font); -webkit-text-size-adjust: 100%; }

/* Titles 17/600; section heads 12/600 uppercase; meta 13. */
.title, h1, h3 { margin: 0; font-size: 17px; font-weight: 600; }
h2, th, summary { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.meta { font-size: 13px; color: var(--muted); }
.kind-tag { font: 600 12px var(--font); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 2px 6px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Controls: quiet by default, 36 tall (44 on touch), tight corners. */
input, select, button {
  -webkit-appearance: none; appearance: none; box-sizing: border-box; min-height: 36px; margin: 0;
  font: inherit; line-height: 1.25; padding: 6px 12px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
@media (pointer: coarse) { input, select, button { min-height: 44px; } }
input[type=number] { width: 4em; }
input::placeholder { color: var(--muted); }
select {
  padding-right: 28px; background-repeat: no-repeat; background-position: right 10px center;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238a8a8a'/%3E%3C/svg%3E");
}
button { cursor: pointer; }
@media (hover: hover) { button:hover:not(:disabled) { border-color: var(--line-strong); } }
/* iOS only applies :active when the page has a touchstart handler: each page has <body ontouchstart="">. */
button:active:not(:disabled) { background: var(--surface-2); border-color: var(--line-strong); }

/* Primary: the one white action per page. */
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.primary:active:not(:disabled) { background: var(--accent-press); border-color: var(--accent-press); }
/* Danger: red text only, never a red fill. */
button.danger { color: var(--alert); }
button.danger:active:not(:disabled) { background: var(--alert-bg); }
/* Disabled never keeps a fill, so a disabled Start can't read as "almost ready". */
button:disabled, button.primary:disabled, button.danger:disabled { background: transparent; border-color: var(--line); color: var(--faint); cursor: default; }

:focus { outline: none; }
:focus-visible { box-shadow: var(--ring); }

progress { -webkit-appearance: none; appearance: none; height: 4px; border: 0; border-radius: 2px; background: var(--line); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--line); border-radius: 2px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 2px; }

.status { color: var(--text); }
.err, .status.err, .offline { color: var(--alert); }

/* Dialogs (confirm boxes on every page). */
dialog { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px; max-width: min(90vw, 420px); }
dialog::backdrop { background: var(--overlay); }
dialog h3 { margin: 0 0 8px; font-size: 17px; font-weight: 600; }
dialog p { margin: 0; }
dialog .row { justify-content: flex-end; margin-top: 16px; }
/* Alarm: the one red fill, a full-screen warning before something can't be undone (a tile's clips). Cancel is the
   white default; the destructive button is outlined. */
dialog.alarm { box-sizing: border-box; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 24px;
  border: 0; border-radius: 0; background: var(--alert); color: #fff; }
dialog.alarm[open] { display: flex; align-items: center; justify-content: center; }
dialog.alarm form { max-width: 560px; text-align: center; }
dialog.alarm h3 { margin-bottom: 12px; font-size: 26px; }
dialog.alarm p { font-size: 18px; line-height: 1.4; }
dialog.alarm .row { justify-content: center; margin-top: 28px; gap: 12px; }
dialog.alarm button { min-height: 52px; padding: 0 20px; font-size: 17px; border-color: #fff; }
dialog.alarm button[value="cancel"] { background: #fff; color: var(--alert); font-weight: 600; }
dialog.alarm button.danger { background: transparent; color: #fff; }
dialog.alarm button.danger:active:not(:disabled) { background: rgba(255,255,255,.15); }

/* Name dialog (askname.mjs). */
#nameInput { width: 100%; }
#nameErr { margin-top: 6px; min-height: 1.2em; }
#kindBox { border: 0; margin: 4px 0 8px; padding: 0; }
#kindBox legend { padding: 0; margin-bottom: 6px; }
/* Two-way switch: hidden radios, the checked label raised. Native radios are stripped above (appearance: none). */
.seg { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.seg label { position: relative; }
.seg input { position: absolute; top: 0; left: 0; width: 1px; height: 1px; min-height: 0; padding: 0; border: 0; opacity: 0; pointer-events: none; }
.seg span { display: flex; align-items: center; min-height: 30px; padding: 0 16px; border-radius: 2px; color: var(--muted); cursor: pointer; }
@media (pointer: coarse) { .seg span { min-height: 38px; } }
.seg input:checked + span { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-strong); }
.seg input:focus-visible + span { box-shadow: var(--ring); }

/* Feedback: one message, kept until the next action or ×; red marks an error, never a red fill. */
#notice { display: flex; align-items: flex-start; gap: 8px; padding: 2px 0 2px 12px; border-left: 2px solid var(--line-strong); }
#notice.err { border-left-color: var(--alert); color: var(--text); }
#noticeText { flex: 1; padding-top: 7px; overflow-wrap: anywhere; }
#noticeClose { flex: none; min-width: 36px; padding: 6px; border-color: transparent; background: transparent; color: var(--muted); }

/* Loading scrim (scrim.mjs): covers the page until its first data arrives, and while it navigates away. */
#scrim { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: var(--bg); transition: opacity .15s; }
#scrim.off { opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .15s, visibility 0s .15s; }
.spin { width: 20px; height: 20px; box-sizing: border-box; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
