:root {
  --ink: #f3f5f7;
  --muted: #9aa3ad;
  --green: #3ee05a;
  --green-dark: #2ec44a;
  --green-soft: rgba(62, 224, 90, 0.14);
  --paper: #0e1013;
  --card: #1a1d23;
  --raised: #14161a;
  --line: #2c313a;
  --gold: #3ee05a;
  --danger: #ff8d86;
  --danger-soft: rgba(255, 90, 80, 0.12);
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  --sans: "Outfit", "Noto Sans SC", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

*,
*::before,
*::after { box-sizing: border-box; }

html {
  height: 100%;
  color-scheme: dark;
  scroll-behavior: smooth;
  overflow-x: clip;
}

body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}

.site-header,
.progress-wrap { flex: none; }

button,
input,
select,
textarea { font-family: inherit; font-size: 16px; color: inherit; }

::placeholder { color: #6e7680; }

button,
label,
a {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--card);
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 20;
}

.skip:focus { top: 12px; }

.site-header {
  background: var(--paper);
  color: var(--ink);
  padding: calc(10px + env(safe-area-inset-top)) 16px 8px;
  position: relative;
}

body:has(#progress-wrap.is-hidden) .site-header,
html.view-results .site-header { padding-bottom: 14px; }

.header-inner {
  width: min(760px, 100%);
  margin: 0 auto;
}

.progress-wrap {
  position: relative;
  background: var(--paper);
  color: var(--ink);
  padding: 0 16px 12px;
}

.progress-inner {
  width: min(760px, 100%);
  margin: 0 auto;
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.brand-logo {
  display: block;
  height: 40px;
  width: auto;
  max-width: min(180px, 100%);
  object-fit: contain;
}

.logo-sub {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  max-width: 100%;
}

.lang {
  display: flex;
  background: #1c1f26;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  flex: none;
}

.lang button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 8px;
  min-height: 28px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.72rem;
  line-height: 1.2;
}

.lang button[aria-pressed="true"] {
  background: var(--green);
  color: #0b0d10;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  font-size: 0.92rem;
  margin-bottom: 8px;
  min-width: 0;
}

#progress-label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-weight: 600;
}

.progress-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#progress-count { opacity: 0.85; flex: none; }

.progress {
  height: 8px;
  background: #262a32;
  border-radius: 999px;
  overflow: hidden;
}

#progress-bar {
  display: block;
  height: 100%;
  width: 0;
  background: var(--green);
  border-radius: inherit;
  transition: width 0.3s ease;
}

