/* Rotten Apple — design tokens from SPEC Appendix A. Dark is the default; "system" follows the OS; light is an option. */
:root, :root[data-theme="dark"] {
  --bg-base: #0b0710; --bg-surface: #15101c; --bg-raised: #1d1626; --bg-input: #0f0a15;
  --poison: #8b3dff; --poison-hover: #a25cff; --poison-glow: #b26bff;
  --apple: #d7263d; --apple-bright: #ff3b4e;
  --text: #f2eaf7; --text-muted: #a394b3;
  --ok: #4cd07d; --warn: #e8b04a; --error: #ff5c6c;
  --line: #2b2138; --rot-a: rgba(59, 42, 32, .12); --rot-b: rgba(42, 30, 24, .10);
  --on-accent: #ffffff;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg-base: #faf6f4; --bg-surface: #ffffff; --bg-raised: #f4ece7; --bg-input: #ffffff;
  --poison: #6c2bd9; --poison-hover: #5a22b8; --poison-glow: #8b3dff;
  --apple: #c21e34; --apple-bright: #d7263d;
  --text: #1b1220; --text-muted: #6b5c78;
  --ok: #1e9e53; --warn: #b97a12; --error: #c21e34;
  --line: #e2d6cd; --rot-a: rgba(234, 223, 214, .7); --rot-b: rgba(234, 223, 214, .5);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0; background-color: var(--bg-base); color: var(--text);
  font: 15px/1.5 -apple-system, "SF Pro Text", Inter, "Segoe UI", system-ui, sans-serif;
  /* rot spots: brown texture on the page background only, never behind text (text sits on opaque surfaces) */
  background-image:
    radial-gradient(circle at 12% 18%, var(--rot-a) 0 90px, transparent 91px),
    radial-gradient(circle at 86% 72%, var(--rot-b) 0 140px, transparent 141px),
    radial-gradient(circle at 60% 8%, var(--rot-b) 0 60px, transparent 61px);
  background-attachment: fixed;
}
a { color: var(--poison-glow); text-decoration: none; }
a:hover { text-decoration: underline; }
:root[data-theme="light"] a { color: var(--poison); }
:focus-visible { outline: 2px solid var(--poison-glow); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.right { text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

header.top { display: flex; align-items: center; gap: 16px; padding: 10px 24px; background: var(--bg-surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.1rem; color: var(--text); letter-spacing: .01em; }
.brand:hover { text-decoration: none; }
.brand svg { width: 28px; height: 28px; }
nav.main { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
nav.main a { color: var(--text-muted); padding: 6px 12px; border-radius: 8px; font-weight: 600; }
nav.main a:hover { color: var(--text); background: var(--bg-raised); text-decoration: none; }
nav.main a[aria-current="page"] { color: var(--text); background: var(--bg-raised); box-shadow: inset 0 -2px 0 var(--poison); }
.userbar { display: flex; align-items: center; gap: 10px; }
select.theme { width: auto; }

.banner { padding: 8px 24px; font-weight: 600; text-align: center; border-bottom: 1px solid var(--line); }
.banner.fake { background: #3b1c22; color: #ffb3bb; }
:root[data-theme="light"] .banner.fake { background: #fde7ea; color: #8d1325; }
.banner.info { background: var(--bg-raised); color: var(--text-muted); }

main { max-width: 1120px; margin: 0 auto; padding: 24px; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.card { background: var(--bg-surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.card h2, .card h3 { margin-top: 0; }
.card.accent { border-color: var(--poison); box-shadow: 0 0 0 1px var(--poison), 0 0 24px -8px var(--poison-glow); }
section.block { margin-bottom: 32px; }
section.block > h2 { padding-bottom: 8px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }

button, .btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px; border: 1px solid var(--line); padding: 7px 14px;
  background: var(--bg-raised); color: var(--text); display: inline-block; text-align: center;
}
button:hover, .btn:hover { border-color: var(--poison); text-decoration: none; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--poison); border-color: var(--poison); color: var(--on-accent); }
button.primary:hover { background: var(--poison-hover); }
button.buy, .btn.buy { background: var(--apple); border-color: var(--apple); color: #fff; }
button.buy:hover { background: var(--apple-bright); }
button.danger { color: var(--error); border-color: var(--error); background: transparent; }
button.link { background: none; border: none; padding: 0; color: var(--poison-glow); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.stack > * + * { margin-top: 12px; }

label { display: block; font-weight: 600; margin-bottom: 4px; font-size: .9rem; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg-input); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px;
}
input[type="checkbox"], input[type="radio"] { width: auto; }
input[type="file"] { padding: 6px; }
input:focus, select:focus, textarea:focus { border-color: var(--poison); outline: none; box-shadow: 0 0 0 2px rgba(139, 61, 255, .35); }
textarea { min-height: 90px; resize: vertical; }
.field { margin-bottom: 12px; }
.inline-check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.inline-check input { margin: 0; }
form.inline { display: inline-flex; gap: 6px; align-items: center; }
form.inline input, form.inline select { width: auto; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--text-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.tablewrap { overflow-x: auto; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 700; border: 1px solid var(--line); color: var(--text-muted); background: var(--bg-raised); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.bad { color: var(--error); border-color: var(--error); }
.badge.poison { color: var(--poison-glow); border-color: var(--poison); }
.badge.apple { color: #fff; background: var(--apple); border-color: var(--apple); }

.empty { text-align: center; padding: 32px 16px; color: var(--text-muted); border: 1px dashed var(--line); border-radius: 12px; }
.notice { padding: 10px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-raised); margin-bottom: 12px; }
.notice.warn { border-color: var(--warn); }
.notice.bad { border-color: var(--error); }
.notice.ok { border-color: var(--ok); }

.app-card { display: flex; flex-direction: column; gap: 6px; }
.app-card h3 { margin: 0; }
.app-card .price { font-weight: 800; }
.app-icon { width: 56px; height: 56px; border-radius: 14px; background: linear-gradient(135deg, var(--poison), var(--apple)); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.4rem; color: #fff; }
.hero { display: flex; gap: 20px; align-items: center; margin-bottom: 20px; }
.hero .app-icon { width: 96px; height: 96px; border-radius: 22px; font-size: 2.4rem; }

.adbar { display: block; margin: 0 0 16px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: var(--bg-surface); position: relative; }
.adbar img, .adbar video { display: block; width: 100%; max-height: 120px; object-fit: cover; }
.adbar .adtag { position: absolute; top: 6px; left: 6px; font-size: .7rem; background: rgba(0, 0, 0, .6); color: #fff; padding: 1px 6px; border-radius: 4px; }
.adbar .adtools { position: absolute; top: 6px; right: 6px; display: flex; gap: 6px; }
.adbar .adtools button { padding: 1px 8px; font-size: .75rem; background: rgba(0, 0, 0, .6); color: #fff; border-color: transparent; }
.thumb { max-width: 240px; max-height: 120px; border-radius: 8px; border: 1px solid var(--line); }

.toast { position: fixed; right: 16px; bottom: 16px; max-width: 420px; padding: 12px 16px; border-radius: 10px; background: var(--bg-raised); border: 1px solid var(--line); box-shadow: 0 8px 30px rgba(0, 0, 0, .4); z-index: 20; }
.toast.error { border-color: var(--error); }
.toast.ok { border-color: var(--ok); }
.overlay { position: fixed; inset: 0; background: rgba(5, 2, 8, .7); display: flex; align-items: center; justify-content: center; z-index: 30; }
.modal { width: min(420px, 92vw); background: var(--bg-surface); border: 1px solid var(--poison); border-radius: 14px; padding: 22px; }

.tabs { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.tabs a { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); color: var(--text-muted); font-weight: 600; }
.tabs a[aria-current="true"] { color: var(--text); border-color: var(--poison); background: var(--bg-raised); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; }
.kv dt { color: var(--text-muted); } .kv dd { margin: 0; }
.codes { font-family: ui-monospace, Menlo, monospace; columns: 2; background: var(--bg-input); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.player { position: sticky; bottom: 0; background: var(--bg-surface); border-top: 1px solid var(--poison); padding: 10px 24px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.player audio { flex: 1; min-width: 200px; }
.progress { height: 6px; background: var(--bg-input); border-radius: 3px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--poison); width: 0; }
footer.foot { text-align: center; color: var(--text-muted); padding: 24px; font-size: .85rem; }

@media (prefers-reduced-motion: no-preference) {
  button, .btn, a, input, select { transition: background-color .15s, border-color .15s, box-shadow .15s; }
}
@media (max-width: 640px) {
  main { padding: 16px; } header.top { padding: 8px 12px; }
  .hero { flex-direction: column; align-items: flex-start; }
}
.grow { flex: 1; min-width: 180px; }

/* additions: pages */
.secret { font-family: ui-monospace, monospace; background: var(--bg-input); padding: 10px; border-radius: 6px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; user-select: all; }
.ad-media { max-width: 100%; max-height: 220px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-input); }
textarea { width: 100%; font: inherit; color: inherit; background: var(--bg-input); border: 1px solid var(--line); border-radius: 6px; padding: 8px; }
.dim { opacity: .6; }
.hidden { display: none !important; }
.track-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.track-row .grow { min-width: 0; }
.meter { height: 8px; background: var(--bg-input); border-radius: 4px; overflow: hidden; }
.meter > i { display: block; height: 100%; width: 0; background: var(--apple); }
.meter > i.w10 { width: 10%; } .meter > i.w20 { width: 20%; } .meter > i.w30 { width: 30%; } .meter > i.w40 { width: 40%; } .meter > i.w50 { width: 50%; }
.meter > i.w60 { width: 60%; } .meter > i.w70 { width: 70%; } .meter > i.w80 { width: 80%; } .meter > i.w90 { width: 90%; } .meter > i.w100 { width: 100%; }
article.legal { max-width: 78ch; line-height: 1.6; }
article.legal h2, article.legal h3, article.legal h4 { margin-top: 1.6em; }
article.legal code { background: var(--bg-input); padding: 0 4px; border-radius: 4px; }
footer.foot div + div { margin-top: 6px; }
