:root {
  color-scheme: dark;
  --ink: #ecf0df;
  --muted: #9bacaa;
  --deep: #071418;
  --surface: #0c2025;
  --panel: rgba(15, 39, 44, .92);
  --line: rgba(207, 222, 196, .13);
  --gold: #e7b94f;
  --gold-light: #f5d98c;
  --green: #75c49a;
  --danger: #ef8c7b;
  --shadow: 0 18px 55px rgba(0, 0, 0, .26);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: radial-gradient(circle at 12% 0%, #173b3b 0, transparent 38%), radial-gradient(circle at 92% 30%, #202f38 0, transparent 36%), var(--deep); color: var(--ink); }
button, input { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.hidden { display: none !important; }
.grain { position: fixed; inset: 0; pointer-events: none; opacity: .15; 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='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.22'/%3E%3C/svg%3E"); z-index: 10; mix-blend-mode: soft-light; }
.site-header { height: 94px; max-width: 1540px; margin: auto; padding: 20px 36px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.brand { display: flex; gap: 13px; align-items: center; border: 0; background: none; padding: 0; text-align: left; }
.brand strong { display: block; font-family: Georgia, serif; letter-spacing: .16em; font-size: 21px; }
.brand small { display: block; margin-top: 4px; color: var(--muted); letter-spacing: .22em; font-size: 8px; }
.brand-mark { position: relative; width: 42px; height: 38px; display: flex; align-items: flex-end; justify-content: center; gap: 2px; border-bottom: 5px solid var(--gold); }
.brand-mark i { display: block; width: 12px; height: 26px; background: var(--gold); clip-path: polygon(0 0, 50% 32%, 100% 0, 86% 100%, 14% 100%); }
.brand-mark i:nth-child(2) { height: 36px; }
.header-actions { display: flex; gap: 24px; }
.text-button, .back-button { border: 0; background: none; color: var(--muted); padding: 7px 0; }
.text-button:hover, .back-button:hover { color: var(--gold-light); }
main { max-width: 1540px; margin: auto; padding: 38px 36px 60px; }
.panel { background: linear-gradient(145deg, rgba(18, 46, 50, .96), rgba(10, 30, 35, .96)); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.eyebrow { color: var(--gold); font-size: 10px; font-weight: 750; letter-spacing: .22em; margin: 0 0 10px; }
.muted { color: var(--muted); }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { font-family: Georgia, 'Times New Roman', serif; font-weight: 500; }
h1 { font-size: clamp(34px, 4vw, 58px); line-height: 1.04; margin-bottom: 18px; }
h2 { font-size: 24px; margin-bottom: 10px; }
h3 { color: var(--gold-light); }
.primary-button, .secondary-button, .danger-button { border-radius: 8px; padding: 12px 18px; font-weight: 700; font-size: 13px; border: 1px solid transparent; transition: transform .15s, filter .15s; }
.primary-button { color: #142122; background: linear-gradient(135deg, var(--gold-light), var(--gold)); box-shadow: 0 5px 20px rgba(231, 185, 79, .13); }
.secondary-button { background: rgba(255,255,255,.035); border-color: var(--line); }
.danger-button { background: rgba(239, 140, 123, .1); color: var(--danger); border-color: rgba(239, 140, 123, .3); }
.primary-button:hover:not(:disabled), .secondary-button:hover:not(:disabled), .danger-button:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.08); }
.stack { display: grid; gap: 18px; }
label { display: grid; gap: 7px; font-size: 12px; color: var(--muted); }
input { width: 100%; border: 1px solid var(--line); background: rgba(3, 15, 18, .56); color: var(--ink); border-radius: 8px; padding: 13px 14px; }
input::placeholder { color: #6f8483; }
.toast { position: fixed; z-index: 50; left: 50%; top: 22px; transform: translate(-50%, -18px); background: #f2e7c9; color: #172326; border-radius: 9px; padding: 12px 20px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s; max-width: min(90vw, 540px); text-align: center; font-size: 13px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.auth-layout { min-height: calc(100vh - 220px); display: grid; grid-template-columns: 1.3fr .8fr; gap: 9vw; align-items: center; max-width: 1180px; margin: auto; }
.hero-copy { max-width: 620px; }
.hero-copy h1 em { color: var(--gold-light); font-weight: inherit; }
.hero-copy > p:not(.eyebrow) { color: var(--muted); max-width: 500px; line-height: 1.8; }
.hero-lands { display: flex; margin-top: 35px; }
.land-swatch { width: 55px; height: 55px; display: block; border: 4px solid var(--deep); border-radius: 10px; margin-right: -7px; transform: rotate(-5deg); box-shadow: 0 5px 15px #0005; }
.land-swatch:nth-child(even) { transform: translateY(-10px) rotate(6deg); }
.sunfields { background: #e7b94f; }.moonwood { background: #276749; }.coral { background: #38a3a5; }.clouds { background: #9bc53d; }.ember { background: #c1663f; }.crystal { background: #8b7bb8; }
.auth-card { padding: 30px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; background: #06171a; padding: 4px; border-radius: 9px; margin-bottom: 26px; }
.segmented button { border: 0; border-radius: 6px; padding: 10px; color: var(--muted); background: none; font-size: 12px; }
.segmented button.active { background: #254349; color: var(--ink); }
.auth-card .primary-button { margin-top: 5px; }
.test-accounts { border-top: 1px solid var(--line); margin-top: 25px; padding-top: 18px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
.test-accounts button { border: 1px solid var(--line); background: none; border-radius: 5px; padding: 4px 8px; }
.test-accounts small { margin-left: auto; }
.lobby-heading, .room-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; }
.lobby-heading h1 { font-size: 42px; margin: 0; }
.lobby-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.profile-card, .join-card, .rooms-card, .quick-rules { padding: 26px; }
.profile-card { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; }
.profile-card h2 { margin: 3px 0; }
.profile-card p { margin: 0; }
.avatar { width: 64px; height: 64px; display: grid; place-items: center; border-radius: 16px; color: #071418; background: var(--gold); font-family: Georgia, serif; font-size: 29px; font-weight: bold; box-shadow: inset 0 0 0 5px #ffffff1c; }
.stat-row { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); padding-top: 20px; margin-top: 5px; }
.stat-row div { display: grid; gap: 4px; text-align: center; border-right: 1px solid var(--line); }
.stat-row div:last-child { border: 0; }
.stat-row strong { font-family: Georgia, serif; font-size: 26px; color: var(--gold-light); }
.stat-row span { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.code-form { display: flex; gap: 10px; margin-top: 22px; }
.code-form input { text-transform: uppercase; letter-spacing: .2em; font-weight: bold; }
.rooms-card { min-height: 280px; }
.card-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-heading h2 { margin-bottom: 0; }
.card-heading > span { font-size: 11px; }
.room-list { display: grid; gap: 9px; margin-top: 20px; }
.room-list-item { display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--line); background: #06171a66; border-radius: 8px; padding: 13px 15px; text-align: left; }
.room-list-item:hover { border-color: #e7b94f66; }
.room-list-item strong { letter-spacing: .13em; }
.room-list-item span { color: var(--muted); font-size: 11px; }
.empty-state { text-align: center; color: var(--muted); padding: 45px 15px; font-size: 13px; }
.quick-rules ol { list-style: none; padding: 0; margin: 20px 0 0; display: grid; gap: 18px; }
.quick-rules li { display: flex; gap: 14px; }
.quick-rules li > span { flex: 0 0 29px; height: 29px; display: grid; place-items: center; border: 1px solid #e7b94f66; border-radius: 50%; color: var(--gold); font-family: Georgia, serif; }
.quick-rules strong { font-size: 13px; }
.quick-rules p { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 4px 0 0; }
.room-heading h1 { font-size: 32px; margin: 6px 0 0; }
.room-title { display: flex; align-items: center; gap: 15px; }
.room-code { border: 1px dashed #e7b94f77; color: var(--gold-light); background: #e7b94f0a; border-radius: 6px; padding: 7px 10px; font-size: 12px; letter-spacing: .16em; }
.connection-status { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 11px; }
.connection-status > span:first-child { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.connection-status > span:first-child.online { background: var(--green); box-shadow: 0 0 12px #75c49a66; }
.game-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.game-column { display: grid; gap: 12px; min-width: 0; }
.game-status { padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; box-shadow: none; }
.game-status > div:first-child { display: grid; gap: 4px; }
.game-status span { font-size: 10px; }
.game-status strong { font-family: Georgia, serif; font-size: 18px; font-weight: 500; }
.phase-badge { font-size: 9px; font-weight: 800; letter-spacing: .15em; border: 1px solid #e7b94f55; color: var(--gold); padding: 7px 9px; border-radius: 5px; }
.canvas-shell { overflow: hidden; position: relative; box-shadow: none; }
#gameCanvas { display: block; width: 100%; height: 650px; touch-action: manipulation; }
.game-controls { display: flex; align-items: center; gap: 15px; padding: 11px 14px; box-shadow: none; }
.game-controls .muted { font-size: 11px; flex: 1; text-align: center; }
.waiting-controls, .results-panel { padding: 20px; box-shadow: none; }
.member-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; margin: 17px 0; }
.member-item { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.member-color { width: 10px; height: 28px; border-radius: 4px; }
.member-item strong { font-size: 12px; display: block; }
.member-item small { color: var(--muted); font-size: 10px; }
.member-item .ready-mark { margin-left: auto; color: var(--green); font-size: 10px; }
.waiting-actions { display: flex; gap: 10px; }
.waiting-controls > p { margin: 12px 0 0; font-size: 11px; }
.chat-panel { display: grid; grid-template-rows: auto minmax(300px, 1fr) auto; height: 735px; position: sticky; top: 15px; overflow: hidden; box-shadow: none; }
.chat-heading { padding: 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.chat-heading h2 { margin: 0; font-size: 21px; }
.chat-heading .eyebrow { margin-bottom: 5px; }
.live-label { color: var(--green); font-size: 9px; letter-spacing: .13em; }
.chat-messages { overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; scrollbar-color: #345158 transparent; }
.chat-message { display: grid; gap: 4px; }
.chat-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 10px; }
.chat-author { font-weight: 700; }
.chat-time { color: #6f8483; }
.chat-body { color: #cbd5ca; font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; white-space: pre-wrap; }
.chat-empty { color: var(--muted); font-size: 12px; text-align: center; margin: auto; }
.chat-form { display: flex; gap: 8px; border-top: 1px solid var(--line); padding: 13px; }
.chat-form input { min-width: 0; padding: 10px; font-size: 12px; }
.chat-form button { border: 0; border-radius: 7px; padding: 0 13px; background: var(--gold); color: #142122; font-size: 11px; font-weight: bold; }
.result-hero { text-align: center; padding: 8px 0 20px; }
.result-hero h2 { color: var(--gold-light); font-size: 29px; margin-bottom: 7px; }
.result-hero p { color: var(--muted); font-size: 12px; }
.score-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.score-table th, .score-table td { text-align: left; padding: 10px 7px; border-bottom: 1px solid var(--line); }
.score-table th { color: var(--muted); font-size: 9px; letter-spacing: .1em; }
.score-table td:last-child, .score-table th:last-child { text-align: right; }
.score-table .winner-score { color: var(--gold-light); font-weight: bold; }
.region-details { margin-top: 16px; display: grid; gap: 7px; }
.region-row { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
dialog { width: min(680px, calc(100vw - 30px)); max-height: 85vh; overflow-y: auto; color: var(--ink); background: #102a2f; border: 1px solid #e7b94f44; border-radius: 14px; box-shadow: 0 30px 100px #000a; padding: 28px; }
dialog::backdrop { background: #020b0edb; backdrop-filter: blur(5px); }
.dialog-heading { display: flex; justify-content: space-between; align-items: start; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.dialog-heading h2 { font-size: 30px; }
.dialog-close { border: 0; background: none; color: var(--muted); font-size: 28px; line-height: 1; }
.rules-content { display: grid; gap: 18px; }
.rules-content h3 { margin-bottom: 7px; }
.rules-content p { color: #b8c5bb; line-height: 1.65; font-size: 13px; margin-bottom: 7px; }

@media (max-width: 1050px) {
  .game-grid { grid-template-columns: minmax(0, 1fr) 260px; }
  #gameCanvas { height: 620px; }
  .chat-panel { height: 705px; }
  .auth-layout { gap: 5vw; }
}

@media (max-width: 800px) {
  .site-header { padding: 18px 20px; height: 80px; }
  main { padding: 26px 18px 40px; }
  .header-actions { gap: 15px; }
  .auth-layout { grid-template-columns: 1fr; gap: 35px; padding: 25px 0; }
  .hero-copy h1 { font-size: 48px; }
  .lobby-grid { grid-template-columns: 1fr; }
  .game-grid { grid-template-columns: 1fr; }
  .chat-panel { position: static; height: 480px; }
  #gameCanvas { height: 850px; }
}

@media (max-width: 520px) {
  .site-header { padding: 16px 14px; }
  .brand strong { font-size: 17px; }
  .brand small { display: none; }
  .brand-mark { transform: scale(.8); margin-right: -4px; }
  .header-actions { gap: 11px; }
  .header-actions .text-button { font-size: 11px; }
  main { padding: 22px 11px 35px; }
  h1 { font-size: 36px; }
  .hero-copy h1 { font-size: 42px; }
  .auth-card { padding: 21px; }
  .lobby-heading { align-items: end; gap: 12px; }
  .lobby-heading h1 { font-size: 32px; }
  .lobby-heading .primary-button { padding: 11px; font-size: 11px; }
  .profile-card, .join-card, .rooms-card, .quick-rules { padding: 20px; }
  .room-heading { align-items: end; }
  .room-heading h1 { font-size: 25px; }
  .room-title { gap: 8px; }
  .connection-status { font-size: 9px; }
  .game-status { padding: 12px; }
  .game-status strong { font-size: 15px; }
  #gameCanvas { height: 790px; }
  .game-controls { flex-wrap: wrap; gap: 9px; }
  .game-controls .muted { order: 3; flex-basis: 100%; }
  .member-list { grid-template-columns: 1fr; }
  .waiting-actions { flex-wrap: wrap; }
  dialog { padding: 20px; }
}
