/* PonPonKo web app. Mobile first; the forest at night (Sanzo Wada 325). */
:root {
  --ochre-300: #EFD27F; --ochre-500: #E2B540; --ochre-700: #A9831F;
  --red-300: #EC8C94; --red-500: #DA525D;
  --naples-50: #FEF9EA; --naples-100: #FDF2CF; --naples-300: #FBE6A0;
  --slate-300: #7F9895; --slate-500: #3F5D59; --slate-700: #1E4440; --slate-800: #163A36; --slate-900: #112F2C; --slate-950: #0A1D1B;
  --bg: var(--slate-950); --surface: var(--slate-900); --raised: var(--slate-800); --line: var(--slate-700);
  --text: var(--naples-50); --text-2: var(--slate-300);
  --display: ui-rounded, "SF Pro Rounded", "Zen Maru Gothic", system-ui, -apple-system, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 20px;
  --pad: max(16px, env(safe-area-inset-left));
  color-scheme: dark;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { font: 16px/1.5 var(--body); -webkit-font-smoothing: antialiased; overscroll-behavior-y: contain; }
h1, h2, h3 { font-family: var(--display); letter-spacing: -0.01em; line-height: 1.15; margin: 0; }
a { color: var(--ochre-300); }
button { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.app { min-height: 100dvh; }
.screen { min-height: 100dvh; display: flex; flex-direction: column; }
.center { align-items: center; justify-content: center; text-align: center; padding: 32px var(--pad); gap: 24px; }
.splash { min-height: 100dvh; display: grid; place-items: center; }
.splash img { animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.04); opacity: .8; } }

