:root {
  color-scheme: dark;
  --bg: #07111f;
  --bg-soft: #0d1a2b;
  --panel: #12243a;
  --panel-2: #172d47;
  --line: #29445f;
  --text: #f6f8fb;
  --muted: #9eb1c6;
  --gold: #f0bb45;
  --gold-2: #ffdc78;
  --cyan: #43d4e8;
  --green: #58d68d;
  --red: #ff6b6b;
  --shadow: 0 20px 60px rgba(0, 0, 0, .38);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 16% 8%, rgba(41, 112, 164, .18), transparent 28rem),
    radial-gradient(circle at 86% 18%, rgba(230, 169, 54, .11), transparent 24rem),
    linear-gradient(135deg, #06101d 0%, #0b1727 45%, #07111f 100%);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 16px;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin-top: 0; }

.site-header {
  min-height: 66px;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid rgba(240, 187, 69, .35);
  background: rgba(5, 14, 25, .94);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: max-content; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  border: 2px solid var(--gold); color: var(--gold-2); font-weight: 900; letter-spacing: -.04em;
  box-shadow: 0 0 0 3px rgba(240, 187, 69, .12), inset 0 0 22px rgba(240, 187, 69, .16);
}
.brand strong { display: block; font-size: 15px; letter-spacing: .02em; }
/* Единая панель роли: на узких экранах она прокручивается по горизонтали,
   поэтому ссылки не сжимаются и не перекрывают название страницы. */
.site-header-tools { min-width: 0; display: flex; align-items: center; justify-content: flex-end; gap: 8px; overflow-x: auto; scrollbar-width: thin; }
.role-navigation { min-width: max-content; display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.role-navigation form { margin: 0; }
.role-navigation a,
.role-navigation button {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: #d7e3ee;
  font: inherit;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
  cursor: pointer;
}
.role-navigation a:hover,
.role-navigation button:hover,
.role-navigation a[aria-current="page"] { border-color: #527295; background: #14283e; color: white; }
.role-navigation .system-exit { border-color: rgba(240, 187, 69, .32); color: var(--gold-2); }
.role-badge { min-height: 31px; display: inline-flex; align-items: center; gap: 5px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; color: white; font-size: 11px; font-weight: 900; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
.role-badge.participant { border-color: rgba(67, 212, 232, .55); color: #91edf7; }
.role-badge.host { border-color: rgba(240, 187, 69, .55); color: var(--gold-2); }
.role-badge.admin { border-color: rgba(88, 214, 141, .55); color: #a8f1c3; }
.role-badge.visitor { color: var(--muted); }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.header-actions form { margin: 0; }
.session-code { color: var(--muted); font-size: 13px; letter-spacing: .05em; text-transform: uppercase; }
.session-code strong { color: var(--gold-2); font-size: 17px; letter-spacing: .12em; }
.save-indicator { color: var(--green); font-size: 13px; }

.button {
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 42px;
  padding: 10px 15px;
  cursor: pointer;
  color: var(--text);
  background: var(--panel-2);
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
  transition: transform .15s ease, border-color .15s ease, background .15s ease, opacity .15s ease;
}
.button:hover { transform: translateY(-1px); border-color: #527295; }
.button:active { transform: translateY(0); }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.button[hidden] { display: none; }
.button.primary { background: linear-gradient(135deg, #d49727, #f0bb45); color: #161005; border-color: #ffd777; }
.button.accent { background: linear-gradient(135deg, #1c8fa5, #43d4e8); color: #041116; border-color: #78e7f4; }
.button.secondary { background: #1b3957; border-color: #3d6488; }
.button.ghost { background: transparent; }
.button.danger { background: rgba(192, 54, 54, .2); border-color: rgba(255, 107, 107, .55); color: #ffd4d4; }
.button.small { min-height: 34px; padding: 7px 11px; font-size: 13px; }
.button.wide { width: 100%; }
.text-button { border: 0; padding: 2px 4px; background: transparent; color: var(--cyan); font-weight: 700; cursor: pointer; }
.icon-button { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: #0d1c2e; color: white; cursor: pointer; font-size: 26px; line-height: 1; }

.eyebrow { margin-bottom: 8px; color: var(--gold); text-transform: uppercase; letter-spacing: .14em; font-size: 11px; font-weight: 800; }
.panel { background: rgba(18, 36, 58, .94); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

.landing-page main {
  position: relative;
  isolation: isolate;
  background: url("../assets/entry/hero.webp") 54% center / cover fixed no-repeat;
}
.landing-page main::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(90deg, rgba(3, 9, 18, .12) 0%, rgba(4, 12, 23, .24) 38%, rgba(4, 12, 23, .50) 60%, rgba(3, 9, 18, .68) 100%),
    linear-gradient(180deg, rgba(3, 9, 18, 0), rgba(3, 9, 18, .06));
}
.hero {
  width: min(1240px, calc(100% - 40px));
  min-height: calc(100vh - 67px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 64px;
  align-items: center;
  padding: 60px 0;
}
.hero-copy { text-shadow: 0 3px 24px rgba(0, 0, 0, .92); }
.hero h1 { font-size: clamp(46px, 7vw, 92px); line-height: .92; letter-spacing: -.045em; margin-bottom: 28px; }
.hero h1 span { color: var(--gold-2); font-size: .55em; letter-spacing: -.025em; }
.hero-lead { max-width: 700px; color: #c6d4e3; font-size: clamp(17px, 2vw, 22px); line-height: 1.55; }
.entry-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.entry-card { display: block; position: relative; min-height: 260px; padding: 132px 18px 20px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(10, 25, 42, .94); transition: transform .2s, border-color .2s, background .2s; }
.entry-card:hover { transform: translateY(-5px); border-color: var(--gold); background: rgba(20, 43, 67, .98); }
.entry-card.primary { border-color: rgba(240, 187, 69, .7); }
.entry-card h2 { margin-bottom: 8px; font-size: 20px; }
.entry-card p { margin: 0; color: var(--muted); line-height: 1.42; font-size: 13px; }
.entry-number { position: absolute; left: 18px; top: 92px; z-index: 2; font-size: 28px; color: var(--gold-2); font-weight: 900; text-shadow: 0 2px 10px #000; }
.entry-art { position: absolute; inset: 0 0 auto; height: 116px; background-image: var(--role-bg-image, none); background-position: center; background-size: cover; border-bottom: 1px solid rgba(240, 187, 69, .38); }
.entry-art::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 34%, rgba(6, 16, 29, .38) 100%); }
.entry-card-participant { --role-bg-image: url("../assets/role-backgrounds/participant-preview-v1.webp"); }
.entry-card-create .entry-art { background-image: url("../assets/entry/create-game.webp"); }
.entry-card-host { --role-bg-image: url("../assets/role-backgrounds/host-preview-v1.webp"); }
.entry-card-rules .entry-art { background-image: url("../assets/entry/rules.webp"); }
.entry-card-admin { --role-bg-image: url("../assets/role-backgrounds/admin-preview-v1.webp"); }
.entry-card-admin { border-color: rgba(67, 212, 232, .58); }

/* Ролевые иллюстрации загружаются в два этапа: компактный WebP задаётся
   сразу, а common.js заменяет переменную на полноразмерный фон после decode. */
.participant-access-page { --role-bg-image: url("../assets/role-backgrounds/participant-preview-v1.webp"); }
.host-login-page { --role-bg-image: url("../assets/role-backgrounds/host-preview-v1.webp"); }
.admin-login-page,
.admin-page { --role-bg-image: url("../assets/role-backgrounds/admin-preview-v1.webp"); }

.access-page .site-header { display: none; }
.access-page main {
  min-height: 100vh;
  background: #030405;
}
.access-gate {
  width: min(420px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  padding: 32px 0;
}
.access-panel {
  padding: 26px 0;
  background: transparent;
}
.access-form { display: grid; gap: 16px; }
.access-form label { display: grid; gap: 8px; color: #e2ebf3; font-size: 14px; font-weight: 700; }
.access-form input {
  width: 100%;
  min-height: 48px;
  border: 1px solid #43617e;
  border-radius: 11px;
  background: rgba(5, 16, 29, .94);
  color: white;
  padding: 11px 13px;
  outline: none;
}
.access-form .button { min-height: 50px; margin-top: 4px; }
.access-panel .form-error { margin: 0 0 18px; }

.form-page { width: min(1000px, calc(100% - 36px)); min-height: calc(100vh - 67px); margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr; gap: 60px; align-items: center; padding: 50px 0; }
.form-page.single { grid-template-columns: 1fr; max-width: 700px; }
.form-intro h1 { font-size: clamp(36px, 5vw, 64px); line-height: 1; margin-bottom: 20px; }
.form-intro p:not(.eyebrow) { color: var(--muted); line-height: 1.6; font-size: 18px; }
.form-intro-visual { align-self: center; }
.form-visual { margin-top: 24px; width: 100%; aspect-ratio: 16 / 9; border: 1px solid rgba(240, 187, 69, .46); border-radius: var(--radius); background-position: center; background-size: cover; box-shadow: var(--shadow); }
.form-page-participant .form-visual { background-image: url("../assets/role-backgrounds/participant-preview-v1.webp"); }
.form-page-create .form-visual { background-image: url("../assets/entry/create-game.webp"); }
.form-page-host .form-visual { background-image: url("../assets/role-backgrounds/host-preview-v1.webp"); }
.form-page-host { width: min(1180px, calc(100% - 36px)); grid-template-columns: .8fr 1.2fr; }
.form-card { padding: 28px; }
.form-card label, .compact-label, .modal-window > label { display: grid; gap: 7px; margin-bottom: 17px; color: #dce6ef; font-size: 14px; font-weight: 700; }
.form-card input, .form-card select, .compact-label select, .modal-window textarea,
.balance-form input, .balance-form textarea, .balance-form select {
  width: 100%; border: 1px solid #35516d; border-radius: 9px; background: #0b1a2b; color: white; padding: 10px 11px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(67, 212, 232, .13); }
.form-card small { color: var(--muted); font-weight: 400; }
.panel-note { margin: 2px 0 18px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: rgba(20, 45, 70, .62); color: var(--muted); line-height: 1.45; }
.panel-note b { color: var(--text); }
.optional-label { color: var(--muted); font-size: 11px; font-weight: 500; }
.form-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.code-input { text-transform: uppercase; letter-spacing: .18em; font-size: 22px !important; font-weight: 900; text-align: center; }
.form-error { padding: 11px 13px; border-radius: 9px; background: rgba(190, 50, 50, .2); color: #ffd4d4; border: 1px solid rgba(255, 107, 107, .5); }
.error-panel { padding: 42px; text-align: center; }
.session-picker { min-width: 0; margin: 0 0 18px; padding: 0; border: 0; }
.session-picker legend { margin-bottom: 9px; color: #dce6ef; font-size: 14px; font-weight: 700; }
.session-list { display: grid; gap: 8px; max-height: min(48vh, 480px); overflow-y: auto; padding: 2px 6px 2px 2px; }
.session-option { position: relative; display: grid !important; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px !important; margin: 0 !important; padding: 13px; border: 1px solid #35516d; border-radius: 12px; background: #0b1a2b; cursor: pointer; }
.session-option:hover { border-color: #5c7895; }
.session-option:has(input:checked) { border-color: var(--gold); box-shadow: inset 3px 0 0 var(--gold), 0 0 0 2px rgba(240, 187, 69, .08); background: #142941; }
.session-option input { width: 18px !important; height: 18px; margin: 0; accent-color: var(--gold); }
.session-option-main, .session-option-meta { display: grid; gap: 4px; min-width: 0; }
.session-option-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-option-main span { color: var(--muted); font-size: 12px; font-weight: 500; }
.session-option-meta { text-align: right; }
.session-option-meta b { color: var(--gold-2); letter-spacing: .12em; }
.session-option-meta small { font-size: 10px; }
.empty-sessions { display: grid; gap: 8px; justify-items: start; padding: 18px; border: 1px dashed #486783; border-radius: 12px; color: var(--muted); }
.empty-sessions strong { color: white; }

.game-shell { --host-font-scale: 1; --players-panel-width: 310px; --control-panel-width: 330px; height: calc(100vh - 67px); display: grid; grid-template-columns: var(--players-panel-width) minmax(500px, 1fr) var(--control-panel-width); overflow: hidden; background: var(--bg); }
.game-shell.control-panel-hidden { grid-template-columns: var(--players-panel-width) minmax(500px, 1fr); }
.game-shell.control-panel-hidden .control-sidebar { display: none; }
.game-shell:fullscreen, .player-shell:fullscreen { width: 100vw; height: 100vh; min-height: 100vh; background: var(--bg); }
.player-shell:fullscreen .sidebar { top: 0; height: 100vh; }
.player-shell:fullscreen .player-board-stage { height: 100vh; }
.sidebar { min-height: 0; overflow-y: auto; padding: 18px; background: rgba(10, 24, 40, .97); }
.players-sidebar { border-right: 1px solid var(--line); }
.control-sidebar, .player-card-sidebar { border-left: 1px solid var(--line); }
.sidebar-heading { padding: 4px 3px 14px; }
.sidebar-heading h2 { margin: 0; font-size: 22px; }
.sidebar-note { margin-top: 12px; color: var(--muted); font-size: 12px; line-height: 1.45; }

.players-list { display: grid; gap: 8px; margin-bottom: 14px; }
.player-row { position: relative; display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 11px; border: 1px solid #29445f; border-radius: 12px; background: #12253b; cursor: pointer; }
.player-row.selected { border-color: var(--gold); box-shadow: inset 3px 0 0 var(--gold); background: #19304a; }
.player-row:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
.player-token { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--player-color); display: grid; place-items: center; font-weight: 900; font-size: 12px; color: white; }
.player-info { min-width: 0; }
.player-info strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-info span { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.player-money { text-align: right; }
.player-money strong { display: block; color: var(--gold-2); font-size: 14px; }
.player-money button { margin-top: 4px; color: var(--cyan); border: 0; background: none; padding: 0; cursor: pointer; font-size: 11px; }

.board-stage { position: relative; min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; padding: 12px; background: #050c15; }
.board-toolbar { min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 0 4px 10px; color: var(--muted); font-size: 13px; }
.board-toolbar strong { color: white; }
.board-identity { min-width: 170px; max-width: 38%; display: grid; justify-items: center; gap: 3px; text-align: center; line-height: 1.1; }
.board-identity-role { color: var(--gold-2) !important; font-size: 18px; font-weight: 900; letter-spacing: .14em; text-shadow: 0 0 16px rgba(240, 187, 69, .32); }
.board-identity-player .board-identity-role { color: var(--cyan) !important; text-shadow: 0 0 16px rgba(67, 212, 232, .3); }
.board-identity-name, .board-identity #turn-summary { display: block; width: 100%; overflow: hidden; color: white; text-overflow: ellipsis; white-space: nowrap; }
.board-identity-name { font-size: 14px; }
.board-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
.board-actions .zoom-button { min-width: 36px; padding-inline: 10px; font-size: 18px; line-height: 1; }
.board-zoom-value { min-width: 60px; padding: 8px 9px; border: 1px solid var(--line); border-radius: 9px; background: #10243a; color: var(--gold-2); text-align: center; font-weight: 800; }
.status-dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); }
.board-viewport { position: relative; min-width: 0; min-height: 0; overflow: auto; padding: 4px; overscroll-behavior: contain; }
.board-viewport.pan-enabled .board-wrap { cursor: grab; touch-action: none; }
.board-viewport.dragging, .board-viewport.dragging .board-wrap { cursor: grabbing; user-select: none; }
.board-wrap { position: relative; width: min(100%, 940px); max-width: none; margin: 0 auto; border: 1px solid rgba(240, 187, 69, .45); box-shadow: var(--shadow); overflow: hidden; background: #040810; container-type: inline-size; }
.board-wrap.dragging { cursor: grabbing; user-select: none; }
.board-wrap.hidden { display: none; }
.board-image { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.board-quality-status { position: absolute; z-index: 12; top: 64px; right: 22px; width: max-content; max-width: calc(100% - 44px); margin: 0; padding: 8px 11px; border: 1px solid rgba(240, 187, 69, .65); border-radius: 9px; background: rgba(5, 12, 21, .9); color: var(--gold-2); box-shadow: 0 8px 24px rgba(0, 0, 0, .3); font-size: 12px; font-weight: 800; pointer-events: none; }
.board-quality-status[hidden] { display: none; }
.token-layer { position: absolute; inset: 0; pointer-events: none; }
.board-token { position: absolute; transform: translate(-50%, -50%); border-radius: 50%; background: rgba(4, 12, 20, .38); border: clamp(2px, .32cqw, 11px) solid var(--token-color); box-shadow: 0 0 0 1px rgba(255,255,255,.8), 0 0 10px var(--token-color); width: clamp(12px, 1.92cqw, 68px); height: clamp(12px, 1.92cqw, 68px); display: grid; place-items: center; font-size: clamp(7px, .85cqw, 30px); font-weight: 900; color: white; }
.history-strip { width: min(100%, 940px); min-height: 31px; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 9px; margin: 5px auto 0; }
.history-strip h3 { margin: 0; color: var(--muted); font-size: 11px; white-space: nowrap; }
.history-list { min-width: 0; display: flex; gap: 5px; overflow-x: auto; padding: 1px 0 3px; }
.history-card { flex: 0 0 auto; min-width: 0; max-width: 170px; min-height: 26px; padding: 4px 8px; overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: #10243a; cursor: pointer; }
.history-card strong { display: block; overflow: hidden; font-size: 11px; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
.history-list .empty-state { margin: 0; align-self: center; font-size: 11px; white-space: nowrap; }

.control-block { padding: 15px 0; border-top: 1px solid rgba(58, 85, 112, .65); }
.control-block h3 { font-size: 15px; margin-bottom: 11px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 9px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: #091725; }
.segmented button { border: 0; border-radius: 7px; padding: 8px; background: transparent; color: var(--muted); cursor: pointer; font-weight: 700; }
.segmented button.active { background: #244866; color: white; }
.dice-result { min-height: 46px; margin-top: 9px; padding: 12px; display: grid; place-items: center; border: 1px dashed #4b6b8b; border-radius: 10px; color: var(--gold-2); text-align: center; font-weight: 800; }
.dice-result.compact { font-size: 13px; color: var(--muted); }
.manual-dice { margin-top: 9px; color: var(--muted); font-size: 12px; }
.manual-dice summary { cursor: pointer; font-weight: 800; }
.manual-dice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; align-items: end; margin-top: 9px; }
.manual-dice-row label { display: grid; gap: 4px; }
.manual-dice-row input { width: 100%; min-width: 0; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #091725; color: white; }
.manual-dice-row .button { grid-column: 1 / -1; }
.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-bottom: 8px; }
.button-grid .button { min-height: 54px; font-size: 12px; padding: 8px; }
.participant-head { display: flex; justify-content: space-between; margin: 10px 0 6px; font-size: 13px; font-weight: 700; }
.participant-list { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 10px; }
.participant-check { display: flex; gap: 6px; align-items: center; padding: 7px; border-radius: 8px; background: #0b1a2b; font-size: 12px; }
.setting-check { display: flex; gap: 7px; align-items: flex-start; margin: 8px 0 10px; color: #c9d6e3; font-size: 12px; line-height: 1.35; }
#host-app .sidebar { font-size: calc(16px * var(--host-font-scale)); }
#host-app .sidebar-heading h2 { font-size: calc(22px * var(--host-font-scale)); }
#host-app .sidebar-note { font-size: calc(12px * var(--host-font-scale)); }
#host-app .player-info span { font-size: calc(12px * var(--host-font-scale)); }
#host-app .player-money strong { font-size: calc(14px * var(--host-font-scale)); }
#host-app .player-money button { font-size: calc(11px * var(--host-font-scale)); }
#host-app .control-block h3 { font-size: calc(15px * var(--host-font-scale)); }
#host-app .participant-check, #host-app .setting-check, #host-app .manual-dice { font-size: calc(12px * var(--host-font-scale)); }
#host-app .button:not(.small):not(.zoom-button) { font-size: calc(14px * var(--host-font-scale)); }

.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(1, 6, 12, .78); backdrop-filter: blur(7px); }
.modal-window { position: relative; z-index: 1; width: min(1120px, calc(100vw - 48px)); max-height: calc(100vh - 48px); overflow: auto; padding: 22px; border: 1px solid rgba(240, 187, 69, .62); border-radius: 20px; background: #0d1c2e; box-shadow: 0 30px 90px rgba(0,0,0,.65); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.modal-header h2 { margin: 0; }
.card-modal-window { width: min(1180px, calc(100vw - 360px)); min-width: 600px; }
.game-card { height: clamp(430px, calc(100vh - 265px), 690px); min-height: 430px; display: grid; place-items: center; overflow: hidden; padding: 52px clamp(34px, 7vw, 100px); border-radius: 18px; background-color: #ead36e; background-position: center; background-size: 100% 100%; color: #15110b; }
.game-card-text { width: 100%; max-width: 830px; max-height: 100%; overflow: hidden; overflow-wrap: anywhere; hyphens: auto; white-space: pre-wrap; text-align: center; font-size: clamp(20px, 2.1vw, 33px); line-height: 1.28; font-weight: 700; text-shadow: 0 1px rgba(255,255,255,.55); }
.game-card-text.card-text-scrollable { overflow-y: auto; padding-right: 7px; scrollbar-width: thin; }
.card-participant-status { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 0 0; }
.decision-chip { padding: 6px 9px; border-radius: 999px; background: #1a314a; font-size: 12px; color: var(--muted); }
.decision-chip.yes { color: #bbf3d0; border: 1px solid rgba(88,214,141,.4); }
.decision-chip.no { color: #ffd1d1; border: 1px solid rgba(255,107,107,.4); }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; padding-top: 14px; }
.font-modal-window { width: min(520px, calc(100vw - 32px)); }
.font-modal-note { margin: 0 0 18px; color: var(--muted); line-height: 1.5; }
.font-controls { display: grid; grid-template-columns: 72px 1fr 72px; gap: 10px; align-items: center; }
.font-controls output { padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: #10243a; color: var(--gold-2); text-align: center; font-size: 24px; font-weight: 900; }

.dice-overlay { position: absolute; inset: 0; z-index: 280; display: grid; place-items: center; padding: 18px; }
.dice-overlay-backdrop { position: absolute; inset: 0; background: rgba(1, 6, 12, .7); backdrop-filter: blur(5px); }
.dice-popup { position: relative; z-index: 1; width: min(440px, calc(100% - 24px)); display: grid; justify-items: center; gap: 16px; padding: 24px; border: 1px solid rgba(240, 187, 69, .72); border-radius: 20px; background: #0d1c2e; box-shadow: 0 30px 90px rgba(0,0,0,.7); }
.dice-faces { display: flex; justify-content: center; gap: 18px; }
.dice-face { width: clamp(92px, 12vw, 120px); aspect-ratio: 1; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 14px; border-radius: 20px; background: linear-gradient(145deg, #fff, #dce8f1); box-shadow: inset 0 0 0 3px #a9bac8, 0 12px 24px rgba(0,0,0,.42); }
.dice-pip { width: clamp(13px, 2vw, 20px); aspect-ratio: 1; align-self: center; justify-self: center; border-radius: 50%; background: #10243a; box-shadow: inset 0 2px 2px rgba(0,0,0,.5); }
.dice-pip.tl { grid-area: 1 / 1; } .dice-pip.tc { grid-area: 1 / 2; } .dice-pip.tr { grid-area: 1 / 3; }
.dice-pip.ml { grid-area: 2 / 1; } .dice-pip.mc { grid-area: 2 / 2; } .dice-pip.mr { grid-area: 2 / 3; }
.dice-pip.bl { grid-area: 3 / 1; } .dice-pip.bc { grid-area: 3 / 2; } .dice-pip.br { grid-area: 3 / 3; }
.dice-popup-result { color: var(--gold-2); font-size: 20px; }
.dice-overlay.rolling .dice-popup { cursor: progress; }
.dice-overlay.rolling .dice-face { animation: dice-tumble .36s ease-in-out infinite alternate; }
.dice-overlay.rolling .dice-face:nth-child(2) { animation-delay: -.18s; }
@keyframes dice-tumble {
  from { transform: rotate(-7deg) translateY(-4px) scale(.96); }
  to { transform: rotate(7deg) translateY(4px) scale(1.04); }
}
.personal-code-window { width: min(560px, calc(100vw - 32px)); text-align: center; }
.personal-code-window > p:not(.eyebrow) { color: var(--muted); line-height: 1.55; }
.personal-code-value { display: block; margin: 22px 0 10px; padding: 18px; border: 1px solid var(--gold); border-radius: 14px; background: #071422; color: var(--gold-2); font-size: clamp(30px, 7vw, 52px); font-weight: 900; letter-spacing: .12em; }
.help-cards-open { margin-top: 16px; }
.help-cards-window { width: min(1180px, calc(100vw - 48px)); }
.help-card-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.help-card-tabs .button.active { border-color: var(--gold); background: #244866; color: var(--gold-2); }
.help-card-view { min-height: 0; display: grid; place-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: #060d16; }
.help-card-view img { display: block; max-width: 100%; max-height: calc(100vh - 220px); width: auto; height: auto; object-fit: contain; }

.rules-page main { padding-bottom: 70px; }
.rules-hero { min-height: 420px; display: grid; align-items: end; padding: 70px max(24px, calc((100vw - 1180px) / 2)) 54px; background: linear-gradient(90deg, rgba(4, 12, 23, .68), rgba(4, 12, 23, .18)), url("../assets/entry/rules.webp") center / cover no-repeat; border-bottom: 1px solid rgba(240, 187, 69, .4); }
.rules-hero-copy { max-width: 720px; }
.rules-hero h1 { margin-bottom: 16px; font-size: clamp(42px, 7vw, 78px); line-height: 1; }
.rules-hero-copy > p:last-child { margin: 0; color: #ced9e6; font-size: 19px; line-height: 1.55; }
.rules-nav { position: sticky; top: 66px; z-index: 90; display: flex; gap: 8px; overflow-x: auto; padding: 11px max(20px, calc((100vw - 1180px) / 2)); border-bottom: 1px solid var(--line); background: rgba(6, 16, 29, .95); backdrop-filter: blur(14px); }
.rules-nav a { flex: 0 0 auto; padding: 7px 10px; border: 1px solid #29445f; border-radius: 999px; color: #c7d4e1; font-size: 12px; }
.rules-nav a:hover { border-color: var(--gold); color: var(--gold-2); }
.rules-layout { width: min(1180px, calc(100% - 36px)); margin: 34px auto 0; display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: start; }
.rules-content { display: grid; gap: 16px; }
.rules-section { scroll-margin-top: 125px; display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 18px; padding: 25px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(15, 32, 52, .93); }
.rules-step { width: 54px; height: 54px; display: grid; place-items: center; border: 1px solid var(--gold); border-radius: 50%; color: var(--gold-2); font-size: 18px; font-weight: 900; }
.rules-section h2 { margin-bottom: 13px; font-size: 25px; }
.rules-section h3 { color: var(--gold-2); }
.rules-section li, .rules-section > div > p:not(.eyebrow) { color: #c7d4e1; line-height: 1.58; }
.rules-section li + li { margin-top: 7px; }
.rules-note { padding: 12px 14px; border-left: 3px solid var(--cyan); background: rgba(67, 212, 232, .08); border-radius: 0 9px 9px 0; }
.rules-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.rules-cards article { padding: 15px; border: 1px solid #2b4a68; border-radius: 12px; background: #0a192a; }
.rules-cards article p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.rules-aside { position: sticky; top: 125px; display: grid; gap: 14px; }
.rules-aside-card { padding: 20px; }
.rules-aside-card h2 { font-size: 20px; }
.rules-aside-card > p:last-child { margin: 0; color: var(--muted); line-height: 1.55; }
.balance-view { width: min(1040px, calc(100vw - 60px)); }
.balance-view-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.balance-view-part { grid-column: 1 / -1; margin: 12px 0 0; padding: 10px 2px 7px; border-bottom: 2px solid var(--gold); color: var(--gold-2); }
.balance-view section { padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #11243a; }
.balance-view section.wide { grid-column: 1 / -1; }
.balance-view dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; font-size: 13px; }
.balance-view dt { color: var(--muted); }
.balance-view dd { margin: 0; font-weight: 700; }
.balance-view table { width: 100%; border-collapse: collapse; font-size: 12px; }
.balance-view th, .balance-view td { padding: 7px; text-align: left; border-bottom: 1px solid var(--line); }

.player-shell { min-height: calc(100vh - 67px); display: grid; grid-template-columns: 270px minmax(620px, 1fr) 300px; align-items: start; background: #eef2f4; }
.player-shell .sidebar { position: sticky; top: 67px; height: calc(100vh - 67px); }
.player-main { min-width: 0; background: #eef2f4; }
.player-board-stage { height: calc(100vh - 67px); min-height: 620px; }
.my-position { margin: 13px 0; padding: 13px; border-radius: 11px; background: #11263e; border: 1px solid var(--line); }
.my-position span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.my-position strong { display: block; margin-top: 4px; }
.balance-stage { width: min(100%, 820px); min-width: 0; margin: 0 auto; padding: 28px 24px 48px; background: #eef2f4; color: #18222c; }
.balance-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 25px; margin-bottom: 18px; }
.balance-heading h1 { margin: 0; font-size: 30px; }
.balance-heading .eyebrow { color: #805f17; }
.balance-totals { display: grid; grid-template-columns: repeat(2, minmax(130px, auto)); gap: 9px; }
.balance-totals div { min-width: 110px; padding: 9px 12px; border: 1px solid #c9d1d8; border-radius: 10px; background: white; }
.balance-totals span { display: block; color: #66727d; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.balance-totals strong { display: block; margin-top: 3px; font-size: 16px; }
.balance-totals .cashflow { border-color: #c49a39; background: #fff8e6; }
.balance-form { display: grid; gap: 14px; }
.balance-part { display: grid; gap: 14px; padding: 18px; border: 1px solid #c7d0d8; border-radius: 17px; background: #e4e9ed; }
.balance-part + .balance-part { margin-top: 12px; }
.balance-part-heading { padding: 2px 3px 6px; border-bottom: 2px solid #b88927; }
.balance-part-heading .eyebrow { margin-bottom: 3px; color: #805f17; }
.balance-part-heading h2 { margin: 0; font-size: 24px; color: #18222c; }
.form-section { padding: 17px; border: 1px solid #cbd4dc; border-radius: 13px; background: #fff; box-shadow: 0 5px 15px rgba(26, 45, 63, .06); }
.form-section h2 { margin-bottom: 12px; font-size: 17px; }
.form-grid { display: grid; gap: 10px; }
.form-grid.three { grid-template-columns: repeat(3, 1fr); }
.span-2 { grid-column: span 2; }
.dynamic-profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 13px; }
.dynamic-profile-section { padding: 12px; border: 1px solid #d3dce3; border-radius: 11px; background: #f7f9fa; }
.dynamic-profile-heading { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.dynamic-profile-heading h3 { margin: 0; color: #253a4b; font-size: 15px; }
.dynamic-profile-section > p { margin: 4px 0 10px; color: #74808a; font-size: 11px; }
.dynamic-profile-list { display: grid; gap: 8px; }
.dynamic-profile-row { display: grid; gap: 4px; }
.dynamic-profile-row > label { color: #53606b; font-size: 11px; font-weight: 700; }
.dynamic-profile-row > div { display: flex; align-items: center; gap: 7px; }
.dynamic-profile-row input { width: 100%; min-width: 0; }
.remove-profile-entry { flex: 0 0 32px; width: 32px; height: 32px; border: 1px solid #d7a8a8; border-radius: 7px; background: #fff0f0; color: #a32626; font-size: 20px; line-height: 1; cursor: pointer; }
.dynamic-profile-empty { margin: 0; padding: 10px; border: 1px dashed #c8d1d8; border-radius: 8px; color: #74808a; font-size: 12px; }
.balance-form label { display: grid; gap: 5px; color: #53606b; font-size: 12px; font-weight: 700; }
.balance-form input, .balance-form textarea, .balance-form select { color: #17232d; background: #f7f9fa; border-color: #ccd5dd; padding: 8px 9px; }
.balance-form input[readonly] { color: #5d6872; background: #e9eef2; }
.balance-columns { display: grid; grid-template-columns: 1fr 1fr .75fr; gap: 14px; }
.money-label { grid-template-columns: minmax(120px, 1fr) 125px !important; align-items: center; margin-bottom: 7px; }
.money-label input { text-align: right; }
.money-label.emphasis { color: #654a0a; }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 15px; }
.balance-form .text-button { color: #126b7c; }
.editable-table { overflow-x: auto; }
.editable-table table { width: 100%; min-width: 740px; border-collapse: collapse; }
.editable-table th { padding: 7px; background: #e8eef3; color: #4c5c69; font-size: 10px; text-transform: uppercase; letter-spacing: .04em; text-align: left; }
.editable-table td { padding: 4px; border-bottom: 1px solid #e0e5e9; }
.editable-table input { min-width: 92px; padding: 7px; }
.editable-table .remove-row { width: 30px; height: 30px; border: 0; border-radius: 7px; background: #fee8e8; color: #a32626; cursor: pointer; }
.summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.summary-grid div { padding: 11px; border: 1px solid #d4dbe1; border-radius: 10px; background: #f7f9fa; }
.summary-grid span { display: block; color: #66727d; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.summary-grid strong { display: block; margin-top: 4px; font-size: 16px; }

.my-card-list { display: grid; gap: 9px; }
.my-card-item { padding: 12px; border: 1px solid var(--line); border-radius: 11px; background: #13283f; cursor: pointer; }
.my-card-item.open { border-color: var(--gold); }
.my-card-item strong { display: block; margin-bottom: 4px; }
.my-card-item span { color: var(--muted); font-size: 11px; }
.empty-state { color: var(--muted); font-size: 13px; }

.toast { position: fixed; right: 18px; bottom: 18px; z-index: 500; max-width: 420px; padding: 12px 16px; border-radius: 10px; background: #17314b; color: white; border: 1px solid #477091; box-shadow: var(--shadow); opacity: 0; transform: translateY(20px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #4a2024; border-color: #a94b53; }

@media (max-width: 1280px) {
  .game-shell { grid-template-columns: 260px minmax(430px, 1fr) 290px; }
  .player-shell { grid-template-columns: 240px minmax(540px, 1fr) 260px; }
  .card-modal-window { width: min(1000px, calc(100vw - 90px)); }
}

@media (max-width: 980px) {
  .site-header { position: relative; align-items: flex-start; }
  .hero, .form-page { grid-template-columns: 1fr; gap: 28px; }
  .hero { padding: 35px 0; }
  .landing-page main { background-position: 62% top; background-attachment: scroll; }
  .landing-page main::before {
    background: linear-gradient(180deg, rgba(3, 9, 18, .24) 0%, rgba(3, 9, 18, .52) 34%, rgba(3, 9, 18, .84) 58%, rgba(3, 9, 18, .88) 100%);
  }
  .access-page main { background: #030405; }
  .access-gate { grid-template-columns: 1fr; padding: 32px 0; }
  .form-page-host { grid-template-columns: 1fr; }
  .game-shell, .player-shell { height: auto; display: block; overflow: visible; }
  .sidebar, .player-shell .sidebar { position: relative; top: auto; width: 100%; height: auto; max-height: none; border: 0; border-bottom: 1px solid var(--line); }
  .players-list { grid-template-columns: repeat(2, 1fr); }
  .board-stage { height: 78vh; min-height: 560px; }
  .control-sidebar { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 18px; }
  .control-sidebar .sidebar-heading { grid-column: 1 / -1; }
  .balance-stage { width: min(100%, 760px); padding: 16px; }
  .balance-columns { grid-template-columns: 1fr 1fr; }
  .cash-section { grid-column: 1 / -1; }
  .player-card-sidebar { min-height: 300px; }
  .card-modal-window { min-width: 0; width: calc(100vw - 32px); }
  .editable-table { overflow: visible; }
  .editable-table table, .editable-table tbody { display: block; width: 100%; min-width: 0; }
  .editable-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
  .editable-table tbody { display: grid; gap: 10px; }
  .editable-table tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 10px; border: 1px solid #d7dee4; border-radius: 11px; background: #f8fafb; }
  .editable-table td { min-width: 0; display: grid; gap: 4px; padding: 0; border: 0; }
  .editable-table td::before { content: attr(data-label); color: #66727d; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
  .editable-table td.row-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
  .editable-table td.row-actions::before { display: none; }
  .editable-table input { width: 100%; min-width: 0; }
  .rules-layout { grid-template-columns: 1fr; }
  .rules-aside { position: static; grid-template-columns: repeat(2, 1fr); }
  .rules-cards { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  body { font-size: 15px; }
  .site-header { padding: 9px 12px; flex-wrap: wrap; }
  .brand small { display: none; }
  .header-actions { width: 100%; justify-content: flex-start; }
  .hero { width: min(100% - 24px, 1240px); }
  .access-gate { width: min(100% - 24px, 420px); padding: 24px 0; }
  .access-panel { padding: 18px 0; }
  .entry-grid { grid-template-columns: 1fr; }
  .entry-card { min-height: 230px; padding: 126px 18px 18px; }
  .entry-number { left: 18px; top: 86px; }
  .form-page { width: min(100% - 24px, 1000px); }
  .form-columns, .form-grid.three, .dynamic-profile-grid, .balance-columns, .balance-totals, .summary-grid, .control-sidebar { grid-template-columns: 1fr; }
  .span-2, .cash-section { grid-column: auto; }
  .balance-heading { display: block; }
  .balance-totals { margin-top: 14px; }
  .players-list { grid-template-columns: 1fr; }
  .board-stage { height: 72vh; min-height: 460px; padding: 8px; }
  .board-toolbar { align-items: flex-start; flex-direction: column; }
  .board-identity { order: -1; align-self: center; width: 100%; max-width: 100%; }
  .board-actions { width: 100%; justify-content: flex-start; }
  .board-actions .button:not(.zoom-button) { font-size: 12px; padding-inline: 9px; }
  .balance-part { padding: 10px; }
  .section-title { align-items: flex-start; flex-direction: column; }
  .editable-table tr { grid-template-columns: 1fr; }
  .editable-table td.row-actions { grid-column: auto; }
  .modal { padding: 8px; }
  .modal-window { width: calc(100vw - 16px); max-height: calc(100vh - 16px); padding: 14px; }
  .game-card { height: min(72vh, 560px); min-height: 380px; padding: 36px 22px; }
  .game-card-text { font-size: 19px; }
  .balance-view-grid { grid-template-columns: 1fr; }
  .balance-view section.wide { grid-column: auto; }
  .help-card-tabs { display: grid; grid-template-columns: 1fr; }
  .session-option { grid-template-columns: auto minmax(0, 1fr); }
  .session-option-meta { grid-column: 2; text-align: left; }
  .rules-hero { min-height: 340px; padding: 48px 18px 36px; }
  .rules-nav { top: 0; }
  .rules-layout { width: min(100% - 24px, 1180px); }
  .rules-section { grid-template-columns: 1fr; padding: 18px; }
  .rules-aside { grid-template-columns: 1fr; }
}
