:root {
	--bg: #0a0e1f;
	--bg2: #141a2f;
	--ink: #e8eef8;
	--muted: #7a8aa6;
	--accent: #ffa940;
	--werewolf: #c0392b;
	--village: #27ae60;
	--tanner: #9b59b6;
	--line: rgba(255, 255, 255, 0.08);
	--card: rgba(255, 255, 255, 0.04);
	--radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
	background: radial-gradient(120% 80% at 50% -10%, #1a2348 0%, var(--bg) 55%) fixed;
	color: var(--ink);
	font: 16px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
	min-height: 100dvh;
	overflow-x: hidden;
	transition: background 0.8s ease;
}
body.night-mode { background: radial-gradient(120% 80% at 50% -10%, #0b1024 0%, #05060f 60%) fixed; }

/* starry sky */
.sky {
	position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: 0.5;
	background-image:
		radial-gradient(1px 1px at 20% 30%, #fff, transparent),
		radial-gradient(1px 1px at 70% 60%, #fff, transparent),
		radial-gradient(1px 1px at 40% 80%, #cdd6ff, transparent),
		radial-gradient(1.5px 1.5px at 85% 25%, #fff, transparent),
		radial-gradient(1px 1px at 55% 15%, #fff, transparent),
		radial-gradient(1px 1px at 10% 70%, #cdd6ff, transparent);
	animation: twinkle 6s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: 0.3; } to { opacity: 0.65; } }

#app { max-width: 560px; margin: 0 auto; padding: 18px 16px calc(40px + env(safe-area-inset-bottom)); }
.screen { display: flex; flex-direction: column; gap: 14px; animation: fadein 0.4s ease; }
.center { align-items: center; text-align: center; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

h1 { font-size: 22px; margin: 6px 0; }
.hd h1 { margin: 0; }
.sub { color: var(--muted); margin: 2px 0; font-size: 14px; }
.dim { color: var(--muted); }

/* landing */
.hero { text-align: center; margin: 18px 0 8px; }
.moon { font-size: 56px; filter: drop-shadow(0 0 24px rgba(255, 200, 120, 0.4)); animation: float 5s ease-in-out infinite; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.logo { font-size: 26px; line-height: 1.2; margin: 10px 0 4px; }
.tag { color: var(--muted); font-style: italic; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; width: 100%; }
.lbl { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 8px 0 4px; }
.inp {
	width: 100%; padding: 14px; font-size: 17px; color: var(--ink);
	background: rgba(0, 0, 0, 0.25); border: 1px solid var(--line); border-radius: 12px; outline: none;
}
.inp:focus { border-color: var(--accent); }
.code-inp { text-align: center; letter-spacing: 0.4em; font-size: 28px; font-weight: 700; text-transform: uppercase; }
.or { text-align: center; color: var(--muted); margin: 12px 0; font-size: 13px; }
.foot { text-align: center; color: var(--muted); font-size: 13px; margin-top: 18px; }

/* buttons */
.btn {
	display: inline-flex; align-items: center; justify-content: center; gap: 8px;
	padding: 13px 16px; min-height: 48px; font-size: 16px; font-weight: 600;
	color: #1a1206; background: linear-gradient(180deg, #ffc06b, var(--accent) 55%, #f08c1f);
	border: none; border-radius: 12px; cursor: pointer;
	box-shadow: 0 4px 16px rgba(255, 169, 64, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.35);
	transition: transform 0.08s ease, opacity 0.2s; width: 100%;
}
.btn.ready-on {
	background: linear-gradient(180deg, #4cd784, var(--village) 55%, #1d8c4c);
	color: #04210f;
	box-shadow: 0 4px 18px rgba(39, 174, 96, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.4; pointer-events: none; }
.btn.big { font-size: 18px; padding: 16px; margin-top: 6px; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); box-shadow: none; }
.btn.tiny { width: auto; min-height: 36px; padding: 8px 14px; font-size: 14px; }
.row { display: flex; }
.row.gap { gap: 10px; }
.row .btn { flex: 1; }

.leave { background: none; border: none; color: var(--muted); text-decoration: underline; cursor: pointer; margin-top: 18px; align-self: center; padding: 8px; }

/* lobby */
.codebox { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 6px 0; }
.code-big { font-size: 44px; font-weight: 800; letter-spacing: 0.18em; color: var(--accent); text-shadow: 0 0 20px rgba(255, 169, 64, 0.35); }
.plist { display: flex; flex-direction: column; gap: 8px; }
.prow { display: flex; justify-content: space-between; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.prow.off { opacity: 0.45; }
.pname { font-weight: 600; }
.youtag { color: var(--accent); font-weight: 400; font-size: 13px; }
.pmeta { display: flex; align-items: center; gap: 8px; }
.host { font-size: 14px; }
.kick { background: rgba(192, 57, 43, 0.2); color: #ff8a7a; border: none; width: 28px; height: 28px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.wait { color: var(--muted); text-align: center; font-style: italic; }

/* role select */
.tally { text-align: center; font-weight: 700; font-size: 18px; color: var(--muted); padding: 6px; }
.tally.ok { color: var(--village); }
.rolegrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chip {
	position: relative; text-align: left; background: var(--card); border: 1.5px solid var(--line);
	border-radius: 14px; padding: 12px; cursor: pointer; color: var(--ink); display: flex; flex-direction: column; gap: 3px;
	transition: border-color 0.15s, background 0.15s, transform 0.08s;
}
.chip:active { transform: scale(0.97); }
.chip.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent); }
.chip-emoji { font-size: 26px; }
.chip-name { font-weight: 700; font-size: 15px; }
.chip-short { font-size: 11px; color: var(--muted); line-height: 1.25; }
.chip-badge { position: absolute; top: 8px; right: 8px; background: var(--c); color: #0a0e1f; font-weight: 800; font-size: 12px; padding: 1px 8px; border-radius: 20px; }
.warn { background: rgba(192, 57, 43, 0.14); border: 1px solid rgba(192, 57, 43, 0.4); color: #ffb3a8; border-radius: 12px; padding: 10px 12px; font-size: 14px; text-align: center; }
.chiprow, .chiprow { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.minichip { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 5px 10px; font-size: 13px; }
.big-emoji { font-size: 48px; }

/* role reveal / cards */
.flipcard {
	position: relative; overflow: hidden;
	background:
		radial-gradient(120% 90% at 50% -20%, color-mix(in srgb, var(--c, #2a3354) 38%, transparent), transparent 60%),
		linear-gradient(160deg, color-mix(in srgb, var(--c, #2a3354) 30%, var(--bg2)), var(--bg2));
	border: 2px solid var(--c, var(--line)); border-radius: 20px; padding: 32px 26px; width: 100%; max-width: 340px;
	box-shadow: 0 0 36px color-mix(in srgb, var(--c, #2a3354) 35%, transparent), 0 12px 40px rgba(0, 0, 0, 0.45);
}
.flipcard::after {
	content: ''; position: absolute; inset: 6px; border-radius: 14px; pointer-events: none;
	border: 1px solid color-mix(in srgb, var(--c, var(--line)) 45%, transparent);
}
.reveal-anim { animation: flipin 0.7s cubic-bezier(0.3, 0.8, 0.3, 1); transform-style: preserve-3d; }
@keyframes flipin { from { transform: rotateY(90deg); opacity: 0; } to { transform: rotateY(0); opacity: 1; } }
.bigemoji { font-size: 96px; line-height: 1.1; filter: drop-shadow(0 0 22px color-mix(in srgb, var(--c, #ffa940) 55%, transparent)) drop-shadow(0 6px 10px rgba(0, 0, 0, 0.4)); }
.rname { font-size: 26px; font-weight: 800; margin: 8px 0; }
.rname.sm { font-size: 18px; margin: 0; }
.rshort { color: var(--muted); font-size: 14px; }

.timerbar { margin-top: 8px; }
.timer { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.timer.big { font-size: 30px; }

/* night */
.nighthdr, .dayhdr { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; justify-content: center; padding: 6px; }
.nighthdr .timer, .dayhdr .timer { margin-left: auto; }
.zzz { animation: pulse 2.5s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }
.ambient p { font-size: 18px; }
.actionhdr { display: flex; gap: 12px; align-items: center; margin-bottom: 6px; }
.hint { font-weight: 600; margin: 8px 0; }
.done { color: var(--village); font-weight: 700; text-align: center; padding: 10px; }

.pickgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0; }
.pickgrid.centers { grid-template-columns: 1fr 1fr 1fr; }
.pick {
	display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 18px 8px; min-height: 96px;
	background:
		repeating-linear-gradient(45deg, rgba(255, 169, 64, 0.04) 0 6px, transparent 6px 12px),
		linear-gradient(165deg, #232c4e, #11162b);
	border: 1.5px solid var(--line); border-radius: 14px; color: var(--ink); cursor: pointer;
	font-size: 15px; font-weight: 600;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
	transition: transform 0.08s, border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.pick:active { transform: scale(0.96); }
.pick.sel { border-color: var(--accent); background: rgba(255, 169, 64, 0.16); box-shadow: 0 0 16px rgba(255, 169, 64, 0.3); }
.pick.off { opacity: 0.4; }
.pick.vote:active { border-color: var(--werewolf); background: rgba(192, 57, 43, 0.2); }
.pick.center { aspect-ratio: 3 / 4; min-height: 110px; border-color: rgba(255, 169, 64, 0.35); }
.pick-emoji { font-size: 42px; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.45)); }

.notices { margin-top: 10px; }
.notices-h { font-weight: 700; color: var(--accent); margin-bottom: 6px; font-size: 14px; }
.ncard { background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.n-text { font-weight: 600; }
.n-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tagi { background: rgba(255, 255, 255, 0.06); border-radius: 8px; padding: 3px 8px; font-size: 13px; }

/* big role-reveal tiles inside notices */
.n-tiles { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.rtile {
	flex: 0 0 auto; width: 110px; padding: 12px 8px 10px; text-align: center; border-radius: 14px;
	background:
		radial-gradient(100% 70% at 50% 0%, color-mix(in srgb, var(--c, #2a3354) 30%, transparent), transparent 70%),
		linear-gradient(165deg, #1d2546, #11162b);
	border: 2px solid var(--c, var(--line));
	box-shadow: 0 0 18px color-mix(in srgb, var(--c, #2a3354) 30%, transparent), 0 5px 14px rgba(0, 0, 0, 0.4);
	animation: fadein 0.35s ease;
}
.rtile-label { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rtile-emoji { font-size: 52px; line-height: 1.15; filter: drop-shadow(0 0 14px color-mix(in srgb, var(--c, #ffa940) 50%, transparent)) drop-shadow(0 4px 7px rgba(0, 0, 0, 0.45)); }
.rtile-name { font-weight: 800; font-size: 15px; margin-top: 4px; }

/* player tray — sticky bottom roster of face-down cards */
.ptray {
	position: sticky; bottom: 0; z-index: 4;
	display: flex; gap: 10px; justify-content: safe center; overflow-x: auto; -webkit-overflow-scrolling: touch;
	margin: 18px -16px 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
	background: linear-gradient(to top, rgba(5, 6, 15, 0.96) 60%, rgba(5, 6, 15, 0));
	border-top: 1px solid var(--line); backdrop-filter: blur(8px); scrollbar-width: none;
}
.ptray::-webkit-scrollbar { display: none; }
.pcard { flex: 0 0 auto; width: 68px; text-align: center; }
.pcard-face {
	position: relative; width: 68px; height: 92px; border-radius: 11px;
	background:
		radial-gradient(80% 55% at 50% 0%, rgba(255, 200, 120, 0.14), transparent 70%),
		repeating-linear-gradient(45deg, rgba(255, 169, 64, 0.07) 0 7px, transparent 7px 14px),
		linear-gradient(155deg, #2b345a, #11162b);
	border: 1.5px solid rgba(255, 169, 64, 0.4);
	display: flex; align-items: center; justify-content: center;
	box-shadow: 0 5px 14px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.pcard.you .pcard-face { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255, 169, 64, 0.5), 0 0 18px rgba(255, 169, 64, 0.3), 0 5px 16px rgba(0, 0, 0, 0.55); }
.pcard.off { opacity: 0.42; }
.pcard-emblem { font-size: 36px; filter: grayscale(0.2) drop-shadow(0 3px 5px rgba(0, 0, 0, 0.5)); opacity: 0.95; }
.pcard-host { position: absolute; top: -8px; right: -6px; font-size: 17px; }
.pcard-off { position: absolute; top: -6px; left: -4px; font-size: 12px; color: var(--muted); }
.pcard-status {
	position: absolute; bottom: -6px; right: -6px; width: 22px; height: 22px;
	background: var(--village); color: #04210f; border-radius: 50%;
	font-size: 13px; font-weight: 800; display: flex; align-items: center; justify-content: center;
	box-shadow: 0 0 10px rgba(39, 174, 96, 0.55);
}
.pcard-name { font-size: 12px; margin-top: 6px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard.you .pcard-name { color: var(--accent); font-weight: 600; }

/* day */
.recall { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.recall summary { cursor: pointer; font-weight: 600; }

/* vote */
.votecount { text-align: center; color: var(--muted); margin-top: 6px; }

/* reveal */
.banner { text-align: center; font-size: 26px; font-weight: 800; padding: 16px; border-radius: 16px; }
.banner.win { background: rgba(39, 174, 96, 0.18); border: 1px solid rgba(39, 174, 96, 0.5); color: #6ee7a0; }
.banner.lose { background: rgba(192, 57, 43, 0.16); border: 1px solid rgba(192, 57, 43, 0.45); color: #ff9d90; }
.summary { text-align: center; font-size: 16px; padding: 4px 8px; color: var(--ink); }
.revlist { display: flex; flex-direction: column; gap: 8px; }
.revrow { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px; }
.revrow.died { border-color: rgba(192, 57, 43, 0.5); }
.revrow.won { box-shadow: inset 3px 0 0 var(--village); }
.rv-name { font-weight: 700; }
.rv-roles { font-size: 14px; margin-top: 2px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.rv-fin { color: var(--c); font-weight: 600; }
.rv-was { color: var(--muted); font-size: 12px; }
.rv-votes { color: var(--muted); font-size: 13px; margin-top: 2px; }
.centerrow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center; margin: 6px 0; }

/* top tabs */
.tabs {
	position: sticky; top: 0; z-index: 6;
	display: flex; gap: 6px; justify-content: center;
	margin: -18px -16px 14px; padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
	background: linear-gradient(to bottom, rgba(5, 6, 15, 0.95) 70%, rgba(5, 6, 15, 0));
	backdrop-filter: blur(8px);
}
.tab {
	flex: 0 1 auto; padding: 8px 16px; min-height: 38px;
	background: transparent; border: 1px solid transparent; border-radius: 20px;
	color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer;
	transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.tab.on { color: var(--accent); background: rgba(255, 169, 64, 0.12); border-color: rgba(255, 169, 64, 0.4); }

/* rules tab */
.rules p { margin: 8px 0; }
.rolerow {
	display: flex; gap: 12px; align-items: center;
	background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--c, var(--line));
	border-radius: 12px; padding: 10px 12px;
}
.rr-emoji { font-size: 30px; flex: 0 0 auto; }
.rr-name { font-weight: 700; }
.rr-team { color: var(--c, var(--muted)); font-size: 12px; font-weight: 600; }
.rr-short { color: var(--muted); font-size: 13px; line-height: 1.3; }

/* fix-its tab */
.fixit {
	display: flex; gap: 10px; align-items: flex-start;
	background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.fixit.done { opacity: 0.55; }
.fixit.done .fix-text { text-decoration: line-through; }
.fix-check { background: none; border: none; font-size: 20px; cursor: pointer; padding: 0; line-height: 1.3; }
.fix-text { font-weight: 600; overflow-wrap: anywhere; }
.fix-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* games hub */
.gamegrid { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 380px; }
.gametile {
	display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 26px 16px;
	background:
		radial-gradient(100% 60% at 50% 0%, rgba(255, 169, 64, 0.12), transparent 70%),
		linear-gradient(165deg, #1d2546, #11162b);
	border: 2px solid rgba(255, 169, 64, 0.4); border-radius: 18px; color: var(--ink); cursor: pointer;
	box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
	transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s;
}
.gametile:active { transform: scale(0.97); }
.gametile.soon { opacity: 0.5; border-style: dashed; cursor: default; pointer-events: none; }
.gt-emoji { font-size: 56px; filter: drop-shadow(0 0 18px rgba(255, 169, 64, 0.35)) drop-shadow(0 5px 9px rgba(0, 0, 0, 0.45)); }
.gt-name { font-size: 20px; font-weight: 800; }
.gt-sub { font-size: 13px; color: var(--muted); }
.backlink { align-self: flex-start; margin: 0; }

/* update banner */
.update-banner {
	position: fixed; left: 50%; top: calc(54px + env(safe-area-inset-top)); transform: translateX(-50%);
	z-index: 9; padding: 10px 18px; border: none; border-radius: 24px; cursor: pointer;
	background: linear-gradient(180deg, #6f86ff, #4257d8); color: #fff; font-weight: 700; font-size: 14px;
	box-shadow: 0 6px 24px rgba(66, 87, 216, 0.5);
	animation: fadein 0.4s ease;
}

/* misc */
.mute { position: fixed; top: calc(10px + env(safe-area-inset-top)); right: 12px; z-index: 5; width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.4); color: var(--ink); font-size: 18px; cursor: pointer; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #2a3354; color: var(--ink); padding: 12px 18px; border-radius: 12px; border: 1px solid var(--line); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5); z-index: 10; max-width: 90vw; text-align: center; animation: fadein 0.3s; }
.shake { animation: shake 0.4s; border-color: var(--werewolf) !important; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.skull { color: var(--werewolf); }
