:root {
  --bg: #14110f; --bg2: #1d1814; --panel: #241e19; --line: #3b3027; --text: #e8dcc2; --muted: #9c8f78;
  --gold: #c9a24b; --gold2: #e3c476; --red: #b03a3a; --green: #5c9a5a; --blue: #5b7fa6;
  --radius: 12px; --tap: 48px;
}
* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow-x: hidden; }
body { background: radial-gradient(1200px 600px at 50% -200px, #2a2018, var(--bg)); }
h1, h2, h3, h4 { font-family: Georgia, "Times New Roman", serif; color: var(--gold2); margin: 0 0 .5rem; font-weight: 600; }
h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; margin-top: 1rem; } h4 { font-size: .85rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 1rem 0 .4rem; }
.muted { color: var(--muted); } .center { text-align: center; } .err { color: #e07a7a; }
small { font-size: .78rem; }

/* controls */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=number], select, textarea {
  width: 100%; min-height: var(--tap); padding: .6rem .75rem; background: var(--bg2); border: 1px solid var(--line);
  border-radius: 10px; outline: none; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(201,162,75,.25); }
.btn { min-height: var(--tap); padding: .5rem 1.1rem; background: var(--panel); border: 1px solid var(--gold);
  color: var(--gold2); border-radius: 10px; cursor: pointer; font-weight: 600; }
.btn:hover:not(:disabled) { background: #33281d; }
.btn.primary { background: linear-gradient(#b8923a, #8f6c25); color: #1a1208; border-color: #d8b25a; }
.btn.primary:hover:not(:disabled) { background: linear-gradient(#c9a24b, #9d7a2d); }
.btn.wide { width: 100%; margin-top: .75rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn { min-width: var(--tap); min-height: var(--tap); background: transparent; border: 0; color: var(--gold2); font-size: 1.3rem; cursor: pointer; }
.tag { display: inline-block; padding: .15rem .55rem; border-radius: 999px; background: #2e261e; border: 1px solid var(--line); font-size: .8rem; margin: 0 .25rem .25rem 0; }
.tag.bad { border-color: var(--red); color: #e59a9a; }
.tag.good { border-color: #4f8a4f; color: #9ad39a; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }

/* start screen */

.brand { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.brand h1 { font-size: 1.7rem; margin: 0; }
.langsw { display: flex; gap: .25rem; }
.langsw button { min-width: 44px; min-height: 40px; background: transparent; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); cursor: pointer; }
.langsw button.on { color: var(--gold2); border-color: var(--gold); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.field { display: block; margin-bottom: .75rem; }
.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.sessions { list-style: none; margin: 0; padding: 0; }
.sessions li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .6rem 0; border-top: 1px solid var(--line); }
.sessions li:first-child { border-top: 0; }
.s-info { display: flex; flex-direction: column; min-width: 0; }
.s-info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.abil-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: .75rem; }
.abil-in { display: block; text-align: center; font-size: .8rem; color: var(--muted); }
.abil-in input { text-align: center; padding: .4rem; }
.chip-check { display: inline-flex; align-items: center; min-height: 40px; padding: 0 .8rem; border: 1px solid var(--line); border-radius: 999px; background: var(--bg2); cursor: pointer; font-size: .85rem; }
.chip-check input { position: absolute; opacity: 0; pointer-events: none; }
.chip-check.on { border-color: var(--gold); color: var(--gold2); background: #2e2517; }

/* game layout */
.game { height: 100dvh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .25rem; padding: 0 .25rem; background: var(--bg2); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
.topbar .title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.topbar .title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: Georgia, serif; color: var(--gold2); }
.conn.open { color: var(--green); } .conn.connecting { color: var(--gold); } .conn.closed { color: #e07a7a; }
.game-body { flex: 1; min-height: 0; display: flex; position: relative; }
.chat-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat { flex: 1; overflow-y: auto; padding: .75rem 12px; display: flex; flex-direction: column; gap: .6rem; }
.card-col { display: none; width: 300px; overflow-y: auto; padding: .75rem; background: var(--bg2); border-left: 1px solid var(--line); }
.card-col.open { display: block; position: absolute; inset: 0 0 0 auto; width: min(320px, 88vw); z-index: 5; box-shadow: -8px 0 24px rgba(0,0,0,.6); }
@media (min-width: 860px) {
  .card-col { display: block; position: static; box-shadow: none; }
  .card-toggle { display: none; }
}

/* messages */
.msg { max-width: 100%; }
.k-action { align-self: flex-end; max-width: 92%; background: #2d2a1d; border: 1px solid #5a4d25; border-radius: 12px 12px 2px 12px; padding: .5rem .75rem; }
.who { font-size: .8rem; color: var(--gold2); font-weight: 600; margin-bottom: .15rem; display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.narr { font-family: Georgia, "Times New Roman", serif; font-size: 1.05rem; line-height: 1.6; background: var(--panel); border-left: 3px solid var(--gold); border-radius: 4px 10px 10px 4px; padding: .7rem .9rem; }
.sys { color: var(--muted); font-size: .88rem; text-align: center; }
.k-error .sys { color: #e07a7a; }
.streaming .narr::after { content: "▌"; color: var(--gold); animation: blink 1s steps(2, start) infinite; margin-left: 1px; }
@keyframes blink { to { visibility: hidden; } }
.dice-chip { align-self: center; display: inline-block; max-width: 100%; padding: .45rem .9rem; border-radius: 12px; background: #1f2630; border: 1px solid var(--blue); text-align: center; }
.dice-chip.good { border-color: var(--green); background: #1b2a1d; }
.dice-chip.bad { border-color: var(--red); background: #2c1b1b; }
.dc-main { font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.dc-sub { font-size: .75rem; color: var(--muted); }
.k-roll { display: flex; justify-content: center; }
.judge-line { text-align: center; }
.status-line { color: var(--muted); font-size: .9rem; text-align: center; }
.dots::after { content: "…"; animation: dots 1.2s infinite; }
@keyframes dots { 50% { opacity: .2; } }

/* picker, roll box, composer */
.picker { padding: .6rem 12px; background: var(--bg2); border-top: 1px solid var(--line); }
.picker-head { font-size: .85rem; color: var(--muted); margin-bottom: .4rem; }
.chip { min-height: 44px; padding: 0 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; cursor: pointer; }
.chip:hover { border-color: var(--gold); color: var(--gold2); }
.chip.gm { border-color: var(--gold); color: var(--gold2); }
.rollbox { display: flex; align-items: center; gap: .75rem; padding: .5rem 12px; background: #1f1a12; border-top: 1px solid var(--gold); }
.rb-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.die { width: 56px; height: 56px; flex: none; display: grid; place-items: center; font: 700 1.4rem Georgia, serif; color: var(--gold2);
  background: linear-gradient(135deg, #3a2e1a, #1a1409); border: 2px solid var(--gold);
  clip-path: polygon(50% 0, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%); }
.die.spin { animation: tumble .6s linear infinite; }
@keyframes tumble { to { transform: rotate(360deg); } }
.die.spin span { display: inline-block; animation: untumble .6s linear infinite; }
@keyframes untumble { to { transform: rotate(-360deg); } }
.composer { display: flex; flex-direction: column; gap: .5rem; padding: .6rem 12px calc(.6rem + env(safe-area-inset-bottom)); background: var(--bg2); border-top: 1px solid var(--line); }
.composer .roll { align-self: flex-start; }
.comp-row { display: flex; gap: .5rem; align-items: stretch; }
.comp-row textarea { flex: 1; min-width: 0; resize: none; }

/* character card */
.charcard h2 { display: flex; flex-direction: column; margin-bottom: .6rem; }
.hp-bar { height: 14px; background: #2b1c1c; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.hp-bar i { display: block; height: 100%; background: var(--green); transition: width .4s; }
.hp-bar i.mid { background: #c99a3a; } .hp-bar i.low { background: var(--red); }
.hp-num { margin: .25rem 0 .6rem; font-variant-numeric: tabular-nums; }
.stats { display: flex; gap: .5rem; margin-bottom: .6rem; }
.stat { flex: 1; text-align: center; padding: .4rem; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; }
.stat b { font-size: .7rem; color: var(--muted); text-transform: uppercase; } .stat span { font-size: 1.3rem; font-weight: 700; }
.abil-grid.view { margin: 0; }
.abil { text-align: center; padding: .35rem .2rem; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; line-height: 1.2; }
.abil b { font-size: .7rem; color: var(--gold2); } .abil .v { font-size: 1.1rem; font-weight: 700; } .abil .mod { font-size: .8rem; color: var(--muted); }
.inv { margin: 0; padding-left: 1.1rem; }

.mock-banner { background: #5a3d12; color: #ffe3a3; text-align: center; font-size: .75rem; padding: 2px; }
@media (max-width: 420px) { .row2 { grid-template-columns: 1fr; } }

/* ===== stage 2 ===== */
.page { max-width: 640px; margin: 0 auto; padding: 1rem 16px 3rem; }
.wide-page { max-width: 1280px; }
.grow { flex: 1; min-width: 0; }
.block { display: block; }
.small { font-size: .85rem; }
.phone-only { display: inline-block; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; }
.home-grid { display: grid; gap: 1rem; }
.create-grid { display: grid; gap: 1rem; }
@media (min-width: 900px) {
  .page:not(.wide-page) { max-width: 980px; }
  .home-grid { grid-template-columns: 1fr 1fr; align-items: start; }
  .create-grid { grid-template-columns: 1.2fr 1fr 1fr; align-items: start; }
  .phone-only { display: none; }
}
.linkish { background: none; border: 0; color: var(--gold2); cursor: pointer; padding: .4rem 0; min-height: 40px; }
.rules-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .75rem; }
.rules-grid.ro input, .rules-grid.ro select { opacity: .75; }
.slider-field { margin-bottom: .75rem; }
.slider-field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
.slider-row { display: flex; gap: .75rem; align-items: center; }
.slider-row input[type=range] { flex: 1; accent-color: var(--gold); min-height: 40px; }
.slider-row input[type=number] { width: 84px; flex: none; text-align: center; }
.comp-row input[type=text] { flex: 1; min-width: 0; }

/* room */
.topbar .title small { display: flex; gap: .4rem; align-items: center; color: var(--muted); }
.timer { font: 700 1.1rem Consolas, monospace; color: var(--gold2); padding: 0 .5rem; }
.timer.low { color: #f08a8a; }
.game.combat .topbar { background: #2c1b1b; border-bottom-color: var(--red); }
.init-strip { display: flex; gap: .4rem; align-items: center; overflow-x: auto; padding: .4rem 12px; background: #1a1511; border-bottom: 1px solid var(--line); }
.ini { flex: none; display: flex; flex-direction: column; align-items: center; min-width: 74px; padding: .25rem .5rem; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); font-size: .8rem; line-height: 1.25; }
.ini.now { border: 2px solid var(--gold); background: #2e2517; color: var(--gold2); font-weight: 700; }
.ini.done { opacity: .55; } .ini.foe { color: #f0b0b0; } .ini.down { text-decoration: line-through; opacity: .45; }
.party-col { display: none; width: 260px; flex: none; overflow-y: auto; padding: .75rem; background: var(--bg2); border-right: 1px solid var(--line); }
@media (min-width: 900px) { .party-col { display: flex; flex-direction: column; gap: .5rem; } }
.pc-card { display: flex; flex-direction: column; gap: .3rem; width: 100%; text-align: left; padding: .6rem; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; margin-bottom: .5rem; }
.pc-card.me { border-color: var(--gold); }
.pc-card:hover { border-color: var(--gold2); }
.pc-top { display: flex; justify-content: space-between; gap: .4rem; }
.nearby { padding: .6rem; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; margin: .25rem 0; }
.lobby { flex: 1; overflow-y: auto; padding: .75rem 12px; }
.lobby .panel { max-width: 640px; margin: 0 auto; }
.ord { display: inline-block; min-width: 1.6rem; color: var(--gold2); font-weight: 700; }
.k-action.passive, .msg.passive { opacity: .7; }
.board { max-height: 30vh; overflow-y: auto; padding: .4rem 12px; background: #1a1511; border-top: 1px solid var(--line); }
.board-row { display: flex; align-items: center; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid #2c241d; }
.board-row:last-child { border-bottom: 0; }
.board-row.ready b { color: var(--gold2); }
.small-btn { min-height: 38px; padding: .2rem .7rem; font-size: .85rem; }
.btn.danger { border-color: var(--red); color: #f0b0b0; }
.comp-form { display: flex; flex-direction: column; gap: .5rem; }
.comp-form textarea { resize: none; }
.comp-buttons { display: flex; gap: .5rem; flex-wrap: wrap; }
.comp-buttons .primary { flex: 1; min-width: 120px; }
.combat-comp { border-top: 2px solid var(--gold); background: #1f1a12; }
.chip.on { border-color: var(--gold); color: var(--gold2); background: #2e2517; }
.chip:disabled { opacity: .4; cursor: not-allowed; }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.6); display: flex; justify-content: center; align-items: flex-end; }
.sheet-panel { width: 100%; max-width: 480px; max-height: 92dvh; overflow-y: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 16px 16px 0 0; padding: 1rem; }
.sheet-panel.big { max-width: 980px; }
@media (min-width: 900px) { .overlay { align-items: center; } .sheet-panel { border-radius: 16px; } }
.tabs { display: flex; border-bottom: 1px solid var(--line); margin: .5rem 0 .75rem; }
.tabs button { flex: 1; min-height: 44px; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; }
.tabs button.on { color: var(--gold2); border-bottom-color: var(--gold); font-weight: 700; }
.hp-bar.big { height: 16px; margin-bottom: .6rem; }
.note { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: .5rem .7rem; font-size: .88rem; color: #d9c9a8; }
.skill-row { display: flex; align-items: center; gap: .7rem; width: 100%; min-height: 52px; padding: 0 .75rem; margin-bottom: .4rem; border-radius: 12px; border: 1px solid #8f6c25; background: var(--panel); text-align: left; cursor: pointer; }
.skill-row:disabled { cursor: default; opacity: 1; }
.sk-mod { font: 700 1.15rem Georgia, serif; color: var(--gold2); width: 2.5rem; text-align: right; }
.go { padding: .2rem .6rem; border-radius: 8px; background: #a8842f; color: #1a1208; font-size: .8rem; font-weight: 700; }
.rest-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .25rem .75rem; margin-bottom: .5rem; }
.rs { display: flex; justify-content: space-between; align-items: center; gap: .3rem; min-height: 38px; padding: 0 .4rem; border: 0; border-bottom: 1px solid #2c241d; background: transparent; color: #d9c9a8; font-size: .88rem; cursor: pointer; text-align: left; }
.rs:disabled { cursor: default; }
.char-grid, .admin-grid { display: grid; gap: 1rem; }
@media (min-width: 900px) { .char-grid, .admin-grid { grid-template-columns: 1fr 1fr; } }
.pb-row { display: flex; align-items: center; gap: .5rem; padding: .25rem 0; }
.pb-name { width: 2.6rem; color: var(--gold2); }
.pb-btn { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--gold); background: var(--panel); color: var(--gold2); font-size: 1.3rem; cursor: pointer; }
.pb-btn:disabled { opacity: .3; cursor: not-allowed; }
.pb-val { width: 2rem; text-align: center; font: 700 1.2rem Georgia, serif; }
.pb-mod { width: 2.2rem; color: var(--muted); }
.pack-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-bottom: .6rem; }
.pack { display: flex; flex-direction: column; gap: .25rem; text-align: left; padding: .6rem; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
.pack.on { border-color: var(--gold); background: #2e2517; }
.btn-col { display: flex; flex-direction: column; gap: .5rem; }