main {
  flex: 1 1 auto;
  min-height: 0;
  width: min(760px, calc(100% - 20px));
  margin: 0 auto;
  padding: 12px 8px 20px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.hero {
  margin: 4px 0 16px;
  padding: 18px 18px 16px;
  border-radius: 18px;
  border: 1px solid #2d4634;
  background:
    radial-gradient(420px 160px at 100% 0%, rgba(62, 224, 90, 0.28), transparent 60%),
    linear-gradient(105deg, #16321e 0%, #102418 55%, #12161c 100%);
}

.kicker {
  margin: 0 0 6px;
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--green);
  font-weight: 700;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(1.7rem, 4vw, 2.2rem);
  line-height: 1.15;
  letter-spacing: -0.03em;
}

.hero-body { margin: 0; color: var(--muted); }

.sec-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 0 14px;
  font-size: 1.35rem;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.sec-head:focus,
#page:focus,
.error-summary:focus { outline: none; }

.q-box {
  background: #22262f;
  border: 1px solid #3d4553;
  border-radius: 16px;
  padding: 14px;
  margin: 0 0 14px;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  scroll-margin-bottom: 16px;
}

.q-box.is-error {
  border-color: #ff8d86;
  box-shadow: 0 0 0 3px rgba(255, 90, 80, 0.12);
}

.q {
  display: block;
  width: 100%;
  min-inline-size: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

legend {
  display: block;
  width: 100%;
  padding: 0;
  margin: 0 0 10px;
}

.q-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.qid {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: var(--green);
  font-weight: 700;
}

.opt-pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: #262a32;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.q-title { display: block; font-size: 1.05rem; font-weight: 600; }

.hint {
  margin: 8px 0 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

.hint.at-max { color: var(--green); font-weight: 600; }

.hint-count {
  display: block;
  margin-top: 2px;
  font-weight: 600;
  color: var(--ink);
}

.hint.at-max .hint-count { color: var(--green); }

.scale-legend span:last-child { text-align: right; }

.choices { display: flex; flex-direction: column; gap: 8px; min-width: 0; width: 100%; }

.choice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--raised);
  cursor: pointer;
  min-height: 48px;
}

@media (hover: hover) and (pointer: fine) {
  .choice:hover { background: #1e2229; }
  .btn-primary:hover { background: var(--green-dark); }
}

.choice:has(input:checked) {
  background: var(--green-soft);
  border-color: rgba(62, 224, 90, 0.7);
}

.choice.is-locked { opacity: 0.48; }

.choice input {
  appearance: none;
  width: 22px;
  height: 22px;
  margin: 2px 0 0;
  border: 2px solid #6d7580;
  background: var(--paper);
  display: grid;
  place-items: center;
  flex: none;
}

.choice input[type="checkbox"] { border-radius: 6px; }

.choice input[type="radio"] { border-radius: 50%; }

.choice input[type="checkbox"]:checked {
  border-color: var(--green);
  background: var(--green) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%230b0d10' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round' d='M3 8.5 6.2 12 13 4'/%3E%3C/svg%3E") center / 14px no-repeat;
}

.choice input[type="radio"]:checked {
  border-color: var(--green);
  background: var(--paper);
  box-shadow: inset 0 0 0 5px var(--green);
}

.choice input:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.choice-copy { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }

.other-field { margin: 2px 0 4px 12px; }

.other-field input,
textarea,
.select-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--raised);
  padding: 12px;
}

textarea { min-height: 120px; resize: vertical; line-height: 1.45; }

.count {
  margin: 6px 0 0;
  text-align: right;
  color: var(--muted);
  font-size: 0.8rem;
}

