:root { color-scheme: dark; --accent: #7b5cff; --bg: #0b0d0e; --card: #1a1d1f; }
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 600px; height: 600px; overflow: hidden; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: #fff; user-select: none;
}

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; padding: 8px; }
.hidden { display: none !important; }

/* focus ring for D-pad */
.focusable { outline: none; }
.focusable:focus { box-shadow: 0 0 0 3px var(--accent); border-radius: 10px; }

/* ===================== HEADER ===================== */
.header { display: flex; align-items: center; gap: 8px; padding: 8px 10px 10px; flex: none; }
.header-title { font-size: 22px; font-weight: 700; flex: 1; }
.cam-mark { font-size: 24px; }
.hdr-btn, .vb-btn {
  background: #26292b; color: #fff; border: none; border-radius: 10px;
  font-size: 20px; padding: 8px 12px; cursor: pointer; min-width: 44px;
}
.hdr-btn.active { background: var(--accent); }

/* ===================== AUTH ===================== */
.auth-wrap { margin: auto; width: 100%; max-width: 440px; text-align: center; }
.brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 8px; }
.brand-name { font-size: 30px; font-weight: 800; }
.auth-hint { color: #aab; font-size: 14px; line-height: 1.5; margin: 6px 0; }
.auth-url { color: var(--accent); font-weight: 700; }
.code-display { display: flex; justify-content: center; gap: 8px; margin: 16px 0; }
.code-cell {
  width: 44px; height: 56px; line-height: 56px; font-size: 32px; font-weight: 700;
  background: #15191b; border-radius: 10px; color: #fff; font-variant-numeric: tabular-nums;
}
.code-cell.filled { background: #20262a; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 320px; margin: 0 auto; }
.key {
  background: #20262a; color: #fff; border: none; border-radius: 12px;
  font-size: 26px; padding: 14px 0; cursor: pointer;
}
.key-alt { background: #2c2222; }
.key-go { background: var(--accent); font-weight: 700; }
.auth-status { margin-top: 12px; color: #f5d76e; font-size: 14px; min-height: 18px; }
.auth-status.ok { color: var(--accent); }

/* ===================== FEED GRID ===================== */
.content { flex: 1; overflow-y: auto; padding: 4px 6px 4px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; align-content: start; }
.cell {
  position: relative; width: 100%; height: 0; padding-bottom: 100%; /* robust square (no aspect-ratio dependency) */
  background: #15191b; border: none; border-radius: 10px; overflow: hidden;
  cursor: pointer;
}
.cell img {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  object-fit: cover; display: block; opacity: 0; transition: opacity .25s;
}
.cell img.loaded { opacity: 1; }
.cell .fav-pip { position: absolute; top: 4px; right: 5px; font-size: 13px; filter: drop-shadow(0 1px 1px #000); }
.sentinel { grid-column: 1 / -1; height: 40px; display: flex; align-items: center; justify-content: center; }

/* ===================== VIEWER ===================== */
#viewer { padding: 0; }
.media { position: relative; flex: 1; background: #000; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.media.focusable:focus { box-shadow: inset 0 0 0 3px var(--accent); border-radius: 0; }
.media-el { width: 100%; height: 100%; object-fit: contain; background: #000; transform-origin: center center; transition: transform .12s ease-out; will-change: transform; }
.zoom-badge {
  position: absolute; top: 10px; right: 12px; background: rgba(0,0,0,.55);
  color: #fff; font-size: 16px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
}
.media-state { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #aab; font-size: 16px; text-align: center; padding: 0 24px; }
.viewer-bar { flex: none; display: flex; align-items: center; gap: 8px; padding: 10px; background: #0b0d0e; }
.vb-btn { font-size: 20px; }
.vb-name { margin-left: auto; font-size: 13px; color: #9aa; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px; }

/* ===================== STATES / SPINNER ===================== */
.state { position: absolute; inset: 64px 8px 8px; display: flex; align-items: center; justify-content: center; color: #9aa; font-size: 16px; text-align: center; padding: 0 24px; }
.spinner { width: 44px; height: 44px; border: 4px solid #2a2d31; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.spinner.small { width: 22px; height: 22px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== TOAST ===================== */
.toast {
  position: absolute; left: 50%; bottom: 76px; transform: translateX(-50%) translateY(20px);
  background: #1c1e21; color: #fff; padding: 12px 22px; border-radius: 999px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 520px; text-align: center;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #3a1416; } .toast.success { background: #14331f; }
