:root {
  --bg: #f6f6f4; --card: #fff; --text: #1d1d1f; --muted: #6e6e73;
  --line: #e3e3e0; --accent: #2d5bd7; --ok: #1f9d55; --bad: #c0392b;
  --atk: #d9534f; --heal: #1f9d55; --lose: #e0a526;
  --die: #fdfdfb; --die-edge: #d4d4cf; --pip: #1d1d1f;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151517; --card: #1f1f22; --text: #ececec; --muted: #9a9aa0;
          --line: #333; --accent: #6f93ff; --die: #ececea; --die-edge: #b9b9b4; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
header { display: flex; justify-content: space-between; align-items: center;
         padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--card); }
.brand { font-weight: 600; text-decoration: none; color: var(--text); }
main { max-width: 860px; margin: 24px auto; padding: 0 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px;
        padding: 16px 20px; margin-bottom: 16px; }
.narrow { max-width: 360px; margin: 40px auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.grid .card { margin: 0 0 16px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
.row h2 { margin: 0; }
form { display: grid; gap: 10px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; }
.toggle { cursor: pointer; }
input { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
        background: var(--bg); color: var(--text); }
button { font: inherit; padding: 8px 14px; border: 0; border-radius: 6px;
         background: var(--accent); color: #fff; cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
.muted { color: var(--muted); }
.flash { color: var(--bad); }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li.turn { font-weight: 600; color: var(--accent); }
.list li.dead { color: var(--muted); text-decoration: line-through; }
.status { margin: 0 0 12px; font-weight: 500; }
.caption { margin: 12px 0 0; font-size: 13px; min-height: 1.5em; }
.log { margin: 0; padding-left: 20px; max-height: 260px; overflow: auto; font-size: 13px; color: var(--muted); }
code { font-size: 1.1em; }

/* ---------- score panel */
.score { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 16px;
         padding: 12px 14px; border-radius: 8px; background: var(--bg); }
.big { display: grid; }
.big .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.big b { font-size: 28px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.big b.attack { color: var(--atk); }
.big b.heal { color: var(--heal); }
.big b.lose { color: var(--lose); }
.gauge { grid-column: 1 / -1; display: flex; gap: 2px; margin-top: 6px; padding-bottom: 16px; }
.cell { position: relative; flex: 1; height: 14px; border-radius: 3px; opacity: .3; }
.cell.attack { background: var(--atk); }
.cell.heal { background: var(--heal); }
.cell.lose { background: var(--lose); }
.cell.range { opacity: .7; }
.cell.now { opacity: 1; outline: 2px solid var(--text); outline-offset: 1px; z-index: 1; }
.cell i { position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
          font-size: 10px; font-style: normal; color: var(--muted); }
.hint { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }

/* ---------- dice */
.dice { display: flex; flex-wrap: wrap; gap: 10px; min-height: 64px; margin: 8px 0 14px; }
.die { --s: 52px; width: var(--s); height: var(--s); transition: transform .15s; user-select: none; }
.die.clickable { cursor: pointer; }
.die.clickable:hover { transform: translateY(-2px); }
.die.selected { transform: translateY(-6px); }
.die.kept .face { background: var(--bg); }
.die.kept .pip { background: var(--muted) !important; }
.die.pending { visibility: hidden; }

.face { width: var(--s); height: var(--s); display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
        padding: 18%; gap: 4%; background: var(--die); border: 1px solid var(--die-edge);
        border-radius: 18%; }
.face span { display: block; }
.face .pip { background: var(--pip); border-radius: 50%; }
.flat .face { box-shadow: 0 2px 0 var(--die-edge); }
.die.selected .face { border-color: var(--ok); box-shadow: 0 0 0 3px var(--ok); }
.die.hit .face { border-color: var(--atk); box-shadow: 0 0 0 3px var(--atk); }
.face.v1 .pip { background: var(--atk); }

/* 3D cube */
.cube-die { perspective: 400px; margin: 0 5px; }
.cube { position: relative; width: var(--s); height: var(--s); transform-style: preserve-3d; }
.cube .face { position: absolute; inset: 0; backface-visibility: hidden; }
.cube .f1 { transform: translateZ(calc(var(--s) / 2)); }
.cube .f6 { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); }
.cube .f3 { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); }
.cube .f4 { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); }
.cube .f2 { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); }
.cube .f5 { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); }
.cube-die.selected .face { box-shadow: none; border-color: var(--ok); border-width: 3px; }
.cube-die.hit .face { box-shadow: none; border-color: var(--atk); border-width: 3px; }

/* flying dice layer */
.throw-layer { position: fixed; inset: 0; z-index: 50; pointer-events: none; perspective: 900px; }
.die.flying { --s: 64px; position: absolute; left: 0; top: 0; transform-origin: 0 0;
              filter: drop-shadow(0 12px 10px rgba(0,0,0,.25)); transition: none; }
.die.flying.landing { transition: transform .5s cubic-bezier(.2,.8,.3,1); }
.cube.landing { transition: transform .5s cubic-bezier(.2,.8,.3,1); }
.rolling .actions, .rolling .dice { pointer-events: none; opacity: .6; }
.rolling .dice { opacity: 1; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }

@media (max-width: 520px) {
  .die { --s: 44px; }
  .big b { font-size: 22px; }
}

/* ---------- header, links, admin, misc (v3) */
nav.top { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.langs a { text-decoration: none; padding: 2px 5px; border-radius: 4px; font-size: 12px; color: var(--muted); }
.langs a.current { background: var(--accent); color: #fff; }
.flash.ok { color: var(--ok); }
button.link { background: none; color: var(--accent); padding: 0 4px; }
button.link:hover { text-decoration: underline; }
button.danger { background: var(--bad); }
.danger-text { color: var(--bad) !important; }
form.inline { display: inline; }
.list li > span:last-child { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
select { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
         background: var(--bg); color: var(--text); }
.admin-nav h1 { margin: 0; }
.tabs { display: flex; gap: 14px; }
.admin-nav { margin-bottom: 16px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.table th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.table tr.dead td { color: var(--muted); }
.hform { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.hform label { min-width: 150px; }
.row h2 button.link { font-size: 16px; }
button.danger { justify-self: start; }

/* ---------- rules popup, captcha (v4) */
dialog.rules { max-width: 560px; width: calc(100% - 32px); max-height: 85vh; overflow: auto;
               border: 1px solid var(--line); border-radius: 10px; background: var(--card);
               color: var(--text); padding: 20px 24px; }
dialog.rules::backdrop { background: rgba(0, 0, 0, .45); }
dialog.rules h2 { margin-bottom: 4px; }
dialog.rules h3 { margin: 16px 0 4px; font-size: 14px; }
dialog.rules p, dialog.rules ul { margin: 0; }
dialog.rules ul { padding-left: 20px; }
dialog.rules form { margin-top: 18px; }
.captcha { display: grid; gap: 8px; }
.captcha-img { display: flex; align-items: center; gap: 8px; }
.captcha-img img { border: 1px solid var(--line); border-radius: 6px; }
.captcha input { text-transform: uppercase; letter-spacing: .15em; }
.small { font-size: 13px; }
dialog.rules button { justify-self: start; }
