/* Two themes: dark = "The Great Hall" (stone, candlelight, gold, gem hourglasses),
   light = "The Enchanted Map" (parchment, brown ink, old-print type, dashed rooms).
   theme.js sets <html data-theme="dark|light">. */
:root, [data-theme="dark"] {
  --bg: #15120f; --surface: #1f1a15; --dialog: #211b15; --field: #100d0a;
  --ink: #eadfc8; --muted: #b5a88f; --accent: #d4af6a; --accent-strong: #f0d79a;
  --line: rgba(212,175,106,.28); --line-strong: rgba(212,175,106,.6); --field-line: rgba(212,175,106,.4);
  --btn: #d4af6a; --btn-ink: #1e1608; --btn-2: #2b241c; --btn-2-ink: #eadfc8;
  --good: #8fd6a8; --bad: #f08a8a; --crest-stroke: #d4af6a;
  --head: 'Cinzel', Georgia, serif; --body: 'EB Garamond', Georgia, serif;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #efe1bf; --surface: rgba(255,249,232,.5); --dialog: #f4e8cb; --field: #f9f0da;
  --ink: #3a2614; --muted: #684f35; --accent: #3a2614; --accent-strong: #3a2614;
  --line: rgba(58,38,20,.28); --line-strong: rgba(58,38,20,.55); --field-line: rgba(58,38,20,.45);
  --btn: #3a2614; --btn-ink: #f4e8cb; --btn-2: transparent; --btn-2-ink: #3a2614;
  --good: #1d5a36; --bad: #8b1e1e; --crest-stroke: #3a2614;
  --head: 'IM Fell English SC', Georgia, serif; --body: 'IM Fell English', Georgia, serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.5 var(--body); }
a { color: var(--accent); }
[hidden] { display: none !important; }
h1, h2 { font-family: var(--head); font-weight: 700; }
[data-theme="light"] h1, [data-theme="light"] h2 { font-weight: 400; }
h1 { margin: 0; color: var(--accent); letter-spacing: .06em; font-size: clamp(1.4rem, 5vw, 2rem); line-height: 1.2; }
h2 { margin: 0 0 12px; color: var(--accent); font-size: 1.1rem; letter-spacing: .12em; }
[data-theme="light"] h2 { letter-spacing: .02em; font-size: 1.25rem; }

