/* Phone controller — big targets, RTL, works one-handed. */
/* One screen, no scrolling: the page is exactly as tall as the visible area and join.js (fit) shrinks a screen that would not fit. */
html, body { height: 100dvh; }
body { min-height: 0; display: flex; flex-direction: column; font-size: 18px; transition: background-color .3s; }
body.catbg { background-color: var(--cat); }
header#top { display: flex; align-items: center; gap: 10px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); min-height: 60px; }
#me { display: flex; align-items: center; gap: 8px; font-family: var(--display); font-size: 1.3rem; margin-inline-end: auto; min-width: 0; }
#me span { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; line-height: 1.15; } /* long names: two lines at most */
#me .ring { flex: none; }
#me .ring { width: 44px; height: 44px; border-width: 3px; }
#score { font-family: var(--display); font-size: 1.2rem; background: var(--ink); color: #fff; padding: 2px 12px; border-radius: 10px; }
#score:empty { display: none; }
#leave { min-height: 44px; padding: 0 10px; }
main#screen { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 8px 16px 0; gap: 16px; max-width: 520px; width: 100%; margin: 0 auto; }

h1, h2 { font-family: var(--display); margin: 0; line-height: 1.15; }
h1 { font-size: 2.6rem; } h2 { font-size: 2rem; }
.muted { color: var(--ink-soft); line-height: 1.6; }
.center { text-align: center; align-items: center; justify-content: center; }
.grow { flex: 1; display: flex; flex-direction: column; gap: 16px; }
.btn.block { width: 100%; font-size: 1.6rem; min-height: 64px; }

label.f { display: flex; flex-direction: column; gap: 6px; font-weight: 700; }
input.inp {
  font-family: var(--display); font-size: 1.8rem; padding: 10px 14px; border: 3px solid var(--ink); border-radius: 12px;
  background: #fff; color: var(--ink); width: 100%; box-shadow: var(--shadow); outline: none;
}
input.inp.code { letter-spacing: 12px; text-align: center; direction: ltr; font-size: 2.4rem; }
input.inp:focus { border-color: var(--purple); }

.avgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; max-width: 400px; margin: 0 auto; width: 100%; }
.avgrid button { aspect-ratio: 1; padding: 0; border: 0; background: none; cursor: pointer; }
.avgrid .ring { width: 100%; height: 100%; border-width: 4px; transition: transform .15s; }
.avgrid button.sel .ring { border-color: var(--cat); transform: scale(1.08) rotate(-4deg); box-shadow: 0 0 0 5px var(--cat); }
.avgrid button[disabled] { opacity: .25; filter: grayscale(1); }

.bigme { width: 180px; height: 180px; margin: 10px auto 0; border-width: 7px; animation: pop .5s both; }

