:root {
  color-scheme: dark;
  --ink: #120c0b;
  --panel: #211513;
  --panel-2: #2d1d19;
  --line: #68483a;
  --line-bright: #a97143;
  --paper: #f0dfbd;
  --muted: #ad9582;
  --gold: #ddb270;
  --red: #a74339;
  --red-dark: #722b28;
  --green: #6f9b73;
  --shadow: 0 22px 55px rgba(0, 0, 0, .42);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--ink); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--paper);
  font-family: "Noto Serif SC", "Songti SC", "Microsoft YaHei", serif;
  background:
    radial-gradient(circle at 50% -12%, rgba(126, 74, 49, .54), transparent 43%),
    radial-gradient(circle at 10% 80%, rgba(89, 31, 28, .18), transparent 42%),
    linear-gradient(180deg, #1b1110, #0b0707 72%);
}

button, input, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.grain {
  position: fixed; inset: 0; pointer-events: none; opacity: .18; z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.3'/%3E%3C/svg%3E");
}
.app-shell { position: relative; z-index: 1; width: min(100%, 620px); min-height: 100dvh; margin: 0 auto; padding: max(18px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom)); }
.home { min-height: calc(100dvh - 46px); display: flex; flex-direction: column; justify-content: center; }
.brand { text-align: center; margin-bottom: 28px; }
.moon { width: 78px; height: 78px; display: grid; place-items: center; margin: 0 auto 14px; border-radius: 50%; font-size: 42px; background: radial-gradient(circle at 34% 28%, #f2d58f, #ba7b43 52%, #3a2117 70%); box-shadow: 0 0 42px rgba(224, 165, 91, .28); }
.brand h1 { margin: 0; letter-spacing: .18em; font-size: clamp(30px, 9vw, 44px); text-shadow: 0 2px 18px #000; }
.brand p { margin: 8px 0 0; color: var(--muted); font-size: 13px; letter-spacing: .12em; }
.panel { border: 1px solid rgba(169, 113, 67, .55); border-radius: 20px; padding: 18px; background: linear-gradient(145deg, rgba(49, 31, 26, .94), rgba(25, 16, 14, .97)); box-shadow: var(--shadow), inset 0 1px rgba(255,255,255,.04); }
.panel + .panel { margin-top: 14px; }
.field-label { display: block; margin: 0 0 8px; color: var(--gold); font-size: 13px; }
.input, .select { width: 100%; min-height: 48px; border: 1px solid var(--line); border-radius: 12px; background: #130d0c; color: var(--paper); padding: 0 14px; outline: none; }
.input:focus, .select:focus { border-color: var(--line-bright); box-shadow: 0 0 0 3px rgba(169,113,67,.16); }
.input::placeholder { color: #77665a; }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.mode-card { min-height: 116px; padding: 14px; text-align: left; border: 1px solid var(--line); border-radius: 14px; background: #1b1210; color: var(--paper); transition: .2s ease; }
.mode-card strong { display: block; color: var(--gold); margin-bottom: 6px; }
.mode-card span { color: var(--muted); font-size: 12px; line-height: 1.55; }
.mode-card.is-selected { border-color: #c68b4d; background: #332117; box-shadow: 0 0 0 2px rgba(198,139,77,.12), 0 8px 24px #0005; transform: translateY(-1px); }
.btn { width: 100%; min-height: 48px; border: 1px solid #c3735d; border-radius: 13px; color: #fff7e8; background: linear-gradient(180deg, var(--red), var(--red-dark)); box-shadow: 0 8px 20px rgba(75,21,20,.32), inset 0 1px rgba(255,255,255,.12); cursor: pointer; }
.btn:active { transform: translateY(1px); filter: brightness(.94); }
.btn:disabled { opacity: .42; cursor: not-allowed; filter: grayscale(.35); }
.btn.secondary { border-color: var(--line); background: #2b1d19; color: var(--paper); box-shadow: none; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); box-shadow: none; }
.btn.danger { background: #7c2827; }
.btn.small { width: auto; min-height: 36px; padding: 0 12px; font-size: 12px; border-radius: 10px; }
.divider { display: flex; align-items: center; gap: 10px; margin: 16px 0; color: #78675b; font-size: 11px; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: #47332c; }
.join-row { display: grid; grid-template-columns: 1fr 108px; gap: 9px; }
.room-header { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; margin: -18px -16px 18px; padding: max(12px, env(safe-area-inset-top)) 16px 12px; background: rgba(15, 9, 9, .9); border-bottom: 1px solid #3d2924; backdrop-filter: blur(16px); }
.room-title { display: flex; align-items: center; gap: 10px; }
.room-title b { display: block; letter-spacing: .12em; }
.room-title small { color: var(--muted); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #9a6a42; box-shadow: 0 0 0 4px rgba(154,106,66,.13); }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 4px rgba(111,155,115,.13); }
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 22px 2px 10px; }
.section-title h2 { margin: 0; font-size: 17px; letter-spacing: .08em; }
.section-title small { color: var(--muted); }
.room-code { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.room-code strong { display: block; color: var(--gold); font-size: 31px; letter-spacing: .15em; }
.room-code span { color: var(--muted); font-size: 12px; }
.template-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.template-tab { border: 1px solid var(--line); border-radius: 11px; background: #1a1110; color: var(--paper); padding: 10px 8px; }
.template-tab.active { color: #ffe1a6; border-color: #b87943; background: #352219; }
.roles { display: grid; gap: 8px; }
.role-row { display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 10px; padding: 8px; border-radius: 11px; background: rgba(12,8,8,.52); }
.role-thumb { width: 42px; height: 50px; border-radius: 7px; object-fit: cover; border: 1px solid #715042; }
.role-row strong { font-size: 14px; }
.role-row small { display: block; color: var(--muted); font-size: 10px; margin-top: 2px; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 8px; background: #32221e; color: var(--paper); }
.stepper span { width: 20px; text-align: center; }
.count-warning { margin-top: 12px; padding: 10px 12px; border-radius: 10px; color: #e8b0a1; background: rgba(130,42,39,.18); border: 1px solid rgba(171,65,56,.35); font-size: 12px; }
.count-ok { color: #aed0af; background: rgba(71,116,75,.18); border-color: rgba(93,151,99,.35); }
.player-list { display: grid; gap: 8px; }
.player { display: grid; grid-template-columns: 38px minmax(0,1fr) auto; gap: 10px; align-items: center; padding: 10px; border: 1px solid #49332c; border-radius: 12px; background: rgba(31,20,18,.78); }
.avatar { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; color: #21140f; background: linear-gradient(145deg,#e4c08a,#9e633b); font-weight: 800; }
.player-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-name small { display: block; color: var(--muted); font-size: 10px; margin-top: 3px; }
.badge { padding: 5px 8px; border: 1px solid #61473b; border-radius: 999px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.badge.ready { color: #bde0be; border-color: #57775a; background: #243426; }
.badge.host { color: #f3c77d; border-color: #8d623d; background: #392519; }
.offline { opacity: .54; }
.sticky-action { position: sticky; bottom: max(10px, env(safe-area-inset-bottom)); z-index: 4; margin-top: 18px; padding: 10px; border: 1px solid #51352d; border-radius: 17px; background: rgba(22,14,13,.9); backdrop-filter: blur(14px); box-shadow: 0 10px 35px #0008; }
.hint { margin: 8px 0 0; text-align: center; color: var(--muted); font-size: 11px; line-height: 1.5; }
.identity-stage { min-height: calc(100dvh - 92px); display: flex; flex-direction: column; align-items: center; }
.identity-heading { text-align: center; margin: 8px 0 16px; }
.identity-heading h1 { margin: 5px 0; font-size: 26px; letter-spacing: .12em; }
.identity-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.identity-card { position: relative; width: min(76vw, 310px); aspect-ratio: 2 / 3; border: 0; padding: 0; background: transparent; perspective: 1200px; cursor: pointer; }
.identity-card-inner { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform .58s cubic-bezier(.2,.72,.2,1); }
.identity-card.revealed .identity-card-inner { transform: rotateY(180deg); }
.card-face { position: absolute; inset: 0; overflow: hidden; border: 5px solid #805332; border-radius: 18px; backface-visibility: hidden; box-shadow: 0 22px 50px #000b, 0 0 0 1px #d3a463; }
.card-back { display: grid; place-items: center; background: radial-gradient(circle at 50% 36%,#72372f,#2a1412 58%,#100807); }
.card-back::before, .card-back::after { content: ""; position: absolute; inset: 16px; border: 1px solid #b27b4c; border-radius: 12px; }
.card-back::after { inset: 25px; border-color: #68402e; }
.back-symbol { font-size: 72px; filter: sepia(1); text-shadow: 0 0 24px #d79a58; }
.back-text { position: absolute; bottom: 17%; letter-spacing: .24em; color: #d7ae75; }
.card-front { transform: rotateY(180deg); background: #120b0a; }
.card-front img { width: 100%; height: 100%; object-fit: cover; display: block; }
.role-caption { position: absolute; left: 12px; right: 12px; bottom: 12px; padding: 10px; border-radius: 11px; color: #f7dfb5; background: rgba(19,10,9,.86); border: 1px solid #8b5839; backdrop-filter: blur(8px); }
.role-caption b { display: block; font-size: 22px; letter-spacing: .12em; }
.role-caption small { color: #c6ab91; }
.progress-strip { width: 100%; margin-top: 18px; padding: 12px; border-radius: 13px; background: rgba(37,23,20,.72); border: 1px solid #4e362e; }
.progress-strip p { margin: 0; font-size: 12px; color: var(--muted); text-align: center; }
.host-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; }
.host-role { overflow: hidden; border: 1px solid #5c3d32; border-radius: 13px; background: #1b1110; }
.host-role img { width: 100%; height: 164px; object-fit: cover; display: block; }
.host-role figcaption { padding: 9px; text-align: center; }
.host-role figcaption b { display: block; }
.host-role figcaption small { color: var(--muted); }
.reveal-list { display: grid; gap: 9px; }
.reveal-item { display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 10px; padding: 9px; border: 1px solid #4f372f; border-radius: 12px; background: #1d1311; }
.reveal-item img { width: 48px; height: 62px; border-radius: 7px; object-fit: cover; }
.reveal-item b, .reveal-item small { display: block; }
.reveal-item small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.reveal-item strong:last-child { color: var(--gold); }
.waiting { text-align: center; padding: 50px 18px; }
.waiting .icon { font-size: 54px; margin-bottom: 10px; }
.waiting p { color: var(--muted); line-height: 1.7; }
.host-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.host-actions button { border: 1px solid #604339; border-radius: 8px; background: #2a1b18; color: #d9c3aa; padding: 6px 8px; font-size: 10px; }
.toast-region { position: fixed; z-index: 50; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(calc(100% - 32px), 520px); pointer-events: none; }
.toast { margin-top: 8px; padding: 12px 15px; border: 1px solid #8a5944; border-radius: 12px; background: rgba(40,24,21,.96); color: #f3dfc5; box-shadow: 0 12px 30px #0008; animation: toast-in .24s ease; }
.toast.error { border-color: #b34e48; background: rgba(84,29,28,.97); }
.empty { padding: 22px; text-align: center; color: var(--muted); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (min-width: 560px) { .host-grid { grid-template-columns: repeat(3,1fr); } .app-shell { padding-left: 24px; padding-right: 24px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; } }
