:root {
  --bg: #0f1722; --panel: #18222f; --panel2: #213042; --line: #2c3d52; --text: #e8eef5; --muted: #8fa3b8;
  --accent: #ffb703; --accent-ink: #1b1300;
  --red: #ef4444; --orange: #f97316; --yellow: #facc15; --green: #22c55e; --blue: #3b82f6; --purple: #a855f7; --white: #f1f5f9; --any: #6b7a8c;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 14px; }
[hidden] { display: none !important; }

.logo { font-size: 56px; font-weight: 800; letter-spacing: -.02em; display: flex; align-items: center; justify-content: center; gap: .2em; }
.logo span:last-child { color: var(--accent); margin-left: -.2em; }
.logo.small { font-size: 34px; margin: 24px 0 16px; }
.logo.tiny { font-size: 20px; display: inline-flex; margin: 0; }
.logo-mark { width: .7em; height: .7em; border-radius: .16em; background: repeating-linear-gradient(90deg, var(--accent) 0 .14em, transparent .14em .24em); border-top: .09em solid var(--text); border-bottom: .09em solid var(--text); }

.screen { max-width: 880px; margin: 0 auto; padding: 16px; }
.hero { text-align: center; padding: 36px 0 12px; }
.tagline { color: var(--muted); font-size: 18px; margin: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin: 18px auto; max-width: 460px; }
.card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input { width: 100%; padding: 11px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-row { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.btn-row.tight { margin-top: 8px; }
.btn { flex: 1; padding: 11px 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.link { flex: none; background: none; border: none; color: var(--muted); font-weight: 500; padding: 6px; }
.btn small { font-weight: 500; opacity: .75; }
.hint, .note { color: var(--muted); font-size: 13px; margin: 12px 0 0; }
.note { color: var(--accent); }
.pill { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--panel2); color: var(--muted); vertical-align: middle; }
.about { margin-top: 28px; color: #c5d2df; }
.about-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 14px 0; }
.about-grid > div { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.about-grid h3 { color: var(--accent); margin-top: 0; }
.about-grid p { margin: 0; font-size: 14px; }
.site-footer { display: flex; gap: 18px; justify-content: center; color: var(--muted); font-size: 13px; padding: 28px 0; }
.site-footer a { color: var(--muted); }

/* Home page */
.screen.wide { max-width: 1120px; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 0; }
.topbar .logo.small { margin: 8px 0; }
.topbar nav a { color: var(--muted); text-decoration: none; font-weight: 600; }
.topbar nav a:hover { color: var(--accent); }
.hero2 { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 36px; align-items: center; padding: 22px 0 10px; }
.hero-copy h1 { font-size: 44px; font-weight: 800; letter-spacing: -.02em; line-height: 1.08; margin-bottom: 14px; }
.hero-copy .tagline { font-size: 17px; color: #c5d2df; }
.facts { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 0; margin: 16px 0 0; }
.facts li { background: var(--panel); border: 1px solid var(--line); border-radius: 99px; padding: 5px 12px; font-size: 13px; color: var(--muted); }
.facts strong { color: var(--accent); }
.hero-copy .card { margin: 20px 0 0; max-width: none; }
.hero-art { margin: 0; }
.hero-art img { width: 100%; height: auto; display: block; border-radius: 16px; border: 1px solid var(--line); box-shadow: 0 18px 50px rgba(0, 0, 0, .45); }
.hero-art figcaption { color: var(--muted); font-size: 13px; text-align: center; margin-top: 10px; }
.about h2 { font-size: 26px; }
.about-grid.two { grid-template-columns: repeat(2, 1fr); }
.about-grid.steps h3 { color: var(--text); }
.faq details { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; margin-bottom: 8px; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq details p { margin: 10px 0 2px; color: #c5d2df; }
@media (max-width: 1000px) {
  .hero2 { grid-template-columns: 1fr; gap: 22px; }
  .about-grid.two { grid-template-columns: 1fr; }
  .hero-copy h1 { font-size: 34px; }
}

/* Ad placeholders: reserved space, filled once ad code is added. */
.ad-slot { display: flex; align-items: center; justify-content: center; border: 1px dashed var(--line); border-radius: 8px; color: #46586c; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.ad-slot::before { content: "Advertisement"; }
.ad-banner { max-width: 728px; height: 90px; margin: 18px auto; }
.ad-box { height: 250px; margin-top: 14px; }

.invite { display: flex; gap: 8px; }
.invite .btn { flex: none; }
.seat-list { list-style: none; padding: 0; margin: 16px 0 0; }
.seat-list li { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; background: var(--bg); margin-bottom: 6px; }
.seat-list li.empty { color: #4d5f73; background: none; border: 1px dashed var(--line); }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.tag { margin-left: auto; font-size: 12px; color: var(--muted); }

/* Game layout */
#game { max-width: none; padding: 0; display: grid; grid-template-columns: 240px minmax(0, 1fr) 250px; height: 100vh; }
#side-left, #side-right { background: var(--panel); padding: 12px; overflow-y: auto; display: flex; flex-direction: column; min-height: 0; }
#side-left { border-right: 1px solid var(--line); }
#side-right { border-left: 1px solid var(--line); }
.brand-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
#players { list-style: none; margin: 0; padding: 0; }
#players li { border: 1px solid var(--line); border-left: 5px solid; border-radius: 9px; padding: 8px 10px; margin-bottom: 7px; background: var(--bg); }
#players li.turn { background: var(--panel2); box-shadow: 0 0 0 2px var(--accent); }
#players .pname { font-weight: 700; display: flex; justify-content: space-between; gap: 6px; }
#players .pname span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#players .pstats { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 1px 9px; margin-top: 2px; white-space: nowrap; }
#players .off { opacity: .55; }
.feed { flex: 1; min-height: 110px; overflow-y: auto; font-size: 13px; background: var(--bg); border-radius: 9px; padding: 8px; margin-top: 6px; }
.feed div { margin-bottom: 3px; color: #b8c6d4; }
.feed .sys { color: var(--accent); }
.feed .chat { color: var(--text); }
.feed b { font-weight: 600; }
#chat-form { margin-top: 6px; }
#chat-input { padding: 8px 10px; font-size: 13px; }

#board-wrap { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100vh; }
#status { padding: 9px 14px; font-weight: 600; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; align-items: center; min-height: 42px; }
#status.mine { background: #3a2f08; color: #ffe08a; }
#status .timer { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 500; }
#status .btn { flex: none; padding: 5px 12px; }
#board { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 6px; }
#board svg { width: 100%; height: 100%; max-height: 100%; display: block; }
#hand-bar { background: var(--panel); border-top: 1px solid var(--line); padding: 10px 14px; min-height: 86px; }
#hand { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: center; }
#hand .empty { color: var(--muted); }

.rcard { position: relative; width: 62px; height: 62px; border-radius: 9px; border: 2px solid rgba(255, 255, 255, .25); display: flex; align-items: center; justify-content: center; font-size: 24px; color: rgba(0, 0, 0, .55); font-weight: 700; user-select: none; }
.rcard.c-red { background: var(--red); } .rcard.c-orange { background: var(--orange); } .rcard.c-yellow { background: var(--yellow); }
.rcard.c-green { background: var(--green); } .rcard.c-blue { background: var(--blue); } .rcard.c-purple { background: var(--purple); }
.rcard.c-white { background: var(--white); }
.rcard.c-wild { background: conic-gradient(var(--red), var(--orange), var(--yellow), var(--green), var(--blue), var(--purple), var(--red)); color: #fff; text-shadow: 0 1px 3px #000; }
.rcard.c-none { background: none; border-style: dashed; border-color: var(--line); }
.rcard .n { position: absolute; right: -6px; top: -8px; min-width: 24px; height: 24px; padding: 0 5px; border-radius: 12px; background: #0b1119; color: #fff; font-size: 14px; line-height: 24px; text-align: center; border: 1px solid var(--line); text-shadow: none; }
#market { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
#market .rcard { width: auto; height: 54px; cursor: pointer; font-size: 20px; }
#market .rcard.off { cursor: not-allowed; opacity: .4; }
#market .rcard:not(.off):hover { transform: translateY(-2px); border-color: #fff; }
#contracts { list-style: none; margin: 0 0 8px; padding: 0; }
#contracts li { display: flex; justify-content: space-between; gap: 8px; padding: 7px 9px; border-radius: 8px; background: var(--bg); margin-bottom: 5px; font-size: 13px; cursor: default; border: 1px solid transparent; }
#contracts li:hover { border-color: var(--accent); }
#contracts li.done { color: #7ee2a0; }
#contracts li .v { font-weight: 700; }
#btn-contracts, #btn-deck { width: 100%; flex: none; }
#side-left > *, #side-right > * { flex-shrink: 0; }
#side-left > .feed { flex-shrink: 1; }
.legend { font-size: 12px; color: var(--muted); margin-top: 12px; }
.legend table { width: 100%; border-collapse: collapse; }
.legend td { padding: 1px 0; }

/* Board */
.lake { fill: #14283f; stroke: #1d3a5c; stroke-width: 2; stroke-linejoin: round; }
.route rect { stroke: rgba(0, 0, 0, .55); stroke-width: 1.2; }
.route { cursor: pointer; }
.route.c-red rect { fill: var(--red); } .route.c-orange rect { fill: var(--orange); } .route.c-yellow rect { fill: var(--yellow); }
.route.c-green rect { fill: var(--green); } .route.c-blue rect { fill: var(--blue); } .route.c-purple rect { fill: var(--purple); }
.route.c-white rect { fill: var(--white); } .route.c-any rect { fill: var(--any); }
.route.open rect { fill-opacity: .5; }
.route.open.can rect { fill-opacity: 1; stroke: #fff; stroke-width: 1.6; }
.route.open:hover rect { fill-opacity: 1; }
.route.closed rect { fill-opacity: .12; stroke-opacity: .3; }
.route.closed { cursor: default; }
.route.claimed rect { stroke: #fff; stroke-width: 1.8; }
.route.claimed { cursor: default; }
.route .tie { stroke: rgba(0, 0, 0, .5); stroke-width: 2; pointer-events: none; }
.route.just rect { animation: pop .9s ease-out; }
@keyframes pop { 0% { stroke-width: 7; stroke: #fff; } 100% { stroke-width: 1.8; } }
.city .halo { fill: #0f1722; opacity: .7; }
.city .dot { fill: #f8fafc; stroke: #0b1119; stroke-width: 2.5; }
.city .pip { fill: #0b1119; }
.trains { pointer-events: none; }
.train .cargo { font-size: 14px; paint-order: stroke; stroke: #0b1119; stroke-width: 3px; }
#board svg { border-radius: 14px; }
.city text { fill: #dbe5ef; font-size: 13px; font-weight: 600; paint-order: stroke; stroke: var(--bg); stroke-width: 3.5px; stroke-linejoin: round; pointer-events: none; }
.city.hl .dot { fill: var(--accent); r: 11; stroke: #fff; }
.city.hl .halo { fill: var(--accent); opacity: .3; r: 18; }
.city.hl text { fill: var(--accent); font-size: 15px; }

/* Goal reminder and introduction */
.goal { background: #2a2208; border: 1px solid #5c4a10; border-radius: 9px; padding: 8px 10px; font-size: 12.5px; line-height: 1.4; color: #f3e3b0; margin-bottom: 4px; }
.goal strong { color: var(--accent); }
#status .btn.help { margin-left: auto; font-weight: 500; font-size: 13px; background: none; }
#modal-box .lead { font-size: 16px; margin: 0 0 6px; }
#modal-box h3 { margin-top: 14px; }
ul.intro { margin: 6px 0 0; padding-left: 18px; }
ul.intro li { margin-bottom: 5px; font-size: 14px; color: #c5d2df; }
ul.intro strong { color: var(--text); }
a.btn { text-decoration: none; text-align: center; }

/* Mode picker and Tycoon mode */
.mode-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.mode { text-align: left; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); color: var(--muted); font: inherit; cursor: pointer; }
.mode strong { display: block; color: var(--text); margin-bottom: 2px; }
.mode span { font-size: 12px; line-height: 1.35; display: block; }
.mode.on { border-color: var(--accent); background: #2a2208; }
.mode.on strong { color: var(--accent); }
.mode:disabled { cursor: default; }
.mode:disabled:not(.on) { opacity: .5; }
.chip { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 16px; text-align: center; min-width: 110px; }
.chip small { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.chip strong { font-size: 20px; font-variant-numeric: tabular-nums; }
#tycoon-panel { display: flex; flex-direction: column; }
#tycoon-panel .btn { flex: none; width: 100%; margin-bottom: 6px; }
.btn.up { text-align: left; white-space: normal; }
.btn.up strong { display: block; }
.btn.up span { font-size: 12px; font-weight: 500; color: var(--muted); }
.hint.tight { margin: 0 0 8px; font-size: 12px; }
.markets { list-style: none; margin: 0 0 8px; padding: 0; }
.markets li { display: flex; justify-content: space-between; gap: 6px; padding: 5px 8px; border-radius: 7px; background: var(--bg); margin-bottom: 3px; font-size: 12.5px; border: 1px solid transparent; cursor: default; }
.markets li:hover { border-color: var(--accent); }
.markets li.done { color: #7ee2a0; }
.markets .v { color: var(--muted); white-space: nowrap; }
.markets li.done .v { color: #7ee2a0; font-weight: 700; }
.markets li.good { display: block; background: none; padding: 7px 2px 2px; }
.markets li.good strong { display: block; font-size: 13px; }
.markets li.good span { color: var(--muted); font-size: 11.5px; }
#board.tycoon .route.open.can rect { fill-opacity: .8; stroke: rgba(0, 0, 0, .55); stroke-width: 1.2; }
#board.tycoon .route.open:not(.can) rect { fill-opacity: .28; }
#board.tycoon .route.open:hover rect { fill-opacity: 1; stroke: #fff; }
#board.tycoon .city { cursor: pointer; }
#board.tycoon .city:hover .dot { stroke: var(--accent); }
.stations { pointer-events: none; }
.station { pointer-events: auto; }
#tycoon-panel .bank .btn { width: auto; flex: 1; margin-bottom: 0; }
#tycoon-panel .bank { margin: 0 0 6px; }
#popover p.note { color: var(--accent); }
.goods { display: none; pointer-events: none; }
#board.tycoon .goods { display: block; }
.goods .badge { pointer-events: auto; }
.goods .badge circle { fill: #0b1119; stroke: #3a4c62; stroke-width: 1.5; }
.goods .badge.buys circle { fill: #2a2208; stroke: var(--accent); stroke-width: 2.5; }
.goods .badge text { font-size: 14px; }

#popover { position: fixed; z-index: 30; background: var(--panel); border: 1px solid var(--accent); border-radius: 11px; padding: 10px; min-width: 190px; box-shadow: 0 8px 30px rgba(0, 0, 0, .55); }
#popover h4 { margin: 0 0 2px; font-size: 14px; }
#popover p { margin: 0 0 8px; font-size: 12px; color: var(--muted); }
#popover .btn { display: flex; width: 100%; margin-top: 5px; align-items: center; gap: 8px; padding: 8px 10px; text-align: left; }
.swatch { width: 16px; height: 16px; border-radius: 4px; flex: none; border: 1px solid rgba(255, 255, 255, .3); }
#modal { position: fixed; inset: 0; z-index: 40; background: rgba(5, 9, 14, .72); display: flex; align-items: center; justify-content: center; padding: 14px; }
#modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; }
.pick { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; margin-bottom: 7px; cursor: pointer; background: var(--bg); }
.pick input { width: auto; }
.pick.on { border-color: var(--accent); }
.pick .v { margin-left: auto; font-weight: 700; color: var(--accent); }
table.results { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 14px; }
table.results th, table.results td { padding: 6px 5px; text-align: right; border-bottom: 1px solid var(--line); }
table.results th:first-child, table.results td:first-child { text-align: left; }
table.results th { color: var(--muted); font-weight: 500; font-size: 12px; }
table.results tr.win td { color: var(--accent); font-weight: 700; }
#toast { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); z-index: 50; background: #0b1119; border: 1px solid var(--accent); padding: 9px 16px; border-radius: 99px; font-weight: 600; max-width: 90vw; }
#conn { position: fixed; top: 8px; left: 50%; transform: translateX(-50%); z-index: 60; background: var(--red); color: #fff; padding: 5px 14px; border-radius: 99px; font-size: 13px; font-weight: 600; }

/* Static pages */
.page { max-width: 760px; margin: 0 auto; padding: 16px 16px 40px; }
.page h2 { margin-top: 1.6em; color: var(--accent); }
.page table { border-collapse: collapse; }
.page td, .page th { border: 1px solid var(--line); padding: 5px 12px; text-align: center; }

@media (max-width: 1000px) {
  #game { display: flex; flex-direction: column; height: auto; }
  #board-wrap { height: auto; order: 1; }
  #board { min-height: 0; padding: 2px; }
  #board svg { height: auto; }
  #side-right { order: 2; border: none; border-top: 1px solid var(--line); overflow: visible; }
  #side-left { order: 3; border: none; border-top: 1px solid var(--line); overflow: visible; }
  .feed { max-height: 160px; }
  .about-grid { grid-template-columns: 1fr; }
  .logo { font-size: 44px; }
  .ad-box { display: none; }
  #status { position: sticky; top: 0; z-index: 5; }
}