/* Background layers: candles in the dark, a parchment vignette in the light. Both stay behind content. */
body { position: relative; z-index: 0; isolation: isolate; }
#candles { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: -1; }
[data-theme="light"] #candles { display: none; }
[data-theme="light"] body::after { content: ''; position: fixed; inset: 0; pointer-events: none; z-index: -1; box-shadow: inset 0 0 110px rgba(120,80,30,.42); }
header, main, footer { position: relative; z-index: 1; transform: translateZ(0); }
.candle { position: absolute; width: 12px; animation: float var(--dur) ease-in-out infinite; animation-delay: var(--delay); opacity: .5; }
.candle .wax { width: 12px; height: var(--h); background: linear-gradient(90deg, #d8cfae, #fff6d6 50%, #cfc3a0); border-radius: 3px 3px 2px 2px; }
.candle .flame, .map-candle .flame { position: absolute; left: 50%; bottom: calc(var(--h) + 1px); width: 7px; height: 16px; margin-left: -3.5px;
  background: radial-gradient(ellipse at 50% 75%, #fff 0%, #ffd56b 35%, #ff9a2e 70%, transparent 100%);
  border-radius: 50% 50% 50% 50% / 65% 65% 35% 35%; transform-origin: 50% 100%;
  animation: flicker .6s ease-in-out infinite alternate; filter: drop-shadow(0 0 8px #ffb347) drop-shadow(0 0 20px #ff9a2e); }
.candle .flame::after, .map-candle .flame::after { content: ''; position: absolute; left: 50%; top: 50%; width: 80px; height: 80px; margin: -40px 0 0 -40px;
  background: radial-gradient(circle, rgba(255,190,90,.18), transparent 70%); border-radius: 50%; }
@keyframes float { 0%,100% { transform: translate(0, 0) rotate(-2deg); } 50% { transform: translate(var(--dx), -26px) rotate(2deg); } }
@keyframes flicker { from { transform: scale(1, 1) rotate(-3deg); } to { transform: scale(.88, 1.1) rotate(3deg); } }
#map-candles { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: -1; }
/* Dark mode: softer, dimmer candles with a warmer glow, like the old drifting ones */
[data-theme="dark"] .map-candle { opacity: .5; }
[data-theme="dark"] .map-candle .wax { border: 0; background: linear-gradient(90deg, #d8cfae, #fff6d6 50%, #cfc3a0); }
[data-theme="dark"] .map-candle .flame::after { width: 80px; height: 80px; margin: -40px 0 0 -40px; background: radial-gradient(circle, rgba(255,190,90,.18), transparent 70%); }
.map-candle { position: absolute; left: 0; top: 0; width: 12px; height: var(--h); transform-origin: 50% 100%; will-change: transform; }
.map-candle .wax { width: 12px; height: var(--h); background: linear-gradient(90deg, #e6d6b0, #fffaf0 50%, #d6c497); border: 1px solid rgba(58,38,20,.45); border-radius: 3px 3px 2px 2px; }
.map-candle .flame::after { width: 60px; height: 60px; margin: -30px 0 0 -30px; background: radial-gradient(circle, rgba(255,170,60,.22), transparent 70%); }
@media (prefers-reduced-motion: reduce) { .candle, .candle .flame, .map-candle .flame { animation: none; } }

/* Header */
header { text-align: center; padding: 34px 16px 8px; }
header p { color: var(--muted); margin: 6px 0 0; font-style: italic; }
[data-theme="light"] header:not(.hero) { width: min(600px, calc(100% - 2 * max(16px, env(safe-area-inset-left), env(safe-area-inset-right)))); margin: 22px auto 0; padding: 14px 12px;
  border: 2px solid var(--ink); outline: 1px solid var(--ink); outline-offset: 3px; }
/* Paint a solid header for Safari's status-area color sampling. */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 14px; background: var(--bg); border-bottom: 1px solid var(--line); }
/* Keep the phone's safe area and a small clearance above installed-iOS controls. */
body.house-app { --status-blur-gap: 0px; --appbar-height: calc(env(safe-area-inset-top, 0px) + var(--status-blur-gap) + 65px);
  padding-top: var(--appbar-height); }
@media (orientation: portrait) and (max-width: 600px) {
  html[data-ios-standalone="true"] body.house-app { --status-blur-gap: 12px; }
}
.house-app .topbar { position: fixed; left: 0; right: 0; height: var(--appbar-height);
  padding-top: calc(env(safe-area-inset-top, 0px) + var(--status-blur-gap) + 10px); }
.house-app .logo { filter: none; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--accent); min-height: 44px; }
.brand-name { font-family: var(--head); font-size: .8rem; line-height: 1.15; letter-spacing: .08em; }
@media (max-width: 480px) { .brand-name { display: none; } }
.topbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.who-line { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--muted); font-size: .92rem; }
.who-line #who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-line[hidden] { display: none; }
.topbar-link { font-size: .95rem; }
.logo { display: block; flex: none; filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)); }
.logo .logo-shield { fill: #2b1f14; stroke: var(--accent); stroke-width: 5; stroke-linejoin: round; }
.logo .logo-inner { fill: #6e1a1d; stroke: rgba(212,175,106,.55); stroke-width: 2; }
.logo .logo-ribbon, .logo .logo-ribbon-tail { fill: #e9d9b0; stroke: #8a6a35; stroke-width: 2; }
.logo .logo-text { font-family: 'Cinzel', Georgia, serif; font-weight: 700; font-size: 21px; letter-spacing: 1.5px; fill: #3a2614; }
[data-theme="light"] .logo { filter: none; }
[data-theme="light"] .logo .logo-shield { fill: #f6ead0; stroke: #3a2614; }
[data-theme="light"] .logo .logo-inner { fill: #1f3f73; stroke: #3a2614; }
[data-theme="light"] .logo .logo-ribbon, [data-theme="light"] .logo .logo-ribbon-tail { fill: #f6ead0; stroke: #3a2614; }

/* Layout */
main { max-width: 1050px; margin: 0 auto; padding: 16px;
  padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right));
  display: grid; gap: 18px; }
.grid { display: grid; gap: 18px; grid-template-columns: 1fr 1fr; }
@media (max-width: 760px) { .grid { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 18px; }
[data-theme="light"] .card { border-radius: 2px; }
.login { max-width: 420px; margin: 0 auto; width: 100%; }
.who { margin: 0; text-align: right; color: var(--muted); }
h2.household { text-align: center; margin: 0; font-size: 1.15rem; font-style: italic; font-family: var(--body); font-weight: 400; color: var(--muted); letter-spacing: 0; }
.banner { background: var(--surface); border: 1px solid var(--accent); border-radius: 6px; padding: 10px 12px; margin: 0 0 12px; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 10px; justify-content: flex-end; }
.muted { color: var(--muted); }
.warn { margin: 0; color: var(--accent); font-size: .9rem; }
.msg { margin: 0; min-height: 1.2em; }
.msg.error { color: var(--bad); } .msg.ok { color: var(--good); }

/* Forms and buttons */
form { display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-weight: 600; }
small { font-weight: normal; color: var(--muted); }
input, select, textarea { font: inherit; padding: 9px; border-radius: 4px; border: 1px solid var(--field-line); background: var(--field); color: var(--ink); width: 100%; }
input[type=color] { padding: 2px; height: 40px; cursor: pointer; }
button, .btn { font: inherit; font-weight: 700; padding: 10px 16px; border: 1px solid var(--btn); border-radius: 4px; background: var(--btn); color: var(--btn-ink); cursor: pointer; }
button:disabled { opacity: .6; cursor: wait; }
button.secondary { background: var(--btn-2); color: var(--btn-2-ink); border-color: var(--line-strong); }
button.small { padding: 4px 10px; font-size: .85rem; }
button.linkbtn { background: none; border: 0; padding: 0; font: inherit; font-weight: normal; color: var(--accent); text-decoration: underline; cursor: pointer; }
.award-link { justify-self: center; display: inline-flex; align-items: center; min-height: 44px; padding: 0 26px;
  border: 1px solid var(--accent); border-radius: 4px; font-family: var(--head); letter-spacing: .12em; text-decoration: none; color: var(--accent-strong); }
[data-theme="light"] .award-link { background: var(--btn); color: var(--btn-ink); letter-spacing: .02em; font-size: 1.1rem; }
form.inline-2 { grid-template-columns: 1fr auto; margin-top: 14px; align-items: center; }
.file { font-weight: normal; color: var(--muted); }
.file input { padding: 6px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: normal; }
label.check input { width: auto; }

/* Scoreboard. Dark: a row of gem hourglasses. Light: a list of dashed "rooms" on the map. */
.houses { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); align-items: end; }
.house { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.house .total { order: 0; font-family: var(--head); font-size: 2rem; font-weight: 700; color: var(--accent-strong); line-height: 1; }
.house .hourglass { order: 1; display: flex; flex-direction: column; align-items: center; }
.house .crest { order: 2; }
.house .info { order: 3; display: grid; gap: 2px; }
.house .house-name { font-family: var(--head); font-size: .85rem; line-height: 1.3; }
.house .kid { font-style: italic; color: var(--muted); }
.hourglass .cap { width: 62px; height: 8px; background: #b8924b; border-radius: 3px; }
.hourglass .glass { position: relative; width: 46px; height: 150px; border: 2px solid rgba(212,175,106,.7); border-radius: 23px; overflow: hidden; background: rgba(255,255,255,.04); }
.hourglass .gems { position: absolute; left: 0; right: 0; bottom: 0; background-color: var(--c); background-size: 9px 9px;
  background-image: radial-gradient(circle at 35% 35%, rgba(255,255,255,.75) 0 1.6px, rgba(255,255,255,.14) 2.4px, transparent 4px);
  transition: height .8s ease; }
.house.first .glass { box-shadow: 0 0 18px rgba(240,215,154,.35); }
[data-theme="light"] .houses { grid-template-columns: 1fr; gap: 10px; }
[data-theme="light"] .house { flex-direction: row; gap: 12px; text-align: left; border: 2px solid var(--line-strong); padding: 10px 12px; }
[data-theme="light"] .house .hourglass { display: none; }
[data-theme="light"] .house .crest { order: 0; }
[data-theme="light"] .house .info { order: 1; flex: 1; }
[data-theme="light"] .house .house-name { font-size: 1.15rem; }
[data-theme="light"] .house .total { order: 2; font-family: var(--body); font-weight: 400; font-size: 1.9rem; }
.footprints { display: none; height: 34px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='58' height='34'%3E%3Cg fill='%233a2614' opacity='.5'%3E%3Cellipse cx='14' cy='24' rx='5' ry='8' transform='rotate(-20 14 24)'/%3E%3Cellipse cx='38' cy='12' rx='5' ry='8' transform='rotate(-20 38 12)'/%3E%3C/g%3E%3C/svg%3E") repeat-x left center; }
[data-theme="light"] .footprints { display: block; }

/* Crests */
.crest { display: block; flex: none; filter: drop-shadow(0 2px 3px rgba(0,0,0,.3)); }
[data-theme="light"] .crest { filter: none; }

/* Points feed. Dark: quiet rows with gold rules. Light: an ink ledger with dotted leaders. */
.feed { list-style: none; margin: 0; padding: 0; display: grid; max-height: 70vh; overflow-y: auto; }
.feed li { padding: 8px 0; border-bottom: 1px solid var(--line); display: grid; gap: 2px; }
.feed .top { display: flex; align-items: flex-start; gap: 8px; }
.feed .who { display: flex; align-items: flex-start; gap: 8px; min-width: 0; flex: 0 1 auto; }
.feed .who .crest { margin-top: 3px; }
.feed .who-text { min-width: 0; text-align: left; overflow-wrap: anywhere; line-height: 1.3; }
.feed .who-name { font-weight: 700; }
.feed .house-sub { font-style: italic; color: var(--muted); font-size: .9rem; }
.feed .leader { flex: 1 1 0; min-width: 12px; align-self: flex-end; }
[data-theme="light"] .feed .leader { border-bottom: 2px dotted var(--line-strong); margin: 0 4px 5px; }
.feed .pts { flex: none; white-space: nowrap; font-family: var(--head); font-size: 1.05rem; line-height: 1.3; }
[data-theme="light"] .feed .pts { font-family: var(--body); font-size: 1.15rem; }
.pos { color: var(--good); font-weight: bold; } .neg { color: var(--bad); font-weight: bold; }
.feed .body { font-size: .98rem; line-height: 1.35; }
[data-theme="light"] .feed .body .reason { font-style: italic; }
.feed .body .meta { display: inline; margin-left: 8px; font-size: .8rem; color: var(--muted); }
.feed .body .meta > * + * { margin-left: 8px; }

/* People list */
.people { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.people li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--field); border: 1px solid var(--line); border-radius: 4px; }
.p-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.people li .sub { display: block; font-size: .8rem; color: var(--muted); }
button.add-child { margin-top: 14px; width: 100%; }

/* Dialogs and the Sorting */
dialog { background: var(--dialog); color: var(--ink); border: 1px solid var(--accent); border-radius: 8px; padding: 20px; width: min(380px, 92vw);
  position: fixed; max-height: calc(100vh - 32px);
  max-height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom)));
  overflow-y: auto; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; }
dialog::backdrop { background: rgba(0,0,0,.65); }
dialog h2 { margin-top: 0; }
dialog img { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto 10px; border-radius: 4px; }
dialog.sort { width: min(520px, 94vw); }
dialog.sort form { gap: 14px; }
dialog.sort h2 { margin-bottom: 0; }
fieldset { border: 1px solid var(--line); border-radius: 6px; margin: 0; padding: 10px 12px 12px; }
legend { font-weight: 700; padding: 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { background: var(--field); color: var(--ink); border: 1px solid var(--field-line); font-weight: normal; padding: 7px 11px; }
.chips button[aria-pressed="true"] { background: var(--btn); color: var(--btn-ink); border-color: var(--btn); font-weight: 700; }
.swatches button { width: 34px; height: 34px; padding: 0; border-radius: 50%; border: 2px solid rgba(255,255,255,.3); }
.swatches button[aria-pressed="true"] { border: 3px solid var(--bg); box-shadow: 0 0 0 2px var(--accent); }
dialog.sort fieldset .file { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
dialog.sort fieldset .file input { width: 52px; height: 32px; padding: 2px; }

/* The Sorting: the hat thinking, then the reveal */
:root, [data-theme="dark"] { --hat: #5b3e24; --hat-band: #d4af6a; --hat-line: #2b1c10; }
[data-theme="light"] { --hat: #4a3220; --hat-band: #8b1e1e; --hat-line: #1e130a; }
.thinking { display: grid; justify-items: center; gap: 14px; padding: 36px 0 30px; text-align: center; }
.hat { overflow: visible; }
.hat .hat-cone, .hat .hat-brim { fill: var(--hat); stroke: var(--hat-line); stroke-width: 2; }
.hat .hat-band { fill: var(--hat-band); }
.hat .hat-crease { fill: none; stroke: var(--hat-line); stroke-width: 2.5; stroke-linecap: round; opacity: .7; }
.hat { transform-origin: 50% 85%; animation: hat-think 1.1s ease-in-out infinite; }
@keyframes hat-think {
  0%, 100% { transform: rotate(-5deg) scaleY(1); }
  25% { transform: rotate(0deg) scaleY(.94); }
  50% { transform: rotate(5deg) scaleY(1); }
  75% { transform: rotate(0deg) scaleY(1.04); }
}
.thinking-text { margin: 0; font-family: var(--head); font-size: 1.2rem; color: var(--accent); }
.thinking-text::after { content: '...'; display: inline-block; width: 1.4em; text-align: left; animation: dots 1.2s steps(4, end) infinite; overflow: hidden; vertical-align: bottom; }
@keyframes dots { from { width: 0; } to { width: 1.4em; } }
.result { display: grid; justify-items: center; gap: 8px; text-align: center; }
.result .muted, .result .welcome { margin: 0; }
.result .welcome { font-style: italic; font-size: 1.1rem; }
.reveal-crest { animation: reveal .6s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes reveal { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.house-input { font-family: var(--head); font-size: 1.8rem; text-align: center; color: var(--accent-strong); background: transparent;
  border: 0; border-bottom: 2px dashed var(--line-strong); border-radius: 0; padding: 4px 0; animation: reveal .6s .15s cubic-bezier(.2, 1.4, .4, 1) both; }
.house-input:focus { outline: none; border-bottom-style: solid; border-color: var(--accent); }
.house-input.pop { animation: reveal .45s cubic-bezier(.2, 1.4, .4, 1) both; }
.result .hint { font-size: .9rem; }
.result .row { width: 100%; margin-top: 8px; }
@media (prefers-reduced-motion: reduce) { .hat, .reveal-crest, .house-input, .thinking-text::after { animation: none; } }

/* Themed confirmation */
dialog.ask { width: min(420px, 92vw); text-align: center; }
dialog.ask form { gap: 8px; justify-items: center; }
.ask-crest:empty { display: none; }
.ask-crest .crest { animation: reveal .5s cubic-bezier(.2, 1.4, .4, 1) both; }
.ask-kicker { margin: 0; font-style: italic; color: var(--muted); }
.ask-kicker:empty { display: none; }
dialog.ask h2 { margin: 0; font-size: 1.45rem; line-height: 1.25; letter-spacing: .04em; }
dialog.ask h2.pos { color: var(--good); }
dialog.ask h2.neg { color: var(--bad); }
.ask-body { margin: 0; font-size: 1.05rem; overflow-wrap: anywhere; }
.ask-warn { margin: 4px 0 0; font-style: italic; color: var(--muted); font-size: .95rem; border-top: 1px solid var(--line); padding-top: 10px; }
dialog.ask .row { width: 100%; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
.topbar button { white-space: nowrap; flex: none; }
/* Space between the list of links and the button that makes a new one */
#invites:not(:empty), #links:not(:empty) { margin-bottom: 14px; }
#invite-btn { margin-top: 2px; }

/* Content pages (About, Help, Privacy, Terms) */
main.doc { max-width: 780px; }
main.doc .card p, main.doc .card li { line-height: 1.6; }
main.doc .card p:last-child { margin-bottom: 0; }
main.doc ol, main.doc ul { padding-left: 1.3em; display: grid; gap: 6px; }
main.doc address { font-style: normal; line-height: 1.6; }
details { border-top: 1px solid var(--line); padding: 10px 0; }
details:first-of-type { border-top: 0; padding-top: 0; }
summary { cursor: pointer; font-weight: 700; min-height: 32px; display: list-item; }
details p { margin: 8px 0 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }

/* Footer on every page */
.site-footer { text-align: center; padding: 26px 16px 90px; color: var(--muted); font-size: .88rem; display: grid; gap: 6px; }
.site-footer p { margin: 0; max-width: 640px; justify-self: center; }
.site-footer nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px; font-size: 1rem; margin-bottom: 6px; }
.site-footer nav a { min-height: 32px; display: inline-flex; align-items: center; }

/* One-time storage notice */
.storage-notice { position: fixed; left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); bottom: 12px; z-index: 20;
  display: flex; flex-direction: column; align-items: stretch; gap: 12px;
  max-height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom)) - 16px);
  max-width: 640px; margin: 0 auto; padding: 10px 14px; background: var(--dialog); color: var(--ink); border: 1px solid var(--accent);
  border-radius: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.35); font-size: .92rem; }
.storage-notice p { margin: 0; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; overflow-wrap: anywhere; }
.storage-notice button { flex: none; align-self: flex-end; min-height: 44px; }
.house-app .storage-notice { max-height: calc(100dvh - var(--appbar-height) - max(12px, env(safe-area-inset-bottom)) - 16px); }

/* Settings */
button.who-btn { color: var(--muted); text-decoration: none; border-bottom: 1px dotted var(--line-strong); max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.who-btn:hover { color: var(--accent); }
dialog.settings { width: min(540px, 94vw); padding: 0 20px 20px; }
.settings-head { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center; padding: 16px 0 10px; background: var(--dialog); border-bottom: 1px solid var(--line); }
.settings-head h2 { margin: 0; }
dialog.settings section { padding: 16px 0; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
dialog.settings section:last-child { border-bottom: 0; }
dialog.settings h3 { margin: 0; font-family: var(--head); color: var(--accent); font-size: 1rem; letter-spacing: .06em; }
dialog.siri > .small-note { margin-top: 14px; }
.siri-install { display: block; text-align: center; text-decoration: none; }
.siri-disconnect { flex-basis: 100%; display: flex; gap: 8px; flex-wrap: wrap; }
.siri-disconnect p { flex-basis: 100%; margin: 0; }
#siri-connections li { flex-wrap: wrap; }
#siri-key { font-family: ui-monospace, monospace; font-size: .85rem; }
.small-note { margin: 0; font-size: .9rem; }
.danger-zone { border: 1px solid var(--bad) !important; border-radius: 6px; padding: 14px !important; margin-top: 12px; }
.danger-zone h3 { color: var(--bad) !important; }
#setup-account > summary { min-height: 44px; }
button.danger-btn { background: var(--bad); border-color: var(--bad); color: #1a0f0f; }
[data-theme="light"] button.danger-btn { color: #fff6ea; }
.captcha { min-height: 65px; }
@media (max-width: 480px) { button.who-btn { max-width: 30vw; } .topbar { padding: 6px 10px; } .topbar-right { gap: 6px; } }

/* Installed app on phones with a notch: keep the top bar and footer clear of the system areas */
.topbar { padding-top: calc(env(safe-area-inset-top, 0px) + 10px); padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
.site-footer { padding-bottom: max(90px, calc(env(safe-area-inset-bottom) + 80px)); }
.storage-notice { bottom: max(12px, env(safe-area-inset-bottom)); }
/* Jump links land below the pinned top bar instead of under it */
section[id], main[id] { scroll-margin-top: 72px; }

/* Pull-to-refresh badge (installed app only) */
.ptr { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) - 46px); z-index: 30; width: 40px; height: 40px;
  border-radius: 50%; display: grid; place-items: center; background: var(--dialog); color: var(--accent);
  border: 1px solid var(--accent); box-shadow: 0 4px 14px rgba(0,0,0,.35); transform: translate(-50%, 0); opacity: 0; pointer-events: none; }
.ptr.settle { transition: transform .25s ease, opacity .25s ease; }
.ptr svg { transition: transform .2s ease; }
.ptr.ready svg { transform: rotate(180deg); }
.ptr.busy { transform: translate(-50%, 70px) !important; opacity: 1 !important; }
.ptr.busy svg { animation: ptr-spin .8s linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }

/* Challenges and the Hall of Champions */
.between { text-align: center; display: grid; justify-items: center; gap: 6px; }
.between h2 { margin: 0; }
.between p { margin: 0; }
.between-crests { display: flex; gap: 8px; animation: reveal .6s cubic-bezier(.2, 1.4, .4, 1) both; }
.challenge-now { margin: 0; }
.standings { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; counter-reset: rank; }
.standings li { display: flex; align-items: center; gap: 10px; padding: 6px 10px; background: var(--field); border: 1px solid var(--line); border-radius: 4px; counter-increment: rank; }
.standings li::before { content: counter(rank); font-family: var(--head); color: var(--muted); min-width: 1.2em; }
.standings .st-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.hall { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.hall > li { border-bottom: 1px solid var(--line); padding-bottom: 10px; display: grid; gap: 6px; }
.hall > li:last-child { border-bottom: 0; padding-bottom: 0; }
.hall-head { display: flex; align-items: flex-start; gap: 8px; }
.hall-head .crest { margin-top: 2px; }
.hall-winner { margin: 2px 0 0; }
dialog.end { width: min(480px, 94vw); }
dialog.end h2 { margin: 0; }
.hall-head .sub, .standings .sub { display: block; font-size: .8rem; color: var(--muted); font-weight: normal; }

/* Application pages: one destination at a time, with the same Back control. */
.app-screen { display: grid; gap: 18px; width: 100%; min-width: 0; align-content: start; }
.app-screen:not([data-screen="home"]) { max-width: 720px; justify-self: center; }
.app-screen-head { display: grid; justify-items: start; gap: 18px; padding: 0 0 4px; }
.app-screen-head h2 { margin: 0; font-size: clamp(1.35rem, 5vw, 1.75rem); line-height: 1.2; letter-spacing: .02em; }
button.app-back { min-height: 44px; padding: 7px 12px; }
.app-screen h3 { margin: 0; font: 600 1.1rem/1.3 var(--head); color: var(--accent); }
.app-screen .card > h3 { margin-bottom: 12px; }
.app-screen .card.stack > h3 { margin-bottom: 0; }
.app-screen .card > form > .muted { margin: 0; }
.app-screen .card > .small-note + .feed { margin-top: 12px; }
#home-msg:empty, #records-note:empty, #settings-msg:empty { display: none; }
.home-add { display: block; width: min(100%, 340px); min-height: 52px; justify-self: center;
  text-align: center; text-decoration: none; font-family: var(--head); font-size: 1.1rem; }
#recent-feed, #feed { max-height: none; overflow: visible; }
#recent-feed > li:last-child { border-bottom: 0; }
#home-page .footprints { margin: -6px 0; }
#points-unavailable { margin: 0; }
#siri-dialog > .small-note { margin: 0; }
#siri-connection-history { padding-left: 0; }
#siri-connection-history li { padding: 10px 0; border-bottom: 1px solid var(--line); list-style: none; }
#siri-connection-history li:last-child { border-bottom: 0; }
#siri-connection-history .sub { display: block; }

/* The wand menu is a short navigation panel, not another settings dialog. */
button.menu-toggle { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px;
  min-height: 48px; padding: 4px; border: 0; border-radius: 0; background: transparent; color: var(--accent); box-shadow: none; }
button.menu-toggle:hover, button.menu-toggle:active { background: transparent; color: var(--accent-strong); }
.menu-wands { display: block; flex: none; }
.app-menu { position: absolute; top: calc(100% + 6px); right: max(10px, env(safe-area-inset-right)); z-index: 10;
  width: min(340px, calc(100vw - 20px)); max-height: calc(100dvh - 100px - env(safe-area-inset-top) - env(safe-area-inset-bottom) - var(--status-blur-gap, 0px));
  overflow-y: auto; overscroll-behavior: contain; padding: 14px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--dialog); box-shadow: 0 14px 40px rgba(0,0,0,.28); }
.menu-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 10px; }
.menu-head strong { font-family: var(--head); color: var(--accent); }
.menu-head button { min-height: 40px; }
.menu-links { list-style: none; margin: 0; padding: 0; display: grid; }
.menu-links a, .menu-profile { display: flex; align-items: center; min-height: 44px; padding: 9px 10px;
  color: var(--ink); text-decoration: none; border-radius: 4px; }
.menu-links a:hover, .menu-links a[aria-current="page"], .menu-profile:hover { background: var(--field); color: var(--accent-strong); }
.menu-links a[aria-current="page"] { box-shadow: inset 3px 0 0 var(--accent); font-weight: 700; }
.menu-account { display: grid; gap: 4px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.menu-account > .small-note { padding-left: 10px; }
.menu-profile { overflow-wrap: anywhere; }
.menu-account > button { min-height: 44px; margin-top: 6px; }
.settings-links { display: grid; padding: 0; overflow: hidden; }
.settings-links a { display: flex; justify-content: space-between; align-items: center; gap: 16px;
  min-height: 56px; padding: 14px 18px; color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--line); }
.settings-links a:last-child { border-bottom: 0; }
.settings-links a:hover { background: var(--field); }
.settings-links a > span { color: var(--muted); font-size: 1.4rem; line-height: 1; }
.menu-toggle:focus-visible, .app-menu a:focus-visible, .settings-links a:focus-visible, .app-back:focus-visible {
  outline: 2px solid var(--accent-strong); outline-offset: 3px;
}
@media (max-width: 480px) {
  #app-view { padding: 18px max(14px, env(safe-area-inset-right)) 18px max(14px, env(safe-area-inset-left)); }
  .app-screen { gap: 16px; }
  .app-screen .card { padding: 16px; }
  .app-screen .settings-links { padding: 0; }
  #sharing-page form.inline-2 { grid-template-columns: 1fr; }
}
#app-view { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
