:root {
  --bg: #0d0c0a;
  --panel: #171511;
  --panel-2: #1d1a15;
  --card: #211d16;
  --line: #3c3427;
  --line-soft: #2a251e;
  --gold: #c8a15a;
  --gold-bright: #e1bd73;
  --paper: #efe2c4;
  --text: #f2ead9;
  --muted: #afa48f;
  --danger: #ca6a61;
  --good: #7fb186;
  --blue: #7c9cb7;
  --shadow: 0 20px 50px rgba(0,0,0,.28);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { color-scheme: dark; background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(200,161,90,.08), transparent 34rem),
    linear-gradient(180deg, #0f0e0c, #0b0a09 60%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button { color: inherit; }
button, input, select { min-height: 44px; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 2px;
}

.app-shell { width: min(1180px, calc(100% - 28px)); margin: 0 auto; padding-bottom: 48px; }
.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 20px 0 18px; border-bottom: 1px solid var(--line-soft); margin-bottom: 28px;
}
.brand { display: inline-flex; align-items: center; gap: 12px; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid var(--gold);
  color: var(--gold-bright); font-family: Georgia, serif; font-size: 24px; font-weight: 700;
  background: linear-gradient(135deg, rgba(200,161,90,.16), transparent);
}
.brand strong { display: block; letter-spacing: .13em; font-family: Georgia, serif; font-size: 15px; }
.brand small { color: var(--muted); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }
.header-status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 999px; background: #756b59; }
.status-dot.online { background: var(--good); box-shadow: 0 0 0 4px rgba(127,177,134,.1); }

.view { display: none; }
.view.active { display: block; animation: view-in .18s ease-out; }
@keyframes view-in { from { opacity: .4; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.hero-grid { display: grid; grid-template-columns: 1.45fr .75fr; gap: 24px; align-items: end; margin-bottom: 24px; }
.hero-copy { padding: 30px 0 22px; }
.eyebrow { margin: 0 0 8px; color: var(--gold); font-size: 11px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; margin: 0; font-weight: 600; }
h1 { font-size: clamp(36px, 7vw, 72px); line-height: .98; letter-spacing: -.035em; }
h2 { font-size: 28px; }
h3 { font-size: 20px; }
.hero-text { max-width: 710px; color: #c9bfad; font-size: 17px; line-height: 1.7; }
.rule-strip { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 20px; }
.rule-strip span { border: 1px solid var(--line); background: rgba(29,26,21,.65); padding: 9px 12px; border-radius: 999px; color: var(--muted); font-size: 12px; }
.rule-strip b { color: var(--paper); }

.panel { background: linear-gradient(180deg, rgba(29,26,21,.96), rgba(20,18,15,.96)); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.identity-panel { padding: 18px; }
.identity-panel label, .stacked-form label { color: var(--muted); font-size: 13px; }
.field-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 8px; }
input, select {
  width: 100%; border: 1px solid var(--line); border-radius: 11px; background: #100f0d; color: var(--text); padding: 10px 12px; font-size: 16px;
}
input::placeholder { color: #71695b; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 18px, calc(100% - 11px) 18px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
.button {
  border: 1px solid var(--line); border-radius: 11px; padding: 10px 15px; cursor: pointer; font-weight: 800; letter-spacing: .025em; transition: border-color .15s ease, transform .15s ease, background .15s ease;
}
.button:hover { border-color: #6b5a3e; }
.button:active { transform: translateY(1px); }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.button.primary { background: linear-gradient(180deg, #d3ad65, #a77f3e); color: #17130d; border-color: #e0bd78; }
.button.secondary { background: #252016; color: var(--paper); }
.button.ghost { background: transparent; color: var(--muted); }
.button.danger { background: rgba(202,106,97,.1); border-color: rgba(202,106,97,.4); color: #e2a09a; }
.button.full { width: 100%; }
.text-button { background: none; border: 0; color: var(--gold-bright); cursor: pointer; padding: 8px; }

.home-actions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.home-actions-grid > .panel { padding: 22px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.section-heading.compact { margin-bottom: 10px; }
.stacked-form { display: grid; gap: 14px; }
.stacked-form label { display: grid; gap: 7px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.toggle-row { grid-template-columns: 22px 1fr !important; align-items: center; gap: 10px !important; }
.toggle-row input { width: 18px; height: 18px; min-height: 18px; accent-color: var(--gold); }
.join-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
#joinCode { text-transform: uppercase; letter-spacing: .25em; font-weight: 800; }
.divider { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; color: #6e6658; font-size: 11px; margin: 20px 0; text-transform: uppercase; letter-spacing: .14em; }
.divider::before, .divider::after { content: ''; height: 1px; background: var(--line-soft); }
.room-list { display: grid; gap: 9px; }
.room-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; background: rgba(10,9,8,.45); border: 1px solid var(--line-soft); padding: 12px; border-radius: 12px; }
.room-row strong { display: block; }
.room-row small { color: var(--muted); }
.empty-state { padding: 20px 12px; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); text-align: center; }

.view-toolbar { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.lobby-layout { display: grid; grid-template-columns: 1.5fr .7fr; gap: 24px; }
.lobby-main, .lobby-sidebar { padding: 24px; }
.lobby-main h1 { font-size: clamp(38px, 6vw, 64px); }
.room-code-block { margin: 22px 0; padding: 16px; background: #100f0d; border: 1px solid var(--line); border-radius: 14px; display: flex; justify-content: space-between; align-items: center; gap: 15px; }
.room-code-block span { color: var(--muted); font-size: 11px; letter-spacing: .16em; }
.room-code-block strong { color: var(--gold-bright); letter-spacing: .2em; font-size: 22px; }
.seat-list { display: grid; gap: 10px; }
.seat { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 12px; border: 1px solid var(--line-soft); background: rgba(10,9,8,.35); padding: 11px; border-radius: 13px; }
.seat-avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--line); background: #252018; color: var(--gold-bright); font-family: Georgia, serif; font-weight: 700; }
.seat small { color: var(--muted); }
.seat-status { color: var(--good); font-size: 11px; text-transform: uppercase; letter-spacing: .1em; }
.seat-status.offline { color: var(--danger); }
.rule-list { display: grid; grid-template-columns: 1fr auto; gap: 12px 16px; margin: 18px 0 24px; }
.rule-list dt { color: var(--muted); }
.rule-list dd { margin: 0; color: var(--paper); font-weight: 700; }
.host-controls { display: grid; gap: 9px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; line-height: 1.5; }

.game-header { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.game-header h1 { font-size: clamp(36px, 6vw, 62px); }
.turn-banner { border: 1px solid var(--line); border-radius: 999px; padding: 10px 14px; color: var(--paper); background: #181510; font-size: 13px; font-weight: 800; }
.turn-banner.yours { color: #17130d; background: var(--gold); border-color: var(--gold-bright); }
.scoreboard { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 18px; }
.score-card { border: 1px solid var(--line-soft); border-radius: 13px; background: #15130f; padding: 12px; min-width: 0; }
.score-card.active { border-color: var(--gold); box-shadow: inset 0 0 0 1px rgba(200,161,90,.12); }
.score-card .score-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.score-card strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-card .points { font-family: Georgia, serif; font-size: 24px; color: var(--gold-bright); }
.score-card small { color: var(--muted); }

.board { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: radial-gradient(circle at center, rgba(92,68,36,.18), transparent 45%), #100f0c; margin-bottom: 18px; }
.board-heading { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 16px; }
.target-badge { border: 1px solid var(--line); color: var(--gold-bright); padding: 8px 11px; border-radius: 999px; font-size: 12px; }
.card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.contract-card {
  position: relative; min-height: 230px; padding: 17px; border: 1px solid #65563c; border-radius: 14px; background:
    linear-gradient(180deg, rgba(239,226,196,.98), rgba(207,185,143,.96)); color: #2a2117; box-shadow: 0 12px 26px rgba(0,0,0,.24); cursor: default; overflow: hidden;
}
.contract-card.selectable { cursor: pointer; }
.contract-card.selectable:hover { outline: 2px solid var(--gold-bright); outline-offset: 2px; }
.contract-card::after { content: ''; position: absolute; inset: 7px; border: 1px solid rgba(74,53,29,.25); border-radius: 9px; pointer-events: none; }
.contract-head { position: relative; z-index: 1; display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.contract-head small { text-transform: uppercase; letter-spacing: .11em; color: #6f5b3d; }
.contract-points { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; border: 2px solid #84683c; color: #513c20; font-family: Georgia, serif; font-size: 21px; font-weight: 700; background: rgba(255,255,255,.18); flex: 0 0 auto; }
.requirements { position: relative; z-index: 1; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 25px 0 20px; }
.req-die { width: 43px; height: 43px; border-radius: 9px; display: grid; place-items: center; background: #f8edd3; border: 1px solid #8e7650; font-size: 29px; line-height: 1; }
.progress-list { position: relative; z-index: 1; display: grid; gap: 5px; margin-top: auto; }
.progress-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid rgba(72,52,29,.18); padding-top: 5px; font-size: 11px; }
.progress-row span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-dice { letter-spacing: .04em; font-size: 16px; }

.dice-tray { padding: 18px; }
.dice-tray-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 14px; }
.dice-grid { display: grid; grid-template-columns: repeat(6, minmax(56px, 1fr)); gap: 10px; }
.die-button, .die-static {
  aspect-ratio: 1; min-width: 0; min-height: 56px; display: grid; place-items: center; border-radius: 14px; border: 1px solid #63543c; background: linear-gradient(145deg, #f4e7cb, #cbb284); color: #241c13; font-size: clamp(34px, 6vw, 54px); box-shadow: inset 0 0 0 3px rgba(255,255,255,.16), 0 7px 13px rgba(0,0,0,.18); }
.die-button { cursor: pointer; }
.die-button.selected { outline: 3px solid var(--gold-bright); outline-offset: 2px; transform: translateY(-2px); }
.die-button.committed, .die-static.committed { opacity: .55; filter: saturate(.6); }
.die-button.rolling, .die-static.rolling { animation: dice-jump .42s ease; }
@keyframes dice-jump { 0%,100% { transform: rotate(0) scale(1); } 35% { transform: rotate(7deg) scale(1.08); } 70% { transform: rotate(-5deg) scale(.98); } }
.game-controls { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 16px; }
.game-controls .button { flex: 1 1 160px; }

.winner-panel { margin-top: 18px; border: 1px solid var(--gold); border-radius: var(--radius); padding: 24px; text-align: center; background: radial-gradient(circle at top, rgba(200,161,90,.16), transparent 60%), #17140f; }
.winner-panel h2 { font-size: 42px; color: var(--gold-bright); margin-bottom: 8px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); background: #252019; border: 1px solid var(--line); color: var(--text); padding: 10px 14px; border-radius: 999px; opacity: 0; pointer-events: none; transition: .18s ease; z-index: 50; box-shadow: var(--shadow); max-width: calc(100% - 30px); text-align: center; font-size: 13px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(202,106,97,.55); color: #f0b0aa; }

@media (max-width: 850px) {
  .hero-grid, .home-actions-grid, .lobby-layout { grid-template-columns: 1fr; }
  .hero-copy { padding-bottom: 0; }
  .scoreboard { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-grid { grid-template-columns: 1fr; }
  .contract-card { min-height: 205px; }
  .dice-grid { grid-template-columns: repeat(3, minmax(64px, 1fr)); }
}

@media (max-width: 560px) {
  .app-shell { width: min(100% - 18px, 1180px); padding-bottom: 28px; }
  .site-header { padding-top: 12px; margin-bottom: 18px; }
  .brand small { display: none; }
  .header-status { font-size: 0; }
  .header-status #connectionText { display: none; }
  .hero-copy h1 { font-size: 46px; }
  .hero-text { font-size: 15px; }
  .home-actions-grid > .panel, .lobby-main, .lobby-sidebar { padding: 16px; }
  .two-col { grid-template-columns: 1fr; }
  .join-form { grid-template-columns: 1fr; }
  .view-toolbar .button { flex: 1; }
  .game-header { align-items: start; flex-direction: column; }
  .game-header h1 { font-size: 42px; }
  .turn-banner { width: 100%; text-align: center; }
  .scoreboard { gap: 7px; }
  .score-card { padding: 9px; }
  .score-card .points { font-size: 20px; }
  .board { padding: 12px; }
  .board-heading h2 { font-size: 22px; }
  .target-badge { font-size: 11px; }
  .contract-card { min-height: 190px; padding: 14px; }
  .requirements { margin: 18px 0 14px; gap: 6px; }
  .req-die { width: 39px; height: 39px; font-size: 27px; }
  .dice-tray { padding: 13px; }
  .dice-tray-heading { align-items: start; flex-direction: column; gap: 5px; }
  .dice-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .die-button, .die-static { font-size: 42px; }
  .toast { bottom: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* v1.1 account, player identity, and dice-color additions */
.header-right { display: flex; align-items: center; gap: 12px; }
.profile-chip { min-height: 38px; display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 999px; background: #17140f; color: var(--paper); padding: 7px 11px; cursor: pointer; }
.player-color-dot { --player-color: var(--gold); width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: 0 0 auto; background: var(--player-color); border: 1px solid rgba(255,255,255,.24); box-shadow: 0 0 0 2px rgba(0,0,0,.14); }
.small-dot { width: 10px; height: 10px; }
.large-color-dot { --player-color: var(--gold); --player-edge: #8c692c; width: 46px; height: 46px; border-radius: 13px; background: var(--player-color); border: 2px solid var(--player-edge); box-shadow: inset 0 0 0 3px rgba(255,255,255,.12); flex: 0 0 auto; }
.identity-heading, .account-summary { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.account-summary { justify-content: flex-start; }
.account-summary-copy { min-width: 0; }
.account-summary-copy h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compact-form { gap: 10px; }
.auth-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.auth-buttons .button { flex: 1 1 120px; }
.profile-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin-top: 14px; }
.stat-tile { border: 1px solid var(--line-soft); border-radius: 11px; padding: 9px; background: rgba(8,7,6,.32); min-width: 0; }
.stat-tile strong { display: block; color: var(--gold-bright); font-family: Georgia, serif; font-size: 20px; overflow: hidden; text-overflow: ellipsis; }
.stat-tile span { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }

.game-header-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }
.score-card { position: relative; overflow: hidden; }
.score-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--score-color, var(--gold)); }
.score-identity { display: flex; align-items: center; gap: 7px; min-width: 0; }
.score-identity strong { min-width: 0; }

.progress-player { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.progress-dice { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; letter-spacing: 0; }
.committed-die-chip { --die-bg: #d6aa54; --die-edge: #8c692c; --die-ink: #241a0c; width: 29px; height: 29px; display: inline-grid; place-items: center; border-radius: 7px; background: var(--die-bg); border: 1px solid var(--die-edge); color: var(--die-ink); font-size: 21px; line-height: 1; box-shadow: inset 0 0 0 2px rgba(255,255,255,.13), 0 2px 4px rgba(0,0,0,.16); }
.empty-progress { color: #745f42; }

.die-button, .die-static {
  --die-bg: #d6aa54;
  --die-edge: #8c692c;
  --die-ink: #241a0c;
  border-color: var(--die-edge);
  background: var(--die-bg);
  color: var(--die-ink);
}
.die-button.committed, .die-static.committed { opacity: .48; filter: none; }

.seat { position: relative; overflow: hidden; }
.seat::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--seat-color, transparent); }
.seat-avatar { --player-color: #252018; --player-edge: var(--line); --player-ink: var(--gold-bright); background: var(--player-color); border-color: var(--player-edge); color: var(--player-ink); }
.open-seat-avatar { background: #252018 !important; color: var(--gold-bright) !important; border-color: var(--line) !important; }

.modal-dialog { width: min(520px, calc(100% - 24px)); max-height: calc(100% - 30px); border: 0; padding: 0; background: transparent; color: var(--text); }
.modal-dialog::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(3px); }
.modal-card { background: linear-gradient(180deg, #1d1a15, #12100d); border: 1px solid var(--line); border-radius: 18px; padding: 20px; box-shadow: 0 28px 80px rgba(0,0,0,.55); }
.modal-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.icon-button { width: 44px; min-width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: #12100d; color: var(--muted); font-size: 25px; cursor: pointer; }
.modal-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 16px; padding: 4px; border: 1px solid var(--line-soft); border-radius: 12px; background: #100f0d; }
.modal-tab { border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; font-weight: 800; }
.modal-tab.active { background: #292216; color: var(--gold-bright); }

@media (max-width: 560px) {
  .header-right { gap: 7px; }
  .profile-chip { padding: 7px 9px; max-width: 150px; }
  .profile-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .game-header-actions { width: 100%; display: grid; grid-template-columns: 1fr auto; }
  .game-header-actions .turn-banner { width: auto; }
  .profile-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .progress-row { align-items: flex-start; }
  .progress-player { max-width: 42%; }
  .committed-die-chip { width: 28px; height: 28px; font-size: 20px; }
  .modal-card { padding: 16px; }
}