/* Top bar, under the status bar when installed. */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) var(--pad) 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.lockup { height: 30px; width: auto; }
.topbar-actions { display: flex; gap: 6px; }
.icon-button { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: transparent; color: var(--naples-100); cursor: pointer; }
.icon-button:active { background: var(--raised); }
.icon-button.spinning .icon { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* The island: the app's status mark, as around the MacBook notch. */
.island { display: inline-flex; align-items: center; gap: 0; padding: 12px 22px 16px; background: #000;
  border-radius: 0 0 28px 28px; box-shadow: 0 14px 40px rgba(0,0,0,.5); }
.island .gap { width: 92px; }
.island .eye { position: relative; width: 26px; height: 26px; }
.island .eye::before { content: ""; position: absolute; left: 1px; right: 1px; top: 6px; height: 10px;
  border-bottom: 3px solid var(--naples-100); border-radius: 0 0 50% 50%; opacity: .9; }
.island.open .eye::before { inset: 0; height: auto; border: 0; border-radius: 50%; background: var(--ochre-500); opacity: 1; }
.island.open .eye::after { content: ""; position: absolute; left: 7px; top: 7px; width: 12px; height: 12px; border-radius: 50%;
  background: #000; box-shadow: inset 3px 3px 0 -1px var(--naples-50); }
.island.alert .eye::before { background: var(--red-500); }

/* Welcome */
.welcome-body { flex: 1; display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 24px var(--pad) calc(32px + env(safe-area-inset-bottom)); gap: 18px; max-width: 520px; margin: 0 auto; width: 100%; }
.welcome-body .island { margin-bottom: 12px; }
.welcome h1 { font-size: clamp(1.9rem, 8vw, 2.6rem); color: var(--naples-50); text-wrap: balance; word-break: auto-phrase; }
.lead { color: var(--naples-100); font-size: 1.05rem; margin: 0; }
.hint { color: var(--text-2); font-size: .92rem; margin: 0; }
.fineprint { color: var(--text-2); font-size: .82rem; margin: 0; }
.center-text { text-align: center; padding: 8px 0 0; }
/* Apple's sign-in, our look: the styled button is underneath, Apple's real
   button (#apple-sign-*) is stretched over it at near-zero opacity and takes
   the tap (app.js, slot). */
.apple-slot { position: relative; width: 100%; max-width: 340px; }
.signin-slot { margin: 8px auto 0; }
.apple-button { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 50px;
  padding: 0 20px; border-radius: 12px; background: #fff; color: #000;
  font: 600 17px/1 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; letter-spacing: -0.01em; }
.apple-slot:active .apple-button { background: #e8e8e8; }
.signout-slot .apple-button { background: transparent; color: var(--naples-50); border: 1px solid var(--line); min-height: 46px; font-size: 16px; }
.signout-slot:active .apple-button { background: var(--raised); }
.apple-glyph { width: 17px; height: 20px; fill: currentColor; margin-top: -3px; flex: none; }
.apple-slot > [id^="apple-sign-"] { position: absolute; inset: 0; z-index: 2; opacity: 0.011; overflow: hidden; cursor: pointer; border-radius: 12px; }
.apple-slot > [id^="apple-sign-"] * { width: 100% !important; height: 100% !important; max-width: none !important; min-width: 0 !important; }

/* Home */
.content { display: flex; flex-direction: column; gap: 16px; width: 100%; max-width: 560px; margin: 0 auto;
  padding: 8px var(--pad) calc(32px + env(safe-area-inset-bottom)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card p { margin: 8px 0 0; }
.card-title { display: flex; align-items: center; gap: 10px; }
.card-title h2 { font-size: 1.15rem; }
.bell { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--raised); color: var(--ochre-300); }
.alerts.on .bell { background: var(--ochre-500); color: var(--slate-950); }
.pill.on { margin-left: auto; color: var(--ochre-500); font-size: 12px; animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.alerts .button { margin-top: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row .button { flex: 1; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; padding: 0 20px;
  border-radius: 14px; border: 1px solid transparent; font-weight: 600; text-decoration: none; cursor: pointer; width: 100%; }
.button.primary { background: var(--ochre-500); color: var(--slate-950); }
.button.primary:active { background: var(--ochre-300); }
.button.ghost { background: var(--raised); border-color: var(--line); color: var(--naples-50); }
.button:disabled { opacity: .6; }
.error { border-color: var(--red-500); }
.error p:first-child { color: var(--red-300); margin-top: 0; }

.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-2);
  font-family: var(--body); font-weight: 600; margin: 4px 2px 10px; }
.latest { padding: 14px; }
.photo-button { position: relative; display: block; width: 100%; padding: 0; border: 0; border-radius: 14px; overflow: hidden;
  background: #000; cursor: pointer; aspect-ratio: 4 / 3; }
.photo { width: 100%; height: 100%; object-fit: cover; }
.badge { position: absolute; padding: 5px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.badge.alarm { left: 10px; top: 10px; background: color-mix(in srgb, var(--red-500) 88%, transparent); color: #fff; }
.badge.count { right: 10px; bottom: 10px; background: rgba(0,0,0,.55); color: var(--naples-50); }
.latest-meta { padding: 12px 4px 2px; }
.latest-meta .when { font-family: var(--display); font-size: 1.35rem; margin: 0; }
.latest-meta .sub { color: var(--text-2); margin: 2px 0 0; font-size: .95rem; }
.map-link { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; text-decoration: none; font-weight: 600; }
.map-link .icon { width: 18px; height: 18px; }

.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.row-button { display: flex; align-items: center; gap: 14px; width: 100%; padding: 10px 12px 10px 10px; border: 0;
  background: transparent; text-align: left; cursor: pointer; min-height: 72px; }
.row-button:active { background: var(--raised); }
.thumb { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; background: #000; flex: none; }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-title { font-weight: 600; }
.row-sub { color: var(--text-2); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-button .icon { color: var(--text-2); width: 18px; height: 18px; }

.empty { text-align: center; padding: 32px 20px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty .island { transform: scale(.85); margin-bottom: 8px; }
.empty p { color: var(--text-2); margin: 0; }
.skeleton-photo { aspect-ratio: 4 / 3; border-radius: 14px; background: linear-gradient(100deg, var(--raised) 40%, var(--slate-700) 50%, var(--raised) 60%) 0 0 / 300% 100%;
  animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -150% 0; } }

/* Incident viewer: full screen, swipe between photos. */
.viewer { width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: #000; color: var(--naples-50); overflow-y: auto; }
.viewer::backdrop { background: #000; }
.viewer-bar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  padding: calc(6px + env(safe-area-inset-top)) var(--pad) 6px; background: linear-gradient(#000c, #0000); }
.counter { font-variant-numeric: tabular-nums; color: var(--naples-100); font-size: .95rem; padding-left: 4px; }
.gallery { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.gallery::-webkit-scrollbar { display: none; }
.gallery figure { flex: 0 0 100%; margin: 0; scroll-snap-align: center; }
.gallery img { width: 100%; max-height: 72dvh; object-fit: contain; background: #000; }
.gallery figcaption { text-align: center; color: var(--text-2); font-size: .85rem; padding: 6px; font-variant-numeric: tabular-nums; }
.viewer-details { padding: 8px var(--pad) calc(28px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto; }
.viewer-details h2 { font-size: 1.4rem; margin-bottom: 10px; }
.viewer-details dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0 0 16px; }
.viewer-details dt { color: var(--text-2); }
.viewer-details dd { margin: 0; }

/* Settings: a bottom sheet on phones, a panel on wider screens. */
.sheet { width: 100%; max-width: 560px; margin: auto auto 0; padding: 8px var(--pad) calc(24px + env(safe-area-inset-bottom));
  border: 1px solid var(--line); border-bottom: 0; border-radius: 24px 24px 0 0; background: var(--surface); color: var(--text);
  max-height: 88dvh; overflow-y: auto; }
.sheet[open] { animation: rise .25s ease-out; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet::backdrop { background: rgba(0,0,0,.55); }
.sheet-bar { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 4px; }
.sheet-bar h2 { font-size: 1.3rem; }
.sheet section { padding: 14px 0; border-top: 1px solid var(--line); }
.sheet section:first-of-type { border-top: 0; }
.sheet h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-2); font-family: var(--body); margin-bottom: 10px; }
.sheet p { margin: 0 0 10px; }
.segmented { display: flex; background: var(--bg); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; }
.segmented button.selected { background: var(--raised); color: var(--ochre-300); font-weight: 600; }
.device-list { list-style: none; margin: 0; padding: 0; }
.device-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.device-list small { display: block; color: var(--text-2); }
.device-list em { color: var(--ochre-300); font-style: normal; }
.link-button { border: 0; background: none; color: var(--red-300); cursor: pointer; padding: 8px; min-height: 44px; }
.ck-buttons { position: fixed; left: -10000px; top: 0; width: 320px; opacity: 0; pointer-events: none; }

@media (min-width: 720px) {
  .sheet { margin: auto; border-radius: 24px; border-bottom: 1px solid var(--line); }
  .content { padding-top: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
.noscript { padding: 24px; text-align: center; }

/* Add to Home Screen helper */
.install-slot:empty { display: none; }
.install-slot { width: 100%; }
.welcome .install-slot { margin-top: 12px; text-align: left; }
.install { position: relative; border-color: var(--ochre-700); background: linear-gradient(160deg, var(--slate-800), var(--surface)); }
.install .card-title { padding-right: 36px; }
.install-icon { width: 40px; height: 40px; border-radius: 10px; flex: none; }
.install-close { position: absolute; top: 6px; right: 6px; color: var(--text-2); }
.install-close .icon { width: 18px; height: 18px; }
.install-steps { margin: 12px 0 0; padding-left: 1.3em; color: var(--naples-100); }
p.install-steps { padding-left: 0; }
.install-steps li { margin: 6px 0; padding-left: 2px; }
.install-steps li::marker { color: var(--ochre-300); font-weight: 700; }
.share-glyph { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--raised);
  color: #4EA3FF; vertical-align: middle; }
.share-glyph .icon { width: 18px; height: 18px; }
.install .button { margin-top: 14px; }

/* Alerts without a photo (no camera, or none in time). */
.no-photo { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; width: 100%; height: 100%;
  min-height: 220px; padding: 20px; text-align: center; color: var(--naples-100); background: radial-gradient(circle at 50% 40%, #3a1418, #000 70%); }
.no-photo .island { transform: scale(.8); }
.thumb-empty { display: grid; place-items: center; overflow: hidden; }
.thumb-empty .island { transform: scale(.32); }

.stale-note { margin: -4px 4px 0; color: var(--text-2); font-size: .85rem; text-align: center; }
.error .button { margin-top: 12px; }

/* Loading state for buttons (Show a test). */
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .8s linear infinite; flex: none; }
.button.done { color: var(--ochre-300); border-color: var(--ochre-700); }
.button:not(:disabled):active { transform: scale(.98); }
/* Hidden switch flipped for haptics on iPhone (app.js, haptic). */
.haptic-switch { position: fixed; left: -100px; top: 0; opacity: 0; pointer-events: none; }
