/* Madhouse IQ — player phone. Mobile-first, 360px up. Team colour arrives as --team (theme.css .team-*). */
:root { --team: var(--violet); --pad: 18px; --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); }
html { height: 100%; }
[hidden] { display: none !important; }
body {
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; overflow-x: hidden;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(155, 92, 255, .22), transparent 60%),
    radial-gradient(90% 50% at 50% 110%, rgba(255, 122, 26, .14), transparent 60%),
    var(--black);
  background-attachment: fixed;
}
body.naughty { background-image: radial-gradient(120% 60% at 50% -10%, rgba(232, 37, 58, .2), transparent 60%), radial-gradient(90% 50% at 50% 110%, rgba(155, 92, 255, .14), transparent 60%); }
body.lockdown { background-image: radial-gradient(120% 60% at 50% -10%, rgba(232, 37, 58, .32), transparent 60%), radial-gradient(90% 50% at 50% 110%, rgba(232, 37, 58, .14), transparent 60%); }
/* vignette + grain, pure CSS */
body::before { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, .55) 100%); }
body > * { position: relative; z-index: 1; }

/* ---------- connection + header ---------- */
.conn { position: fixed; top: 0; left: 0; right: 0; z-index: 50; padding: calc(var(--sat) + 6px) 12px 6px; text-align: center; font-size: 13px; letter-spacing: .02em; background: var(--crimson-deep); color: var(--bone); }
.hdr { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; min-height: 48px; max-height: 56px; padding: calc(var(--sat) + 6px) var(--pad) 6px; border-bottom: 1px solid rgba(255, 255, 255, .07); background: linear-gradient(90deg, color-mix(in srgb, var(--team) 28%, var(--black)), var(--black) 75%); box-shadow: inset 6px 0 0 var(--team); }
.hdr-ico { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--team); color: var(--black); font-size: 18px; flex: none; }
.hdr-text { min-width: 0; flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hdr-team { font-family: var(--serif); font-size: 16px; line-height: 1.1; color: var(--team); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.hdr-team #hdr-team { letter-spacing: .06em; font-weight: 700; }
.hdr-team #hdr-name { color: var(--bone); }
.hdr-dot { color: var(--bone-dim); }
.hdr-sub { flex: none; }
.hdr-chip { display: inline-block; font-size: 11px; line-height: 1; padding: 6px 9px; border-radius: 999px; border: 1px solid rgba(255,255,255,.14); color: var(--bone-dim); white-space: nowrap; }
.hdr-chip:empty { display: none; }
body.lockdown .hdr { --team: var(--crimson); }
body.lockdown .hdr-chip { border-color: var(--crimson); color: var(--bone); }

/* ---------- main column ---------- */
.main { flex: 1; display: flex; flex-direction: column; gap: 16px; padding: var(--pad) var(--pad) calc(var(--sab) + 24px); max-width: 560px; width: 100%; margin: 0 auto; }
.main.center { justify-content: center; align-items: center; text-align: center; }
.main > .grow { flex: 1; }
.main .actions { margin-top: auto; display: flex; flex-direction: column; gap: 12px; padding-top: 8px; }
h1 { font-size: 34px; line-height: 1.05; }
h2 { font-size: 24px; line-height: 1.1; }
.muted { color: var(--bone-dim); }
.small { font-size: 14px; }
.lead { font-size: 18px; line-height: 1.35; max-width: 32ch; }
.tag { display: inline-block; align-self: flex-start; font-size: 12px; letter-spacing: .08em; padding: 4px 10px; border-radius: 999px; border: 1px solid rgba(255, 255, 255, .15); color: var(--bone-dim); }

/* ---------- join form ---------- */
.brand { font-family: var(--serif); font-size: 42px; line-height: .95; letter-spacing: -.02em; }
.brand em { display: block; font-style: normal; font-size: 15px; letter-spacing: .14em; color: var(--orange); font-family: var(--sans); font-weight: 600; margin-top: 10px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field label { font-size: 14px; color: var(--bone-dim); }
.field input { min-height: 60px; padding: 0 18px; border-radius: var(--radius); background: var(--ink); border: 1px solid rgba(255, 255, 255, .12); font-size: 20px; width: 100%; }
.field input::placeholder { color: rgba(185, 173, 156, .55); }
.seg { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.seg button { min-height: 60px; border-radius: var(--radius); background: var(--ink); border: 1px solid rgba(255, 255, 255, .12); font-size: 16px; font-weight: 600; padding: 0 6px; }
.seg button[aria-pressed="true"] { background: var(--violet-deep); border-color: var(--violet); box-shadow: 0 0 0 1px var(--violet), 0 0 24px rgba(155, 92, 255, .45); }
.btn-big { min-height: 64px; font-size: 19px; width: 100%; }

/* ---------- spectrum card ---------- */
.card { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; padding: 16px; border-radius: var(--radius); background: var(--ink); border: 1px solid rgba(255, 255, 255, .08); font-family: var(--serif); font-size: 20px; line-height: 1.15; }
.card .l { text-align: left; } .card .r { text-align: right; }
.card .arrow { width: 36px; height: 2px; background: linear-gradient(90deg, var(--violet), var(--orange)); position: relative; }
.card .arrow::before, .card .arrow::after { content: ""; position: absolute; top: -3px; width: 8px; height: 8px; border-radius: 50%; }
.card .arrow::before { left: -4px; background: var(--violet); } .card .arrow::after { right: -4px; background: var(--orange); }
.clue { font-family: var(--serif); font-style: italic; font-size: 34px; line-height: 1.1; text-align: center; padding: 10px 4px; overflow-wrap: anywhere; }
.clue::before { content: "“"; color: var(--orange); } .clue::after { content: "”"; color: var(--orange); }

/* ---------- patient ---------- */
.danger { padding: 18px 14px; text-align: center; font-weight: 900; font-size: 24px; letter-spacing: .06em; color: #fff; border-radius: var(--radius);
  background: repeating-linear-gradient(135deg, var(--crimson) 0 14px, var(--crimson-deep) 14px 28px); box-shadow: 0 0 40px rgba(232, 37, 58, .45); text-shadow: 0 2px 0 rgba(0, 0, 0, .4); }
.bar { position: relative; height: 18px; border-radius: 999px; background: linear-gradient(90deg, var(--violet-deep), var(--ink-2) 50%, var(--orange-deep)); border: 1px solid rgba(255, 255, 255, .1); }
.bar .pin { position: absolute; top: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 50%; background: var(--bone); box-shadow: 0 0 0 4px var(--black), 0 0 22px rgba(239, 230, 216, .6); }
.bar .pin.team { background: var(--team); box-shadow: 0 0 0 4px var(--black), 0 0 22px var(--team); }
.bar .pin.small { width: 14px; height: 14px; margin: -7px 0 0 -7px; }
.target { display: flex; align-items: baseline; gap: 14px; justify-content: center; }
.target .n { font-family: var(--serif); font-size: 72px; line-height: 1; font-variant-numeric: tabular-nums; }
.target .hint { font-size: 17px; color: var(--bone-dim); font-style: italic; font-family: var(--serif); }
.rules { font-size: 14px; line-height: 1.5; color: var(--bone-dim); padding: 12px 14px; border-left: 3px solid var(--crimson); background: rgba(232, 37, 58, .08); border-radius: 0 10px 10px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips span { font-family: var(--serif); font-style: italic; font-size: 16px; padding: 8px 14px; border-radius: 999px; background: var(--ink-2); border: 1px solid rgba(255, 255, 255, .1); }
.mime { font-family: var(--serif); font-size: 30px; line-height: 1.1; text-align: center; color: var(--orange); padding: 18px; border: 2px dashed var(--orange-deep); border-radius: var(--radius); }

/* ---------- dial ---------- */
.dial-value { font-family: var(--serif); font-size: 104px; line-height: 1; text-align: center; font-variant-numeric: tabular-nums; letter-spacing: -.03em; color: var(--team); text-shadow: 0 0 40px color-mix(in srgb, var(--team) 50%, transparent); transition: color .2s; }
.dial-labels { display: flex; justify-content: space-between; gap: 12px; font-family: var(--serif); font-size: 17px; line-height: 1.15; }
.dial-labels .r { text-align: right; }
.dial { position: relative; height: 72px; border-radius: 36px; background: var(--ink); border: 1px solid rgba(255, 255, 255, .1); box-shadow: inset 0 4px 18px rgba(0, 0, 0, .7); touch-action: none; user-select: none; -webkit-user-select: none; }
.dial::before { content: ""; position: absolute; left: 36px; right: 36px; top: 50%; height: 2px; margin-top: -1px; background: repeating-linear-gradient(90deg, rgba(239, 230, 216, .35) 0 2px, transparent 2px 10%); }
.dial input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.dial .thumb { position: absolute; top: 50%; left: 36px; width: 60px; height: 60px; margin: -30px 0 0 -30px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff8, transparent 45%), var(--team); box-shadow: 0 0 0 3px var(--black), 0 0 28px color-mix(in srgb, var(--team) 70%, transparent), 0 6px 14px rgba(0, 0, 0, .6); will-change: left; }
.dial .thumb::after { content: ""; position: absolute; inset: 22px; border-radius: 50%; background: var(--black); opacity: .45; }
.dial.locked { opacity: .55; } .dial.locked .thumb { box-shadow: 0 0 0 3px var(--black); }
.dial:focus-within { outline: 3px solid var(--orange); outline-offset: 4px; }
.hint-move { text-align: center; color: var(--bone-dim); font-size: 15px; min-height: 1.4em; }
.btn-lock { min-height: 76px; font-size: 24px; font-weight: 800; letter-spacing: .06em; width: 100%; background: linear-gradient(180deg, var(--team), color-mix(in srgb, var(--team) 65%, black)); color: var(--black); border: 0; box-shadow: 0 10px 30px color-mix(in srgb, var(--team) 35%, transparent); }
.btn-lock[disabled] { opacity: 1; filter: none; background: var(--ink-2); color: var(--bone); box-shadow: none; }
.timer { font-family: var(--serif); font-size: 40px; line-height: 1; font-variant-numeric: tabular-nums; text-align: center; }
.timer.paused { color: var(--bone-dim); font-size: 26px; letter-spacing: .1em; }
.counts { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.counts span { font-size: 13px; padding: 6px 10px; border-radius: 999px; background: var(--ink); border: 1px solid rgba(255, 255, 255, .08); color: var(--bone-dim); }
.counts span b { color: var(--bone); font-weight: 600; }

/* last 10 s: edges pulse red */
body.urgent::after { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 40; box-shadow: inset 0 0 70px 10px rgba(232, 37, 58, .75); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .15; } 50% { opacity: 1; } }
body.urgent .timer { color: var(--crimson); }

/* ---------- sabotage ---------- */
.teamrow { display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 10px 14px; border-radius: var(--radius); background: var(--ink); border: 1px solid rgba(255, 255, 255, .08); text-align: left; }
.teamrow .ico { font-size: 22px; color: var(--team); }
.teamrow .nm { font-family: var(--serif); font-size: 18px; color: var(--team); }
.teamrow .bar { height: 8px; margin-top: 6px; }
.teamrow .bar .pin { width: 14px; height: 14px; margin: -7px 0 0 -7px; }
.teamrow .avg { font-family: var(--serif); font-size: 26px; font-variant-numeric: tabular-nums; min-width: 2.2ch; text-align: right; }
.teamrow .avg.none { font-family: var(--sans); font-size: 11px; letter-spacing: .08em; color: var(--bone-dim); }
.teamrow.mine { opacity: .55; }
button.teamrow[aria-pressed="true"] { border-color: var(--team); box-shadow: 0 0 0 1px var(--team), 0 0 26px color-mix(in srgb, var(--team) 45%, transparent); background: color-mix(in srgb, var(--team) 14%, var(--ink)); }
.lr { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.lr .btn { min-height: 68px; font-size: 20px; }

/* ---------- reveal / scoreboard ---------- */
.result { padding: 18px; border-radius: var(--radius); background: var(--ink); border: 1px solid rgba(255, 255, 255, .08); display: grid; gap: 12px; }
.result .headline { font-family: var(--serif); font-size: 30px; line-height: 1.05; }
.result .pts { font-family: var(--serif); font-size: 64px; line-height: 1; color: var(--team); font-variant-numeric: tabular-nums; }
.result .pts small { font-size: 18px; color: var(--bone-dim); font-family: var(--sans); margin-left: 6px; }
.bull { display: inline-block; font-weight: 900; letter-spacing: .1em; color: var(--black); background: var(--orange); padding: 6px 12px; border-radius: 6px; font-size: 14px; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; color: var(--bone-dim); }
.kv b { color: var(--bone); font-weight: 600; font-variant-numeric: tabular-nums; }
.ranks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ranks li { display: grid; grid-template-columns: 2ch 1fr auto; gap: 10px; align-items: center; padding: 8px 12px; border-radius: 10px; background: rgba(255, 255, 255, .03); font-size: 15px; }
.ranks li .nm { color: var(--team); font-family: var(--serif); font-size: 17px; }
.ranks li.mine { background: color-mix(in srgb, var(--team) 14%, transparent); }
.ranks li b { font-variant-numeric: tabular-nums; }
.sane { padding: 22px; text-align: center; border-radius: var(--radius); background: linear-gradient(180deg, var(--orange), var(--orange-deep)); color: var(--black); }
.sane .t { font-weight: 900; letter-spacing: .12em; font-size: 14px; }
.sane .n { font-family: var(--serif); font-size: 32px; margin-top: 6px; }

/* ---------- team reveal overlay ---------- */
.reveal { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; background: var(--team); color: var(--black); padding: 24px; animation: rv-in .5s ease-out; }
.reveal .ico { font-size: 140px; display: block; animation: rv-pop .7s cubic-bezier(.2, 1.4, .4, 1); }
.reveal .youre { font-size: 18px; letter-spacing: .14em; margin-top: 18px; opacity: .8; }
.reveal .who { font-family: var(--serif); font-size: 60px; line-height: 1; letter-spacing: -.02em; }
.reveal.out { animation: rv-out .5s ease-in forwards; }
@keyframes rv-in { from { opacity: 0; } }
@keyframes rv-pop { from { transform: scale(.4); opacity: 0; } }
@keyframes rv-out { to { opacity: 0; transform: scale(1.04); } }
.patient-you { padding: 26px 18px; text-align: center; border-radius: var(--radius); background: var(--team); color: var(--black); }
.patient-you .t { font-size: 15px; letter-spacing: .12em; } .patient-you .n { font-family: var(--serif); font-size: 44px; line-height: 1; margin-top: 6px; }

/* ---------- Create Your Own Madness ---------- */
.pill { position: fixed; top: calc(var(--sat) + 12px); right: 12px; z-index: 45; display: inline-flex; align-items: center; gap: 7px; min-height: 44px; padding: 0 14px; border-radius: 999px; background: var(--ink-2); border: 1px solid rgba(255, 255, 255, .16); color: var(--bone); font-size: 13px; font-weight: 600; white-space: nowrap; box-shadow: var(--shadow); }
.pill::before { content: ""; position: absolute; inset: -6px; } /* 56px hit area on a 44px chip */
.pill .ico { color: var(--orange); font-size: 16px; }
.pill.full { color: var(--bone-dim); } .pill.full .ico { color: var(--bone-dim); }
#pill:not([hidden]) ~ .hdr { padding-right: 170px; }
body.sheet-open { overflow: hidden; }
.sheet { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; justify-content: flex-end; }
.sheet-back { position: absolute; inset: 0; background: rgba(5, 2, 10, .72); animation: rv-in .2s; }
.sheet-panel { position: relative; max-height: 92vh; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 14px; padding: 10px var(--pad) calc(var(--sab) + 24px); background: var(--ink); border-radius: 22px 22px 0 0; border-top: 1px solid rgba(255, 255, 255, .12); box-shadow: 0 -20px 60px rgba(0, 0, 0, .6); animation: sheet-up .3s cubic-bezier(.2, .9, .3, 1); }
.sheet-panel:focus { outline: none; }
.sheet-panel::before { content: ""; flex: none; width: 40px; height: 4px; border-radius: 2px; margin: 0 auto 2px; background: rgba(255, 255, 255, .25); }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-head h2 { font-size: 24px; }
.sheet-x { flex: none; width: 56px; height: 56px; margin-right: -14px; border-radius: 50%; font-size: 32px; line-height: 1; color: var(--bone-dim); }
.sub-sample { margin: -8px 0 0; font-family: var(--serif); font-style: italic; font-size: 16px; color: var(--orange); }
.sheet-panel form { display: flex; flex-direction: column; gap: 14px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; padding: 0 14px; border-radius: var(--radius); background: var(--ink-2); border: 1px solid rgba(255, 255, 255, .1); font-size: 16px; font-weight: 600; text-align: left; }
.switch .knob { position: relative; flex: none; width: 46px; height: 28px; border-radius: 999px; background: rgba(255, 255, 255, .15); transition: background .2s; }
.switch .knob::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--bone); transition: transform .2s; }
.switch[aria-checked="true"] .knob { background: var(--violet); } .switch[aria-checked="true"] .knob::after { transform: translateX(18px); }
.sub-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sub-foot .btn { flex: 1; max-width: 62%; min-height: 60px; font-size: 18px; }
.sub-h { font-size: 18px; margin-top: 4px; }
.sub-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.sub-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 10px; background: rgba(255, 255, 255, .04); }
.sub-list .sub-txt { font-family: var(--serif); font-size: 15px; line-height: 1.2; overflow-wrap: anywhere; } .sub-list i { color: var(--orange); font-style: normal; }
.chip { flex: none; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; padding: 4px 8px; border-radius: 999px; border: 1px solid currentColor; color: var(--bone-dim); }
.chip.approved { color: var(--green); } .chip.rejected { color: var(--crimson); } .chip.played { color: var(--orange); }
.sub-done { display: grid; gap: 14px; padding: 6px 0; }
.sub-done .big { font-family: var(--serif); font-size: 36px; line-height: 1.02; letter-spacing: -.01em; }
.sub-done .lr .btn { min-height: 60px; font-size: 17px; }
.shake { animation: shake .35s; border-color: var(--crimson) !important; }
@keyframes shake { 0%, 100% { transform: none; } 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.ribbon { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: -8px; font-size: 12px; letter-spacing: .12em; font-weight: 800; color: var(--orange); }
.ribbon span { font-family: var(--serif); font-style: italic; font-weight: 400; letter-spacing: 0; font-size: 14px; color: var(--bone-dim); }

/* cheeky one-liners */
.quip { font-family: var(--serif); font-style: italic; font-size: 16px; line-height: 1.3; color: var(--orange); }
.reveal .line { margin-top: 16px; font-size: 18px; color: var(--bone); background: rgba(0, 0, 0, .55); padding: 8px 16px; border-radius: 999px; } /* dark pill: readable on the bone-coloured Ghosts too */
.sane .line { margin-top: 8px; font-family: var(--serif); font-style: italic; font-size: 16px; }

/* amendment 4: compact header, keep dial + LOCK above the fold on 360x640 */
#pill { top: calc(var(--sat, 0px) + 56px); }
@media (max-height: 720px) {
  .clue { font-size: 26px; padding: 4px; }
  .timer { font-size: 32px; }
  .dial-value { font-size: 64px; }
  .main { gap: 10px; }
  .main > .grow { display: none; }
  .dial-labels { font-size: 15px; }
}

/* header: the name wins the space, the round chip yields; pill is icon-only on phones */
.hdr-team { flex: 1 1 auto; min-width: 45%; }
.hdr-sub { flex: 0 1 auto; min-width: 0; }
.hdr-chip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 480px) {
  #pill { width: 44px; min-width: 44px; padding: 0; justify-content: center; font-size: 0; gap: 0; }
  #pill .ico { font-size: 18px; }
}