.scale-legend {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.rate {
  display: grid;
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.rate:first-of-type { border-top: 0; padding-top: 0; }

.rate-name { margin: 0; font-weight: 600; }

.scale {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.scale-opt { position: relative; }

.scale-opt input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.scale-opt span {
  display: grid;
  place-items: center;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--raised);
  font-weight: 700;
}

.scale-opt input:checked + span {
  background: var(--green);
  border-color: var(--green);
  color: #0b0d10;
}

.scale-opt input:focus-visible + span {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

.rank-field {
  display: grid;
  grid-template-columns: 32px 1fr;
  column-gap: 10px;
  row-gap: 6px;
  margin-bottom: 14px;
  align-items: center;
}

.rank-field:last-child { margin-bottom: 0; }

.ord {
  grid-row: 1 / span 2;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--green);
  color: #0b0d10;
  font-weight: 700;
}

.rank-name { font-weight: 600; font-size: 0.95rem; }

.rank-field select {
  grid-column: 2;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background-color: var(--raised);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%239aa3ad' stroke-width='1.8' stroke-linecap='round' d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px;
  padding: 0 36px 0 12px;
  appearance: none;
}

.error {
  color: var(--danger);
  margin: 10px 0 0;
  font-size: 0.92rem;
}

.error-summary {
  background: var(--danger-soft);
  border: 1px solid rgba(255, 141, 134, 0.45);
  color: var(--danger);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 0 0 12px;
}

.banner {
  background: var(--green-soft);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.banner button {
  border: 0;
  background: var(--raised);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  font-weight: 600;
}

.nav {
  position: static;
  flex: none;
  z-index: 5;
  background: #1c1f26;
  color: var(--ink);
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(23, 33, 28, 0.04);
}

.nav-inner {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  display: flex;
  gap: 10px;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
}

.btn {
  min-height: 48px;
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 650;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary {
  flex: 1.4;
  background: var(--green);
  color: #0b0d10;
  border-color: var(--green);
}

.btn-ghost {
  flex: 0.8;
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.nav.is-first .btn-ghost { display: none; }
.nav.is-first .btn-primary { flex: 1; }

.btn:active { transform: translateY(1px); }

.btn:disabled { opacity: 0.6; cursor: wait; }

.is-hidden { display: none !important; }

html.view-results #nav,
html.view-results #progress-wrap { display: none !important; }

.logout {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  flex: none;
}

.gate {
  width: min(440px, 100%);
  margin: 24px auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gate h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}

.gate p { margin: 0; color: var(--muted); }

.gate label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
}

.gate input {
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--raised);
  padding: 0 12px;
}

.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  opacity: 0;
  pointer-events: none;
  background: var(--green);
  color: #0b0d10;
  padding: 10px 14px;
  border-radius: 999px;
  z-index: 30;
  max-width: calc(100% - 32px);
  text-align: center;
  transition: 0.2s ease;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.done {
  text-align: center;
  padding: 28px 8px 12px;
}

.done-mark {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--green);
  color: #0b0d10;
}

.done-mark.warn { background: var(--danger); }

.done h1 {
  font-size: clamp(1.4rem, 3vw, 1.8rem);
  line-height: 1.3;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}

.done p { color: var(--muted); margin: 0 auto; max-width: 46ch; }

.done-code {
  margin-top: 16px !important;
  color: var(--ink) !important;
  font-weight: 600;
}

.payload {
  margin-top: 16px;
  text-align: left;
}

.payload textarea { min-height: 160px; }

.section-enter { animation: rise 0.35s ease; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.noscript {
  width: min(760px, calc(100% - 32px));
  margin: 20px auto;
}

/* Results */
.dash-title {
  margin: 0 0 8px;
  font-size: clamp(1.45rem, 4vw, 2rem);
  line-height: 1.2;
  letter-spacing: -0.03em;
}

.lede { margin: 4px 0 14px; color: var(--muted); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 14px;
}

.toolbar label.field,
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}

.toolbar select,
.toolbar input[type="number"] {
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--raised);
  padding: 0 10px;
  min-width: 0;
}

.chips { display: flex; gap: 6px; flex-wrap: wrap; }

.chips button,
.btn-small {
  border: 1px solid var(--line);
  background: var(--raised);
  border-radius: 999px;
  min-height: 40px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
}

.chips button[aria-pressed="true"] {
  background: var(--green);
  border-color: var(--green);
  color: #0b0d10;
}

.note {
  margin: -4px 0 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.summary,
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.stat,
.panel,
.qcard {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.stat-k {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stat-v { margin: 0; font-weight: 650; line-height: 1.3; }

.stat-s { margin: 6px 0 0; color: var(--muted); font-size: 0.85rem; }

.panel { margin-bottom: 14px; }

.panel summary {
  cursor: pointer;
  font-weight: 700;
}

.panel-body { margin-top: 12px; }

.invite-row,
.sub-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.invite-row code,
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 0.85rem; }

.tag {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 700;
  background: #262a32;
}

.tag.ok { background: var(--green-soft); color: var(--green); }

.qcard { margin-bottom: 12px; }

.qcard h2 { margin: 0 0 4px; font-size: 1.05rem; }

.decision { margin: 0 0 4px; color: var(--green); font-weight: 600; font-size: 0.92rem; }

.method { margin: 0 0 12px; color: var(--muted); font-size: 0.85rem; }

.bar-row { margin: 0 0 10px; }

.bar-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  font-size: 0.92rem;
  margin-bottom: 4px;
}

.bar-top span { min-width: 0; overflow-wrap: anywhere; }

.bar-top strong { flex: none; }

.bar-track {
  height: 8px;
  background: #262a32;
  border-radius: 999px;
  overflow: hidden;
}

.bar-track span {
  display: block;
  height: 100%;
  background: var(--green);
  border-radius: inherit;
}

.bar-row.is-top .bar-track span { background: var(--green); }
.bar-row.is-low .bar-track span { background: #ff8d86; }

.bar-meta { color: var(--muted); font-size: 0.8rem; margin-top: 3px; }

.callout {
  background: #171b16;
  border: 1px solid #2d4634;
  border-radius: 12px;
  padding: 10px 12px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.comment {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.comment p { margin: 4px 0 0; }

.empty {
  color: var(--muted);
  margin: 8px 0;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.danger-btn {
  background: var(--raised);
  color: var(--danger);
  border: 1px solid rgba(255, 141, 134, 0.45);
  border-radius: 12px;
  min-height: 40px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 700;
}

.page-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

@media (max-width: 640px) {
  .site-header { padding-top: calc(10px + env(safe-area-inset-top)); }

  .logo-sub { white-space: normal; max-width: 100%; }

  .header-inner { flex-wrap: nowrap; align-items: center; gap: 8px; }

  .brand-logo { height: 36px; max-width: min(150px, 48vw); }

  .logo-sub { font-size: 0.72rem; }

  .lang { width: auto; }

  .lang button {
    flex: none;
    min-height: 28px;
    padding: 3px 7px;
    font-size: 0.68rem;
  }

  .progress-wrap { padding-bottom: 16px; }

  main {
    width: min(760px, calc(100% - 16px));
    padding: 12px 10px 16px;
  }

  .hero { margin-bottom: 12px; }

  .hero h1 { font-size: 1.45rem; }

  .sec-head { font-size: 1.2rem; margin-bottom: 10px; }

  .q-box { padding: 12px; }

  .choice { padding: 12px; }

  .scale { gap: 8px; }

  .scale-opt span { height: 48px; }

  .nav-inner { width: min(760px, calc(100% - 24px)); }

  body.is-typing .nav { display: none; }

  textarea,
  input[type="text"],
  select { scroll-margin-bottom: calc(28px + env(safe-area-inset-bottom)); }

  .summary,
  .split { grid-template-columns: 1fr; }

  .toolbar { align-items: stretch; }

  .chips { width: 100%; }

  .chips button {
    flex: 1;
    padding-left: 8px;
    padding-right: 8px;
  }

  .toolbar .field { flex: 1 1 calc(50% - 8px); min-width: 0; }

  .toolbar select,
  .toolbar input[type="number"] { width: 100%; }

  .toolbar .btn-small { flex: 1 1 calc(50% - 8px); text-align: center; }

  .invite-row {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .invite-row > div:last-child {
    display: flex;
    gap: 8px;
    align-items: center;
  }

  .invite-row code,
  .invite-row .bar-meta { overflow-wrap: anywhere; }

  .page-actions { display: grid; grid-template-columns: 1fr 1fr; }

  .page-actions .danger-btn { grid-column: 1 / -1; }

  .q-title,
  .choice-copy,
  .rate-name,
  .stat-v,
  .comment p { overflow-wrap: anywhere; }
}

@media (min-width: 740px) {
  .rate {
    grid-template-columns: minmax(0, 1fr) 280px;
    align-items: center;
    gap: 16px;
  }
  .scale-legend { margin-left: auto; width: 280px; }
}

@media (min-width: 900px) {
  .summary { grid-template-columns: repeat(4, 1fr); }
  .split { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .nav,
  .lang,
  .no-print,
  #toast { display: none !important; }
  .site-header { background: white; color: black; }
  .site-header::after { display: none; }
  .logo-sub { color: black; }
  body { background: white; }
  .qcard,
  .stat,
  .panel,
  .q { box-shadow: none; }
}
