:root {
  --bg: #000;
  --fg: #fff;
  --line: color-mix(in srgb, var(--fg) 20%, transparent);
  --soft: color-mix(in srgb, var(--fg) 9%, transparent);
  --dim: color-mix(in srgb, var(--fg) 60%, transparent);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }

/* Which half of the document is live is decided by the inline script in <head>. */
html[data-view="promo"] #app,
html[data-view="promo"] .page,
html[data-view="promo"] #toast { display: none; }
html[data-view="app"] #promo { display: none; }

html[data-view="app"],
html[data-view="app"] body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
}

/* ---------- main screen ---------- */
#app {
  position: fixed;
  left: 0;
  width: 100%;
  top: var(--vt, 0px);
  height: var(--vh, 100dvh);
}

#stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(env(safe-area-inset-top) + 68px)
    calc(env(safe-area-inset-right) + 18px)
    calc(env(safe-area-inset-bottom) + 92px)
    calc(env(safe-area-inset-left) + 18px);
  transition: padding .2s ease;
}
#app[data-mode="show"] #stage {
  padding:
    calc(env(safe-area-inset-top) + 14px)
    calc(env(safe-area-inset-right) + 14px)
    calc(env(safe-area-inset-bottom) + 14px)
    calc(env(safe-area-inset-left) + 14px);
}

#note {
  width: 100%;
  min-width: 0;
  text-align: center;
  font-weight: 800;
  line-height: 1.06;
  letter-spacing: -0.01em;
  white-space: pre-wrap;
  overflow-wrap: normal;
  outline: none;
  caret-color: var(--fg);
  -webkit-user-select: text;
  user-select: text;
}
#note.break-anywhere { overflow-wrap: anywhere; }
#note.empty { font-size: clamp(28px, 9vw, 52px) !important; font-weight: 600; }
#note.empty::before { content: attr(data-placeholder); color: var(--dim); }
#app[data-mode="show"] #note { -webkit-user-select: none; user-select: none; cursor: default; }

.bar {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: opacity .2s ease;
}
.bar-top {
  top: 0;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 10px) 0 calc(env(safe-area-inset-left) + 10px);
}
.bar-bottom {
  bottom: 0;
  justify-content: center;
  padding: 0 16px calc(env(safe-area-inset-bottom) + 16px);
  pointer-events: none;
}
.bar-bottom > * { pointer-events: auto; }
#app[data-mode="show"] .bar { opacity: 0; pointer-events: none; }
#app[data-mode="show"] .bar > * { pointer-events: none; }
.spacer { flex: 1; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  opacity: .8;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:active { background: var(--soft); opacity: 1; }
@media (hover: hover) { .icon-btn:hover { background: var(--soft); opacity: 1; } }

.show-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 15px 32px;
  border: 0;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 0 0 1px var(--line);
}
.show-btn svg { width: 20px; height: 20px; }
.show-btn:active { transform: scale(.97); }

#show-hint {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--dim);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .4s ease;
}
#app[data-mode="show"] #show-hint.visible { opacity: 1; }

@media (orientation: landscape) and (max-height: 500px) {
  #stage {
    padding-top: calc(env(safe-area-inset-top) + 52px);
    padding-bottom: calc(env(safe-area-inset-bottom) + 76px);
  }
}

/* ---------- pages ---------- */
.page {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition: opacity .2s ease, transform .2s ease, visibility 0s .2s;
}
.page.open { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }

.page-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 10px) 6px calc(env(safe-area-inset-left) + 10px);
}
.page-head h2 { margin: 0; font-size: 22px; font-weight: 700; }

.page-body {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  overflow-y: auto;
  padding: 10px calc(env(safe-area-inset-right) + 18px) calc(env(safe-area-inset-bottom) + 32px) calc(env(safe-area-inset-left) + 18px);
  -webkit-overflow-scrolling: touch;
}

.rows {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
  border-radius: 16px;
  background: var(--soft);
  overflow: hidden;
}
.rows > li + li { border-top: 1px solid var(--line); }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 12px 16px;
  border: 0;
  background: none;
  font-size: 17px;
  text-align: left;
  cursor: pointer;
}
.row svg { width: 18px; height: 18px; opacity: .5; flex: none; }
.row:active { background: var(--soft); }
.row.danger { color: #ff5a4f; }
.hint, .lede { margin: 8px 4px 22px; color: var(--dim); font-size: 14px; line-height: 1.45; }
.lede { font-size: 17px; margin-top: 4px; }
.hint.center { text-align: center; }
.empty-msg { margin: 36px 8px; text-align: center; color: var(--dim); }
.empty-msg[hidden] { display: none; }

/* saved list */
.notes li { display: flex; align-items: stretch; }
.notes .row { flex: 1; min-width: 0; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; }
.note-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  width: 100%;
  font-weight: 600;
  white-space: pre-line;
  overflow-wrap: anywhere;
}
.note-meta { font-size: 13px; color: var(--dim); }
.notes .icon-btn { align-self: center; margin-right: 6px; flex: none; }
.notes li.current .note-meta::after { content: " · showing now"; }

/* themes */
.themes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.theme {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 118px;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  text-align: left;
  cursor: pointer;
}
.theme .sample { font-size: 38px; font-weight: 800; line-height: 1; }
.theme .name { font-size: 14px; font-weight: 600; opacity: .85; }
.theme[aria-checked="true"] { outline: 3px solid var(--fg); outline-offset: 3px; }
.theme[aria-checked="true"]::after {
  content: "✓";
  position: absolute;
  top: 8px;
  right: 12px;
  font-weight: 800;
}

/* settings */
.group { margin-bottom: 22px; }
.group-title { margin: 4px 4px 10px; font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--dim); }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button {
  padding: 10px 16px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: none;
  font-size: 15px;
  cursor: pointer;
}
.seg button[aria-checked="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); font-weight: 700; }
.group .hint { margin-top: 10px; margin-bottom: 0; }

.row.toggle { cursor: default; }
.row.toggle label { flex: 1; padding: 6px 0; cursor: pointer; }
input[role="switch"] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 51px;
  height: 31px;
  margin: 0;
  border-radius: 16px;
  background: var(--line);
  cursor: pointer;
  transition: background .2s ease;
}
input[role="switch"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: var(--fg);
  opacity: .85;
  transition: transform .2s ease, background .2s ease;
}
input[role="switch"]:checked { background: var(--fg); }
input[role="switch"]:checked::after { transform: translateX(20px); background: var(--bg); opacity: 1; }

/* share + install */
.share, .install { text-align: center; }
.share .lede, .install .lede { text-align: center; }
.qr-card {
  width: min(78vw, 320px);
  margin: 6px auto 16px;
  padding: 14px;
  border-radius: 22px;
  background: #fff;
}
.qr-card svg { display: block; width: 100%; height: auto; border-radius: 6px; }
.share-url { margin: 0 0 18px; font: 14px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--dim); overflow-wrap: anywhere; }
.share-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.pill {
  padding: 13px 24px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.pill.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.pill[hidden], .install [hidden] { display: none; }
.steps { margin: 18px auto; padding-left: 1.4em; max-width: 22em; text-align: left; font-size: 17px; line-height: 1.6; }

/* toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font: 600 15px var(--font);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity .2s ease, transform .2s ease;
}
#toast.visible { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
#toast button { padding: 0; border: 0; background: none; font-weight: 800; text-decoration: underline; cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; transition-delay: 0s !important; }
}

html[data-view="app"] { touch-action: manipulation; }