/* sealed envelope / task card — identical shell for everyone */
.envelope {
  position: relative; min-height: 280px; border: 4px solid var(--ink); border-radius: 18px; background: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 22px;
  width: 100%; color: var(--ink); cursor: pointer; box-shadow: 6px 8px 0 rgba(0, 0, 0, .2); user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.envelope .cover { position: absolute; inset: 0; border-radius: 14px; background: var(--paper-2); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; font-family: var(--display); font-size: 1.5rem; transition: opacity .12s; }
.envelope .cover svg { width: 110px; }
.envelope.open .cover { opacity: 0; }
.envelope .body { font-family: var(--display); font-size: 1.9rem; line-height: 1.35; min-height: 7.2em; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.envelope .body small { font-family: var(--body); font-size: 1rem; color: var(--ink-soft); }
.envelope .body .fk { width: 90px; margin: 0 auto; }
.face-ref { display: block; max-width: 100%; max-height: 38vh; margin: 6px auto; border: 3px solid var(--ink); border-radius: 12px; }

.lookup { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: #fff; font-family: var(--display); font-size: 2.6rem; gap: 10px; }
.lookup .big { font-size: 5rem; line-height: 1; }
.lookup .cmd { font-size: 3.4rem; line-height: 1.15; padding: 0 12px; }

.vlist { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.vbtn { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px 12px; background: #fff; border: 3px solid var(--ink); border-radius: 16px; box-shadow: var(--shadow); cursor: pointer; font-family: var(--display); font-size: 1.35rem; color: var(--ink); }
.vbtn .ring { width: 74px; height: 74px; border-width: 4px; }
.vbtn.sel { background: var(--ink); color: #fff; transform: rotate(-2deg) scale(1.03); }
.vbtn.cleared { opacity: .45; }
.vbtn[disabled] { cursor: default; box-shadow: none; }
.rule-note { margin: 0; padding: 12px 14px; border-inline-start: 4px solid var(--cat); border-radius: 8px; background: var(--paper-2); color: var(--ink); font-size: 1rem; line-height: 1.65; }
.prompt-card { padding: 16px; background: #fff; color: var(--ink); border: 3px solid var(--ink); border-radius: 14px; font-family: var(--display); font-size: 1.7rem; line-height: 1.45; overflow-wrap: anywhere; }
.prompt-card small { display: block; margin-top: 8px; font-family: var(--body); font-size: 1rem; }
.lookup-hint { font-family: var(--body); font-size: 1.1rem; font-weight: 700; }
button:focus-visible { outline: 3px solid var(--purple); outline-offset: 4px; }
.envelope.open:focus-visible { outline-color: var(--ink); }
.vbtn .ans { font-family: var(--body); font-size: .95rem; color: inherit; opacity: .85; }
.vbtn .who { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
/* 5+ candidates: three small cards per row so the whole table fits one screen */
.vlist.dense { grid-template-columns: repeat(3, 1fr); gap: 10px; }
.vlist.dense .vbtn { padding: 8px 4px; font-size: 1.05rem; line-height: 1.15; }
.vlist.dense .vbtn .ring { width: 52px; height: 52px; border-width: 3px; }
/* final round: one row per player, the answer beside the face */
.vlist.final { grid-template-columns: 1fr; gap: 10px; }
.vlist.final .vbtn { flex-direction: row; gap: 12px; padding: 8px 12px; text-align: start; }
.vlist.final .vbtn .ring { width: 56px; height: 56px; border-width: 3px; flex: none; }
.vlist.final .vbtn .who { align-items: flex-start; flex: 1; }

.catlist { display: flex; flex-direction: column; gap: 12px; }
.catbtn { display: flex; align-items: center; gap: 14px; padding: 10px 14px; border: 4px solid var(--ink); border-radius: 16px; background: var(--c); color: #fff; font-family: var(--display); font-size: 1.8rem; box-shadow: var(--shadow); cursor: pointer; }
.catbtn .ring { width: 64px; height: 64px; border-width: 3px; }

.fw { display: flex; flex-direction: column; gap: 6px; }
.fw .q { font-family: var(--display); font-size: 1.35rem; line-height: 1.3; }
.fw input { font-size: 1.4rem; }
.counter { font-size: .85rem; color: var(--ink-soft); text-align: left; direction: ltr; }

.settings { display: flex; flex-direction: column; gap: 10px; background: #fff; border: 3px dashed var(--line); border-radius: 14px; padding: 12px 14px; }
.settings label { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 600; min-height: 44px; }
.settings select { max-width: 55%; min-height: 44px; font-family: inherit; font-size: 1.05rem; padding: 6px 8px; border-radius: 8px; border: 2px solid var(--ink); background: #fff; }
.settings input[type=checkbox] { width: 32px; height: 32px; accent-color: var(--ink); }
details.rule-note summary { font-weight: 700; cursor: pointer; min-height: 32px; }
label.f small { font-weight: 400; font-size: .9rem; }
main#screen:focus { outline: none; } /* focused on every screen change so screen readers announce it */
#start[disabled] { filter: grayscale(1); background: var(--line); }

.gain { font-family: var(--display); font-size: 3.4rem; text-align: center; animation: pop .5s both; }
/* countdown pill */
#clock { flex: none; align-self: center; direction: ltr; font-family: var(--display); font-size: 1.35rem; line-height: 1.5; padding: 0 16px; background: #fff; color: var(--ink); border: 3px solid var(--ink); border-radius: 999px; box-shadow: 3px 4px 0 var(--ink); }
#clock.hot { background: var(--red); color: #fff; }
#toast { position: fixed; bottom: 22px; left: 16px; right: 16px; background: var(--ink); color: #fff; padding: 14px 16px; border-radius: 12px; text-align: center; font-weight: 700; z-index: 10; animation: rise .25s both; }
body.catbg .muted, body.catbg h1, body.catbg h2 { color: #fff; }
body.catbg #me, body.catbg #prefs-btn, body.catbg #host-menu { color: #fff; }
/* lettering on or in a category colour gets the comic ink outline: mustard, orange and green fail contrast without it */
.lookup, .lookup > *, body.catbg h1, body.catbg h2, body.catbg #me span, .catbtn, .cattitle { -webkit-text-stroke: .13em var(--ink); paint-order: stroke fill; }
.cattitle { color: var(--cat); }
#host-bar { display: flex; gap: 8px; padding: 0 16px 8px; max-width: 520px; margin: 0 auto; width: 100%; }
#host-bar .btn { flex: 1; font-size: 1rem; min-height: 44px; padding: 0 8px; }
#host-menu { min-height: 44px; padding: 0 10px; font-size: 1.3rem; color: var(--mustard); }
#conn { background: var(--red); color: #fff; text-align: center; font-weight: 700; padding: 6px; }
input.inp.code { text-transform: uppercase; letter-spacing: 14px; }
.pauseinfo { background: var(--ink); color: #fff; border-radius: 12px; padding: 10px 14px; text-align: center; font-weight: 700; }

/* category icons (Shared/art/cast/icons) */
.catbtn .iconbox { width: 64px; height: 64px; flex: none; border: 3px solid var(--ink); border-radius: 14px; overflow: hidden; background: #fff; }
.catbtn .iconbox img.caticon { width: 100%; height: 100%; object-fit: cover; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* host: offline lobby seats that can be removed */
.settings[hidden] { display: none; }
.awayrow { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.awayrow .ring { width: 44px; height: 44px; flex: none; }
.awayrow span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.awayrow .btn { padding: 6px 12px; font-size: .95rem; }

/* comic panel slide-in on every screen change (join.js render) */
html, body { overflow-x: clip; } /* the slide-in must not cause sideways scroll */
main#screen.turn { animation: phoneTurn .42s cubic-bezier(.2, 1.3, .4, 1); }
@keyframes phoneTurn { 0% { transform: translateX(-60%) rotate(-6deg) scale(.86); opacity: 0; } 60% { opacity: 1; } 100% { transform: none; } }
@media (prefers-reduced-motion: reduce) { main#screen.turn { animation: none; } }

/* settings sheet (⚙) */
#prefs-btn { min-height: 44px; min-width: 44px; padding: 0 8px; font-size: 1.4rem; }
#prefs { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; background: rgba(27, 23, 20, .5); }
#prefs.hidden { display: none; }
#prefs .sheet { width: 100%; max-width: 520px; background: #fffaf0; border: 4px solid var(--ink); border-bottom: 0; border-radius: 16px 16px 0 0; padding: 18px 18px max(18px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; animation: rise .25s both; }
#prefs h3 { font-family: var(--display); font-size: 1.4rem; margin: 6px 0 0; }
#prefs .muted { margin: 0; font-size: .95rem; }
.pref-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 700; min-height: 44px; }
.pref-toggle input { width: 28px; height: 28px; accent-color: var(--ink); }
.pref-slider { display: grid; grid-template-columns: 6.5em 1fr 2.6em; align-items: center; gap: 10px; font-weight: 700; }
.pref-slider input { width: 100%; height: 36px; accent-color: var(--red); direction: ltr; }
.pref-slider output { font-family: var(--display); text-align: center; background: var(--comic-yellow); border: 3px solid var(--ink); border-radius: 6px; }
#pr-host[hidden] { display: none; }
#pr-host { display: flex; flex-direction: column; gap: 12px; }
#pr-host.muted .pref-slider { opacity: .4; }

/* lobby: everything on one small screen (no big avatar: the header already shows it) */
/* bottom breathing room as a real flex item: padding does not count as overflow, so fit() could not see it being eaten */
main#screen::after { content: ""; flex: none; height: max(4px, calc(env(safe-area-inset-bottom) - 16px)); }
.lobby-top { flex: 0 1 auto; gap: 4px; }
.lobby-top .muted { margin: 0; }
main#screen .avgrid { max-width: 300px; gap: 10px; }
.host-settings { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; padding: 8px 12px; }
.host-settings label { font-size: .95rem; }
.host-settings select { max-width: none; flex: 1; min-width: 0; }
.host-settings small { grid-column: 1 / -1; }

/* one-screen budget: the tall screens are built tight so fit() rarely has to shrink them much */
.bigme { width: clamp(84px, 20dvh, 180px); height: clamp(84px, 20dvh, 180px); }
.tight { margin: 0; font-size: .92rem; line-height: 1.45; }
#vote-status { padding: 6px 12px; font-size: .92rem; line-height: 1.45; }
.vlist.final { gap: 6px; }
.vlist.final .vbtn { padding: 4px 10px; gap: 10px; font-size: 1.1rem; line-height: 1.2; }
.vlist.final .vbtn .ring { width: 38px; height: 38px; border-width: 2px; }
.vlist.final .vbtn .ans { font-size: .85rem; line-height: 1.25; }
.fw { position: relative; gap: 2px; }
.fw .q { font-size: 1.1rem; line-height: 1.25; }
.fw input.inp { font-size: 1.15rem; padding: 6px 12px; padding-inline-end: 3.4em; }
.fw .counter { position: absolute; left: 10px; bottom: 9px; }
