:root {
  --bg: #fbf9f4;
  --card: #fff;
  --ink: #172033;
  --muted: #72798a;
  --line: #e7e1d7;
  --purple: #5b48e8;
  --purple-soft: #f0edff;
  --green: #18a558;
  --green-bg: #e9f8ef;
  --amber: #e99a00;
  --amber-bg: #fff4dd;
  --red: #e74747;
  --red-bg: #fdecec;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--purple); text-underline-offset: 3px; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.app {
  max-width: 500px;
  min-height: 82vh;
  margin: auto;
  padding: env(safe-area-inset-top) 18px 28px;
}
.top, .site-header {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.top { height: 62px; }
.brand {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  font-weight: 900;
  color: var(--ink);
  text-decoration: none;
}
.brand img { width: 30px; height: 30px; }
.hud { display: flex; gap: 12px; align-items: center; font-weight: 700; }
.icon, .icon-link, .close {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  color: var(--ink);
  text-decoration: none;
  font-weight: 900;
}

.screen { display: none; }
.screen.on { display: flex; flex-direction: column; }
.hero-rex { width: 150px; margin: 70px auto 8px; }
.screen h1 { text-align: center; font-size: 38px; margin: 0; }
.screen#loading p { text-align: center; color: var(--muted); }
.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid #ddd;
  border-top-color: var(--purple);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 25px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.tag {
  display: inline-flex;
  align-self: center;
  background: #ece9ff;
  color: var(--purple);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .1em;
  padding: 6px 10px;
  border-radius: 8px;
  margin: 18px 0 12px;
}
.wreck {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px 20px;
}
.wreck p { margin: 0; text-align: center; font-size: 23px; line-height: 1.38; font-weight: 800; }
.meta, .requested-by { text-align: center; color: var(--muted); font-size: 13px; }
.requested-by { margin: -4px 0 4px; color: var(--purple); font-weight: 800; }
.slots { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; margin: 14px 0; }
.slot {
  background: #f1eee7;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: #b4ad9f;
  font-weight: 900;
  letter-spacing: .14em;
}
.slot.hint { background: var(--amber-bg); color: var(--amber); letter-spacing: .03em; }
.slot.part { letter-spacing: .14em; }
.slot .lit { color: #b4740a; font-weight: 800; }
.feedback { min-height: 48px; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; }
.chip { padding: 7px 9px; border-radius: 8px; font-size: 13px; font-weight: 800; }
.chip.ok { background: var(--green-bg); color: var(--green); }
.chip.maybe { background: var(--amber-bg); color: var(--amber); }
.chip.no { background: var(--red-bg); color: var(--red); }

input, textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  padding: 15px;
  outline: none;
}
input { font-size: 17px; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, textarea:focus { border-color: var(--purple); }
.actions { display: grid; grid-template-columns: 1fr 145px; gap: 9px; margin-top: 10px; }
.primary, .secondary, .social-button, .link-button {
  border-radius: 14px;
  padding: 14px 12px;
  font-weight: 900;
  text-align: center;
  text-decoration: none;
}
.primary { border: 0; background: var(--purple); color: #fff; }
.secondary, .social-button { border: 1px solid var(--line); background: #fff; color: var(--ink); }
button:disabled { opacity: .45; cursor: not-allowed; }
.progress { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin: 13px 4px; }
.rex-line { margin-top: 25px; background: var(--purple-soft); border-radius: 13px; padding: 9px 12px; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.rex-line img { width: 34px; height: 34px; }

.result-rex { width: 150px; margin: 25px auto 0; }
#done h2 { text-align: center; font-size: 32px; margin: 0; }
#done > p { text-align: center; color: var(--muted); }
.answer { background: #fff; border: 1.5px solid var(--green); border-radius: 16px; padding: 18px; text-align: center; margin: 12px 0; }
.answer small { display: block; color: var(--muted); font-weight: 800; }
.answer strong { display: block; font-size: 22px; margin-top: 7px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stats div { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 11px; text-align: center; }
.stats small { display: block; color: var(--muted); }
.stats b { font-size: 21px; }
.result-share, .leaderboard-join, .leaderboard-preview {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 16px;
}
.result-share h3, .leaderboard-join h3, .leaderboard-preview h3 { margin: 0 0 10px; font-size: 17px; }
.result-share .primary, .result-share .secondary { width: 100%; }
.result-share .secondary { margin-top: 8px; }
.social-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.social-button { padding: 11px 8px; font-size: 13px; }
.leaderboard-join { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.leaderboard-join p { color: var(--muted); font-size: 13px; margin: -3px 0 12px; }
.nickname-row { display: grid; grid-template-columns: 1fr 125px; gap: 8px; }
.nickname-row input { font-size: 15px; padding: 12px; }
.nickname-row .primary { padding: 11px 8px; }
.form-message { min-height: 18px; margin: 9px 2px 0 !important; color: var(--purple) !important; font-weight: 700; }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.section-heading a { font-size: 13px; font-weight: 800; }
#leaderboardPreview { list-style: none; padding: 0; margin: 0; }
#leaderboardPreview li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
#leaderboardPreview li:last-child { border-bottom: 0; }
.muted-row { color: var(--muted); }
.community-cta { display: flex; flex-direction: column; gap: 4px; margin-top: 18px; padding: 15px; background: var(--purple-soft); border-radius: 14px; text-decoration: none; color: var(--ink); }
.community-cta span { color: var(--muted); font-size: 13px; }
.next { text-align: center; font-size: 13px; color: var(--muted); }

/* Shared public pages */
.site-header { max-width: 960px; margin: auto; padding: 10px 22px; }
.site-nav { display: flex; gap: 18px; align-items: center; }
.site-nav a { color: var(--muted); text-decoration: none; font-weight: 750; font-size: 14px; }
.site-nav a[aria-current="page"], .site-nav a:hover { color: var(--purple); }
.page-shell { max-width: 820px; min-height: 66vh; margin: 22px auto 70px; padding: 0 18px; }
.content-card { background: #fff; border: 1px solid var(--line); border-radius: 22px; padding: clamp(22px, 5vw, 42px); }
.content-card > .tag { margin-top: 0; }
.content-card h1 { font-size: clamp(30px, 6vw, 46px); line-height: 1.08; margin: 6px 0 14px; letter-spacing: -.035em; }
.content-card h2 { margin-top: 30px; font-size: 22px; }
.lede { color: var(--muted); font-size: 17px; line-height: 1.6; }
.prose { line-height: 1.7; }
.prose p, .prose li { color: #394154; }
.prose li + li { margin-top: 8px; }
.steps-list { padding-left: 22px; }
.example-panel, .submission-rules { background: var(--purple-soft); border-radius: 16px; padding: 18px; margin: 22px 0; }
.example-panel small { color: var(--purple); font-weight: 900; letter-spacing: .08em; }
.example-panel blockquote { margin: 10px 0; font-size: 20px; font-weight: 800; }
.link-button { display: inline-block; margin-top: 12px; }
.updated { color: var(--muted); font-size: 14px; }

.stack-form { display: grid; gap: 16px; margin-top: 24px; }
.stack-form label { display: grid; gap: 7px; font-weight: 800; }
.stack-form label input, .stack-form label textarea { font-weight: 400; }
.optional { font-weight: 500; color: var(--muted); font-size: 12px; }
.check-row { grid-template-columns: 20px 1fr !important; align-items: start; font-weight: 500 !important; line-height: 1.45; }
.check-row input { width: 18px; height: 18px; padding: 0; margin-top: 2px; }
.trap { position: absolute !important; left: -10000px !important; width: 1px !important; height: 1px !important; overflow: hidden !important; }
.success-box, .error-box { border-radius: 14px; padding: 14px 16px; margin: 18px 0; }
.success-box { background: var(--green-bg); color: #08753c; }
.error-box { background: var(--red-bg); color: #a92020; }
.error-box ul { margin-bottom: 0; }
.privacy-note { color: var(--muted); font-size: 13px; line-height: 1.55; }

.tabs { display: flex; gap: 8px; margin: 24px 0 14px; }
.tab { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 9px 16px; font-weight: 800; color: var(--muted); }
.tab.active { background: var(--purple); color: #fff; border-color: var(--purple); }
.board-status { color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.table-wrap { overflow-x: auto; }
.leaderboard-table { width: 100%; border-collapse: collapse; min-width: 520px; }
.leaderboard-table th, .leaderboard-table td { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.leaderboard-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.rank { display: inline-grid; place-items: center; min-width: 30px; height: 30px; border-radius: 50%; background: #f1eee7; font-weight: 900; }
.rank-1 { background: #fff1b9; }
.rank-2 { background: #e9edf2; }
.rank-3 { background: #f5ddc5; }

.site-footer { border-top: 1px solid var(--line); background: #f5f2eb; }
.app-footer { margin-top: 30px; }
.footer-inner { max-width: 960px; margin: auto; padding: 28px 22px; }
.footer-brand { display: flex; align-items: center; gap: 12px; }
.footer-brand img { width: 54px; height: 54px; }
.footer-brand div { display: flex; flex-direction: column; gap: 2px; }
.footer-brand span { color: var(--muted); font-size: 13px; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 12px 18px; margin: 20px 0; }
.site-footer nav a { color: var(--ink); font-size: 13px; font-weight: 750; text-decoration: none; }
.site-footer p { color: var(--muted); font-size: 12px; margin: 0; }

dialog { border: 0; border-radius: 18px; max-width: 390px; width: calc(100% - 36px); padding: 25px; box-shadow: 0 20px 70px #0003; }
dialog::backdrop { background: #0008; }
.close { float: right; }
.toast { position: fixed; z-index: 10; left: 50%; bottom: 25px; transform: translate(-50%, 20px); background: #172033; color: #fff; padding: 11px 18px; border-radius: 999px; opacity: 0; transition: .2s; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.sr-only { position: absolute; left: -10000px; }

button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid #bdb5ff; outline-offset: 2px; }
@media (max-width: 650px) {
  .site-header { align-items: flex-start; }
  .site-nav { gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
  .site-nav a { font-size: 12px; }
}
@media (max-width: 410px) {
  .actions, .nickname-row { grid-template-columns: 1fr; }
  .wreck p { font-size: 20px; }
  .social-row { grid-template-columns: 1fr; }
  .app { padding-left: 14px; padding-right: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
.footer-credit { margin-top: 16px !important; font-size: 13px !important; color: var(--ink) !important; }
.footer-credit a { color: var(--purple); font-weight: 850; text-decoration: none; }
.footer-credit a:hover { text-decoration: underline; }
.fast-notice { margin: 14px 0 0; padding: 12px 14px; border-radius: 12px; background: var(--amber-bg); color: #8b5700 !important; font-size: 13px; font-weight: 750; text-align: center !important; }
#timer {
    display: none !important;
}