:root {
  --bg: #0e0e10;
  --surface: #18181c;
  --surface-2: #222228;
  --line: #2e2e36;
  --text: #f2f2f5;
  --muted: #8d8d99;
  --accent: #ffd43b;
  --accent-ink: #1a1500;
  --danger: #ff6b6b;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.muted { color: var(--muted); }

#home {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

header { padding: 8px 0 16px; }

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 750;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.01em;
}

.logo {
  display: inline-grid;
  place-items: center;
  width: 40px; height: 28px;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 850;
}

textarea {
  width: 100%;
  min-height: calc(2 * 1.3em + 30px); /* two lines + padding and border */
  max-height: 45vh;
  resize: none;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 22px;
  line-height: 1.3;
  outline: none;
}
textarea:focus { border-color: var(--accent); }
textarea::placeholder { color: var(--muted); }

.themes {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 14px 0;
}

.swatch {
  min-width: 0;
  height: 40px;
  border-radius: 10px;
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
  padding: 0;
}
.swatch[aria-checked="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

button { font: inherit; color: inherit; }

.toggles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 14px;
}

.speed {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: -6px 0 14px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.speed[hidden] { display: none; }
.speed button {
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.speed button[aria-checked="true"] { background: var(--surface-2); color: var(--accent); }

.toggle {
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
}
.toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.toggle[aria-pressed="true"] {
  border-color: var(--accent);
  background: rgba(255, 212, 59, 0.12);
  color: var(--accent);
}

.primary {
  width: 100%;
  height: 56px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 19px;
  font-weight: 750;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
}
.primary:disabled { opacity: 0.35; cursor: default; }
.primary svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Install card ---------- */

.install {
  position: relative;
  margin-top: 24px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  display: grid;
  gap: 14px;
}
.install[hidden] { display: none; }

.install-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.install-close svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.install-head { display: flex; align-items: center; gap: 12px; padding-right: 32px; }
.logo-lg { width: 52px; height: 44px; border-radius: 11px; font-size: 20px; flex: none; }
.install-title { font-weight: 800; font-size: 17px; line-height: 1.2; }
.install-sub { font-size: 14px; margin-top: 2px; }

.install-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 15px; }
.install-steps[hidden] { display: none; }
.install-steps li { display: flex; align-items: center; gap: 10px; }
.install-steps .num {
  flex: none;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
}
.install-steps .step { flex: 1; }
.install-steps svg { flex: none; width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.install-steps svg.accent { color: var(--accent); }

.install-btn {
  height: 46px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: rgba(255, 212, 59, 0.12);
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}
.install-btn[hidden] { display: none; }
.install-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

#history { margin-top: 32px; }

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

input[type="search"] {
  flex: 0 1 200px;
  min-width: 0;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  outline: none;
}
input[type="search"]:focus { border-color: var(--accent); }

#list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.item {
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}

.item .open {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px 10px 16px;
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
}


.item .body { min-width: 0; flex: 1; }

.item .txt {
  font-size: 17px;
  font-weight: 550;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.item .act {
  flex: none;
  width: 44px;
  border: 0;
  background: none;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.item .act svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.item .act:active, .item .open:active { background: var(--surface-2); }
.item .del:hover { color: var(--danger); }
.item .act { width: 40px; }
.item.pinned { border-color: rgba(255, 212, 59, 0.45); }
.item .pin[aria-pressed="true"] { color: var(--accent); }
.item .pin[aria-pressed="true"] svg { fill: currentColor; }
.link[hidden] { display: none; }

.link {
  display: block;
  margin: 16px auto 0;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 14px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 8px;
}

.note { text-align: center; font-size: 13px; margin-top: 32px; }

/* ---------- Display ---------- */

#display {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--d-bg, #000);
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
#display[hidden] { display: none; }

#stage {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
}
#stage.rotated { transform: translate(-50%, -50%) rotate(90deg); }
#stage { overflow: hidden; }

#big {
  width: 100%;
  color: var(--d-fg, #fff);
  font-weight: 800;
  line-height: 1.08;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: normal;
  word-break: normal;
  text-wrap: balance;
  letter-spacing: -0.01em;
  transform: scale(var(--sx, 1), var(--sy, 1));
}

#big.marquee {
  text-align: left;
  white-space: pre;
  text-wrap: nowrap;
}
#big.marquee #track { display: inline-block; will-change: transform; }

#hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(127, 127, 127, 0.35);
  color: #fff;
  font-size: 13px;
  pointer-events: none;
  transition: opacity 0.6s;
}
#hint.gone { opacity: 0; }

video.awake {
  position: fixed;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
