:root {
  --bg: #FFFFFF; --bg2: #F1F5FF; --bg3: #E3EBFF; --fg: #0A1A33; --muted: #4A5B7A;
  --blue: #1E5BFF; --blue2: #3B82F6; --line: #DCE4F5; --glass: rgba(0, 0, 0, .35);
  --tabs: rgba(255, 255, 255, .92);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #05070D; --bg2: #0F1626; --bg3: #162036; --fg: #FFFFFF; --muted: #A9B6CF;
    --blue: #1E6BFF; --blue2: #4DA3FF; --line: #1C2842; --tabs: rgba(10, 16, 28, .92);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #05070D; --bg2: #0F1626; --bg3: #162036; --fg: #FFFFFF; --muted: #A9B6CF;
  --blue: #1E6BFF; --blue2: #4DA3FF; --line: #1C2842; --tabs: rgba(10, 16, 28, .92);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { background: var(--bg); color: var(--fg); }
body {
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh; padding-bottom: calc(76px + env(safe-area-inset-bottom));
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 8px 16px; background: var(--bg);
}
.brand { flex: 1; display: flex; align-items: center; gap: 10px; font-size: 19px; letter-spacing: -.3px; }
.brand img { width: 30px; height: 30px; border-radius: 9px; }
.brand b { color: var(--blue2); font-weight: 700; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; }
.icon-btn:active { background: var(--bg2); }

.view { padding: 0 0 16px; }
.seg { display: flex; margin: 6px 16px 4px; background: var(--bg2); border-radius: 999px; padding: 4px; }
.seg button { flex: 1; padding: 8px 0; border-radius: 999px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--blue); color: #fff; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 8px 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button, .chips.static span {
  flex: none; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); font-size: 14px; color: var(--muted); white-space: nowrap;
}
.chips button.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.chips.center { justify-content: center; flex-wrap: wrap; }

.dots { display: flex; gap: 10px; padding: 2px 16px 8px; overflow-x: auto; }
.dots button { flex: none; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; position: relative; }
.dots button.on { border: 3px solid var(--blue); }
.dots i { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; }
.dots i::after { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--dot); }
.dots .all { font-style: normal; color: var(--muted); font-size: 15px; }
.dots .all::after { display: none; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 6px 12px; }
.grid .cell { position: relative; border-radius: 14px; overflow: hidden; background: var(--bg2); }
.grid canvas { display: block; width: 100%; height: 100%; }
.grid .code { position: absolute; left: 6px; bottom: 6px; font: 600 10px ui-monospace, Menlo, monospace; color: #fff; background: rgba(0,0,0,.4); padding: 2px 6px; border-radius: 6px; }
.empty { text-align: center; color: var(--muted); padding: 60px 0; }
#sentinel { height: 1px; }

.letter { display: flex; gap: 8px; margin: 4px 16px 6px; }
.letter input {
  flex: 1; min-width: 0; padding: 12px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg2); color: var(--fg); font-size: 16px;
}
.letter button { width: 46px; border-radius: 50%; background: var(--blue); color: #fff; font-size: 22px; }
.igrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 6px; padding: 10px 12px; }
.igrid .ic { display: flex; flex-direction: column; align-items: center; gap: 6px; position: relative; }
.igrid canvas { width: 64px; height: 64px; border-radius: 22%; box-shadow: 0 4px 14px -6px rgba(0,0,0,.35); }
.igrid span { font-size: 11px; color: var(--muted); text-align: center; max-width: 76px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.igrid .ic.on canvas { outline: 3px solid var(--blue2); outline-offset: 2px; }
.igrid .ic.on::after {
  content: "✓"; position: absolute; top: -4px; right: 6px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--blue); color: #fff; font-size: 12px; display: grid; place-items: center; font-weight: 700;
}
.actions {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 6;
  display: flex; gap: 8px; background: var(--bg3); padding: 6px; border-radius: 999px; box-shadow: 0 10px 30px -10px rgba(0,0,0,.5);
}

.primary { white-space: nowrap; background: var(--blue); color: #fff; font-weight: 600; padding: 12px 22px; border-radius: 999px; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; justify-content: center; }
.primary:active { transform: scale(.98); }
.primary.big { padding: 16px 26px; font-size: 17px; width: 100%; }
.ghost { padding: 12px 18px; border-radius: 999px; color: var(--blue2); font-weight: 600; }

.hero { max-width: 420px; margin: 24px auto 0; padding: 0 16px; text-align: center; }
.hero img { width: 92px; height: 92px; border-radius: 26px; box-shadow: 0 18px 50px -14px var(--blue); }
.hero h1 { font-size: 32px; letter-spacing: -.5px; margin-top: 18px; }
.hero h1 span { color: var(--blue2); }
.bar { width: 36px; height: 4px; border-radius: 2px; background: var(--blue); margin: 12px auto 26px; }
.meta { color: var(--muted); font-size: 13px; margin: 12px 0 18px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7; display: flex;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: var(--tabs);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line);
}
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; color: var(--muted); font-size: 11px; font-weight: 600; }
.tabs button svg { width: 24px; height: 24px; padding: 2px 14px; box-sizing: content-box; border-radius: 999px; }
.tabs button.on { color: var(--fg); }
.tabs button.on svg { background: var(--blue); color: #fff; }

.preview { position: fixed; inset: 0; z-index: 20; background: #000; color: #fff; }
.preview canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.mock { position: absolute; inset: 0; text-align: center; padding-top: calc(70px + env(safe-area-inset-top)); pointer-events: none; transition: opacity .2s; }
.mock.dark { color: #0A1A33; }
.mdate { font-size: 17px; font-weight: 600; opacity: .9; }
.mtime { font-size: 92px; font-weight: 700; letter-spacing: -2px; line-height: 1; margin-top: 2px; }
.ptop, .pbottom { position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding: 0 16px; }
.ptop { top: calc(10px + env(safe-area-inset-top)); justify-content: space-between; }
.pbottom { bottom: calc(18px + env(safe-area-inset-bottom)); }
.pbottom .primary { margin-left: auto; padding: 14px 28px; }
.glass { width: 46px; height: 46px; border-radius: 50%; background: var(--glass); color: #fff; display: grid; place-items: center; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.glass.on { background: var(--blue); }
#pFav.on svg { fill: #4DA3FF; stroke: #4DA3FF; }
.pill { background: var(--glass); color: #fff; font: 600 13px ui-monospace, Menlo, monospace; padding: 9px 14px; border-radius: 999px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.sheet {
  position: absolute; left: 10px; right: 10px; bottom: calc(80px + env(safe-area-inset-bottom)); border-radius: 24px; padding: 6px 0 10px;
  background: var(--bg2); color: var(--fg); opacity: .97;
}
.sheet .chips { padding-top: 10px; }
.sheet label { display: flex; align-items: center; gap: 10px; padding: 4px 16px; font-size: 13px; font-weight: 600; }
.sheet input[type=range] { flex: 1; accent-color: var(--blue); }
.sheet label { justify-content: space-between; }
.sheet label input { max-width: 70%; }

dialog { border: 0; border-radius: 24px; padding: 22px; background: var(--bg2); color: var(--fg); width: min(340px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog h3 { font-size: 18px; margin-bottom: 14px; }
dialog input { width: 100%; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); font: 600 16px ui-monospace, Menlo, monospace; text-transform: uppercase; }
dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--fg); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
}
.busy { opacity: .6; pointer-events: none; }
