:root {
  --bg: #10141a;
  --card: #1a212b;
  --card2: #222b37;
  --line: #2e3a49;
  --text: #e8edf3;
  --muted: #8fa0b3;
  --accent: #f0b429;
  --green: #2fbf71;
  --red: #e5534b;
  --blue: #4a90d9;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { margin: 0 0 4px; font-size: 30px; }
h2 { margin: 0 0 10px; }
h3 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
a { color: var(--blue); }
.hidden { display: none !important; }
.sub { color: var(--muted); margin: 0 0 14px; }
.hint { color: var(--muted); font-size: 13px; }
.spacer { flex: 1; }

button {
  background: var(--card2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 14px; font-size: 14px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #1a1206; font-weight: 700; }
button.small { padding: 4px 8px; font-size: 12px; }
input, select {
  background: #0d1117; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 14px; width: 100%;
}
label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
label input { margin-top: 4px; }
.row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 14px 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.code { font-weight: 800; letter-spacing: .15em; background: #0d1117; border: 1px solid var(--line); padding: 2px 10px; border-radius: 6px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.center-card { max-width: 430px; margin: 8vh auto 0; }

.badge { padding: 2px 8px; border-radius: 20px; font-size: 12px; background: var(--card2); border: 1px solid var(--line); }
.badge.bad { color: var(--red); border-color: var(--red); }
.badge.good { color: var(--green); border-color: var(--green); }

/* ---------- topbar ---------- */
#topbar {
  display: flex; gap: 12px; align-items: center; padding: 10px 14px;
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 800; font-size: 18px; }

/* ---------- layout ---------- */
#layout { display: grid; grid-template-columns: 1fr 320px; gap: 14px; padding: 14px; max-width: 1400px; margin: 0 auto; }
main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
aside { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.rules-body { font-size: 13px; color: var(--muted); }
.rules-body b { color: var(--text); }

/* ---------- players strip ---------- */
#playersStrip { display: flex; gap: 8px; flex-wrap: wrap; }
.pchip {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 10px; min-width: 130px; flex: 1;
}
.pchip.turn { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.pchip.you { background: var(--card2); }
.pchip.out { opacity: .45; }
.pname { font-weight: 700; display: flex; justify-content: space-between; gap: 6px; }
.pname .offline { color: var(--red); font-weight: 400; font-size: 11px; }
.pcash { color: var(--green); font-weight: 600; }
.pworth { color: var(--muted); font-size: 12px; }
.phold { display: flex; gap: 5px; margin-top: 4px; flex-wrap: wrap; }
.phold span { font-size: 11px; padding: 1px 6px; border-radius: 4px; color: #fff; }

/* ---------- board ---------- */
#boardRow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.co { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.co .cohead { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.co .coname { font-weight: 800; font-size: 14px; }
.co .price { font-size: 26px; font-weight: 800; }
.co .market { color: var(--muted); font-size: 12px; }
.track { position: relative; height: 10px; background: #0d1117; border-radius: 5px; margin-top: 10px; border: 1px solid var(--line); }
.track .dot { position: absolute; top: -4px; width: 16px; height: 16px; border-radius: 50%; border: 2px solid #fff; transform: translateX(-50%); transition: left .4s; }
.track .lim { position: absolute; top: -16px; font-size: 10px; color: var(--muted); transform: translateX(-50%); }

/* ---------- action panel ---------- */
#actionPanel { }
#actionPanel .ap-line { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#actionPanel .ap-title { font-weight: 700; }
.finalwarn { color: var(--accent); font-weight: 700; }
select { width: auto; min-width: 150px; }

/* ---------- portfolio ---------- */
#portfolioRow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.pf { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; border-top-width: 4px; }
.pf .mine { font-size: 20px; font-weight: 800; }
.pf .val { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.pf .tradebtns { display: flex; gap: 4px; flex-wrap: wrap; }
.pf .tradebtns button { padding: 5px 8px; font-size: 12px; flex: 1; min-width: 52px; }
.pf .locked { color: var(--red); font-size: 11px; display: block; margin-top: 6px; }

/* ---------- hand ---------- */
#handCard h3 { margin-bottom: 10px; }
#handRow { display: flex; gap: 10px; flex-wrap: wrap; }
.mcard {
  width: 168px; background: #f4f1e6; color: #1c2430; border-radius: 8px; padding: 10px;
  border: 2px solid transparent; cursor: default; position: relative;
}
.mcard.clickable { cursor: pointer; }
.mcard.clickable:hover { border-color: var(--blue); }
.mcard.selected { border-color: var(--accent); box-shadow: 0 0 12px rgba(240,180,41,.4); }
.mcard .kind { position: absolute; top: 8px; right: 8px; font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 4px; background: #1c2430; color: #f4f1e6; }
.mcard .up { font-weight: 700; }
.mcard .dn { margin-top: 6px; padding-top: 6px; border-top: 1px dashed #999; }
.mcard .arrow-up { color: #0a7d2c; font-weight: 800; }
.mcard .arrow-dn { color: #b3241c; font-weight: 800; }
.mcard .coname { font-weight: 800; }

/* ---------- log & chat ---------- */
#logBox, #chatMsgs { height: 260px; overflow-y: auto; font-size: 13px; display: flex; flex-direction: column; gap: 3px; }
#logBox div { border-bottom: 1px dotted var(--line); padding-bottom: 2px; color: var(--muted); }
#logBox div:last-child { color: var(--text); }
#chatForm { display: flex; gap: 6px; margin-top: 8px; }
#chatMsgs .sys { color: var(--muted); font-style: italic; }
#chatMsgs .who { font-weight: 700; margin-right: 4px; }

/* ---------- modal & toast ---------- */
#modalRoot .overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 20;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
#modalRoot .modal { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; max-width: 460px; width: 100%; }
#modalRoot .modal h2 { margin-bottom: 8px; }
#modalRoot .modal .row { margin-top: 14px; }
#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #33150f; color: #ffb4a8; border: 1px solid var(--red);
  padding: 10px 16px; border-radius: 8px; z-index: 30; opacity: 0; transition: opacity .25s;
  pointer-events: none; max-width: 90vw;
}
#toast.show { opacity: 1; }

table.standings { width: 100%; border-collapse: collapse; margin-top: 10px; }
table.standings td, table.standings th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
table.standings tr:first-child td { color: var(--accent); font-weight: 800; }

/* ---------- lobby ---------- */
.player-list { list-style: none; padding: 0; margin: 0 0 14px; }
.player-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--card2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin-bottom: 6px; }
.player-list .tag { font-size: 11px; color: var(--muted); }

@media (max-width: 980px) {
  #layout { grid-template-columns: 1fr; }
  #boardRow { grid-template-columns: repeat(2, 1fr); }
  #portfolioRow { grid-template-columns: repeat(2, 1fr); }
}
