:root {
    color-scheme: dark;
    font-family: Inter, system-ui, sans-serif;
    background: #080b12;
    color: #f5f6f8;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: #080b12; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; background: radial-gradient(circle at top, #172033 0, #080b12 58%); }
a { color: inherit; }
.site-header { min-height: 64px; display: flex; align-items: center; gap: 18px; padding: 0 32px; border-bottom: 1px solid #293143; background: rgba(8, 11, 18, .92); position: relative; z-index: 30; }
.brand { font-weight: 800; text-decoration: none; letter-spacing: .04em; }
.site-header span { color: #9aa4b6; font-size: .9rem; }
.site-account { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.site-account a, .link-button { color: #d9dee7; font: inherit; font-size: .86rem; font-weight: 700; text-decoration: none; }
.site-account form { margin: 0; }
.link-button { padding: 0; border: 0; background: none; cursor: pointer; }
.container { width: min(1360px, calc(100% - 40px)); margin: 0 auto; padding: 56px 0 80px; }
.hero { max-width: 820px; margin-bottom: 30px; }
.eyebrow { margin: 0 0 8px; color: #d8b56b; text-transform: uppercase; letter-spacing: .18em; font-size: .78rem; }
h1 { margin: 0; font-size: clamp(2.8rem, 8vw, 5.8rem); line-height: .95; }
.lead { color: #b9c0cc; font-size: 1.1rem; line-height: 1.6; }
.panel { padding: 26px; border: 1px solid #2c3548; border-radius: 18px; background: rgba(15, 20, 31, .86); box-shadow: 0 18px 70px rgba(0, 0, 0, .2); }
.panel h2 { margin: 0; }
.setup-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.setup-card--wide, .setup-actions { grid-column: 1 / -1; }
.section-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 22px; }
.section-head > span { display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 34px; border: 1px solid rgba(216,181,107,.45); border-radius: 50%; color: #d8b56b; font-weight: 800; font-size: .82rem; }
.section-head p { margin: 5px 0 0; color: #9aa4b6; font-size: .86rem; }
.field-grid { display: grid; gap: 16px; }
.field-grid--two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-grid--spaced { margin-top: 18px; }
.field { display: grid; gap: 7px; color: #d9dee7; font-weight: 700; font-size: .88rem; }
.field--stacked { margin-top: 18px; }
.field input, .field select, .field textarea, .invite-box input { width: 100%; padding: 12px 13px; border: 1px solid #39445b; border-radius: 10px; background: #0b101a; color: #fff; font: inherit; font-weight: 500; }
.field textarea { resize: vertical; min-height: 150px; line-height: 1.5; }
.field small, .choice-card small, .setup-actions small { color: #8f99aa; font-weight: 500; line-height: 1.45; }
.validation { color: #ffb8bf; font-size: .78rem; font-weight: 600; }
.choice-grid { display: grid; gap: 12px; }
.choice-card { display: grid; grid-template-columns: 24px 1fr; gap: 5px 10px; align-items: start; padding: 16px; border: 1px solid #344057; border-radius: 12px; background: #0b101a; cursor: pointer; }
.choice-card input { grid-row: 1 / span 2; margin-top: 3px; accent-color: #d8b56b; }
.choice-card strong { font-size: .95rem; }
.setup-actions { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 20px; border: 1px solid #2c3548; border-radius: 16px; background: rgba(10, 14, 23, .92); }
.setup-actions > div { display: grid; gap: 4px; }
button, .setup-actions button { padding: 11px 16px; border: 0; border-radius: 10px; background: #d8b56b; color: #17130a; font-weight: 850; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .45; cursor: not-allowed; }
.secondary-button { border: 1px solid #46536b; background: #161d2a; color: #dce2eb; }
.room-summary, .room-next-step, .generation-grid, .game-loading { margin-bottom: 18px; }
.room-details { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 0; }
.room-details > div { padding: 16px; border: 1px solid #2c3548; border-radius: 12px; background: #0b101a; }
.room-details dt { margin-bottom: 6px; color: #8f99aa; font-size: .75rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.room-details dd { margin: 0; color: #f5f6f8; line-height: 1.5; overflow-wrap: anywhere; }
.room-details code { color: #d8b56b; }
.generation-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.generated-list { display: grid; gap: 10px; margin-top: 16px; }
.generated-item { display: grid; gap: 5px; padding: 13px; border: 1px solid #2c3548; border-radius: 10px; background: #0b101a; }
.generated-item small, .generated-item span { color: #9aa4b6; font-size: .78rem; overflow-wrap: anywhere; }
.generated-item code { color: #d8b56b; font-size: .72rem; overflow-wrap: anywhere; }
.generated-item button { justify-self: start; padding: 7px 10px; font-size: .78rem; }
.room-retry { margin-top: 14px; }
.room-footer-actions { margin-top: 18px; }
.secondary-action { display: inline-flex; padding: 11px 16px; border: 1px solid #39445b; border-radius: 10px; text-decoration: none; font-weight: 750; }
.error { padding: 12px 14px; border: 1px solid #7d3941; border-radius: 10px; background: #29151a; color: #ffc9cf; }
.is-hidden { display: none !important; }
.invite-box { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: end; margin-bottom: 18px; padding: 14px; border: 1px solid #354159; border-radius: 12px; background: #0b101a; }
.invite-box > div { grid-column: 1 / -1; display: grid; gap: 4px; }
.invite-box small { color: #8f99aa; line-height: 1.45; }
.auth-shell { min-height: calc(100dvh - 200px); display: grid; place-items: center; }
.auth-card { width: min(520px, 100%); }
.auth-card h1 { font-size: clamp(2.2rem, 8vw, 4rem); }
.auth-form { display: grid; gap: 16px; margin-top: 22px; }
.auth-check { display: flex; gap: 9px; align-items: center; color: #b9c0cc; font-size: .88rem; }
.auth-check input { accent-color: #d8b56b; }
.auth-provider-form { margin-top: 22px; }
.provider-button { width: 100%; min-height: 48px; }
.auth-divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: #718096; font-size: .78rem; }
.auth-divider::before, .auth-divider::after { content: ""; height: 1px; flex: 1; background: #2c3548; }
.auth-footer { margin: 20px 0 0; color: #8f99aa; font-size: .9rem; }
.profile-grid { max-width: 720px; }
.game-loading progress { width: 100%; height: 18px; }
.game-shell { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.game-stage { padding: 0; overflow: hidden; position: sticky; top: 18px; }
.game-hud { min-height: 58px; display: flex; align-items: center; gap: 14px; padding: 10px 14px; border-bottom: 1px solid #2c3548; background: #0b101a; }
.game-hud #timer { min-width: 78px; font-size: 1.45rem; color: #d8b56b; font-variant-numeric: tabular-nums; }
.game-hud #game-status { color: #9aa4b6; margin-right: auto; }
.game-help { color: #7f8a9d; font-size: .74rem; text-align: right; }
.touch-help { display: none; }
.three-container { position: relative; width: 100%; height: min(70vh, 720px); min-height: 520px; background: #06080c; overflow: hidden; touch-action: none; }
.three-container canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.game-crosshair { position: absolute; z-index: 3; left: 50%; top: 50%; width: 18px; height: 18px; transform: translate(-50%, -50%); pointer-events: none; opacity: .72; }
.game-crosshair::before, .game-crosshair::after { content: ""; position: absolute; background: rgba(255,255,255,.86); box-shadow: 0 0 4px rgba(0,0,0,.8); }
.game-crosshair::before { width: 12px; height: 1px; left: 3px; top: 8px; }
.game-crosshair::after { width: 1px; height: 12px; left: 8px; top: 3px; }
.interaction-hint { position: absolute; z-index: 4; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(86%, 520px); padding: 8px 12px; border: 1px solid rgba(216,181,107,.38); border-radius: 9px; background: rgba(5,8,13,.88); color: #f3e4c3; font-size: .82rem; text-align: center; pointer-events: none; }
.interaction-message { min-height: 38px; padding: 9px 14px; border-top: 1px solid #2c3548; color: #d9dee7; background: #0b101a; }
.game-side { display: grid; gap: 18px; }
.game-side .panel { padding: 18px; }
.communication-panel { margin-bottom: 18px; }
.communication-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.communication-head small { display: block; margin-top: 5px; color: #8f99aa; line-height: 1.4; }
.chat-panel { min-height: 280px; }
.chat-log { height: 220px; overflow: auto; display: grid; align-content: start; gap: 8px; margin: 14px 0; padding-right: 4px; }
.chat-message { display: grid; gap: 2px; padding: 8px 10px; border-radius: 9px; background: #0b101a; }
.chat-message strong { color: #d8b56b; font-size: .78rem; }
.chat-message span { color: #d9dee7; font-size: .86rem; overflow-wrap: anywhere; }
.chat-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.chat-form input { min-width: 0; padding: 10px 11px; border: 1px solid #39445b; border-radius: 9px; background: #080c14; color: #fff; }
.chat-form button { padding: 9px 12px; }
.interaction-dialog { position: fixed; z-index: 1000; inset: 0; display: grid; place-items: center; padding: 24px; background: rgba(2,4,8,.72); backdrop-filter: blur(6px); }
.interaction-dialog__card { width: min(460px, 100%); padding: 24px; border: 1px solid #3b465d; border-radius: 16px; background: #0d121d; box-shadow: 0 24px 90px rgba(0,0,0,.55); }
.interaction-dialog__card p { color: #aeb7c6; line-height: 1.5; }
.interaction-dialog__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
#interaction-code-input { letter-spacing: .14em; font-size: 1.15rem; text-align: center; }
#match-over { margin-top: 18px; }

@media (pointer: coarse) {
    .desktop-help { display: none; }
    .touch-help { display: inline; }
    button, input, select { min-height: 44px; }
    .generated-item button { min-height: 38px; }
}

@media (max-width: 980px) {
    .game-shell { grid-template-columns: 1fr; }
    .game-stage { position: static; }
    .game-side { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .chat-panel { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
    .site-header { min-height: 56px; padding: 8px 14px; gap: 10px; }
    .site-subtitle { display: none; }
    .site-account { gap: 10px; }
    .container { width: 100%; padding: 24px 12px calc(84px + env(safe-area-inset-bottom)); }
    .hero { padding: 0 4px; margin-bottom: 18px; }
    h1 { font-size: clamp(2.35rem, 13vw, 4.2rem); }
    .lead { font-size: 1rem; }
    .panel { padding: 18px; border-radius: 14px; }
    .setup-grid, .field-grid--two, .room-details, .generation-grid, .game-side { grid-template-columns: 1fr; }
    .setup-card--wide, .setup-actions, .chat-panel { grid-column: auto; }
    .setup-actions { align-items: stretch; flex-direction: column; }
    .setup-actions button { width: 100%; }
    .room-details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .room-details > div { padding: 12px; }
    .invite-box { grid-template-columns: 1fr; }
    .invite-box button { width: 100%; }
    .game-shell { display: block; margin-inline: -12px; }
    .game-stage { border-left: 0; border-right: 0; border-radius: 0; }
    .game-hud { min-height: 52px; padding: 8px 12px; }
    .game-hud #timer { font-size: 1.25rem; min-width: 68px; }
    .game-help { font-size: .7rem; }
    .three-container { min-height: 0; height: min(64dvh, 680px); }
    .interaction-hint { bottom: 14px; max-width: 92%; }
    .game-side { display: grid; gap: 10px; padding: 10px 12px 0; }
    .inventory-panel { position: sticky; bottom: max(8px, env(safe-area-inset-bottom)); z-index: 20; padding: 10px !important; background: rgba(11,16,26,.96); backdrop-filter: blur(12px); }
    .inventory-panel h2 { font-size: .9rem; }
    .inventory-list { display: flex; gap: 8px; overflow-x: auto; margin-top: 8px; padding-bottom: 3px; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; }
    .inventory-list .generated-item { min-width: 142px; flex: 0 0 auto; scroll-snap-align: start; padding: 9px; }
    .puzzle-panel { margin-bottom: 10px; }
    .communication-head { align-items: stretch; flex-direction: column; }
    .communication-head button { width: 100%; }
    .chat-log { height: 160px; }
    .interaction-dialog { padding: 12px; align-items: end; }
    .interaction-dialog__card { width: 100%; max-height: 78dvh; overflow: auto; border-radius: 18px 18px 8px 8px; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
    .interaction-dialog__actions { display: grid; grid-template-columns: 1fr 1fr; }
    .auth-shell { min-height: calc(100dvh - 120px); align-items: start; }
    .auth-card { padding: 20px; }
}

@media (max-width: 480px) {
    .room-details { grid-template-columns: 1fr; }
    .chat-form { grid-template-columns: 1fr; }
    .chat-form button { width: 100%; }
    .game-crosshair { opacity: .55; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
