:root {
  --bg: #302e2b;
  --panel: #262522;
  --panel2: #1f1e1b;
  --text: #e8e6e3;
  --muted: #9b9893;
  --light: #ebecd0;
  --dark: #739552;
  --green: #81b64c;
  --green-d: #5d8a35;
  --guilt: #e6b422;
  --dev: #8e5bd6;
  --berserk: #e0412f;
  --blood: #7a0d0d;
  --calm: #7e8a99;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--panel2);
}
.brand { color: var(--text); text-decoration: none; font-weight: 800; font-size: 20px; }
.logo { color: var(--green); font-size: 26px; }
.muted { color: var(--muted); }
button {
  font: inherit;
  color: var(--text);
  background: #3c3a37;
  border: 0;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  box-shadow: 0 3px 0 #22211f;
}
button:hover { background: #47453f; }
button:active { transform: translateY(2px); box-shadow: 0 1px 0 #22211f; }
button.green { background: var(--green); color: #fff; box-shadow: 0 4px 0 var(--green-d); font-weight: 700; }
button.green:hover { background: #8fc45a; }
button.link { background: none; box-shadow: none; color: var(--green); padding: 0; text-decoration: underline; }
button.big { font-size: 18px; padding: 14px; width: 100%; font-weight: 700; }
button:disabled { opacity: .4; cursor: default; }
input {
  font: inherit;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid #4a4844;
  border-radius: 6px;
  padding: 8px 10px;
}
.card { background: var(--panel); border-radius: 10px; padding: 20px; }

#home {
  max-width: 1080px;
  margin: 24px auto;
  padding: 0 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
#home[hidden], #game[hidden] { display: none; }
.play h1 { margin: 0 0 6px; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 14px 0; color: var(--muted); }
.tcs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.tcs button.on { outline: 2px solid var(--green); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.row .big { font-size: 15px; }
.searching { margin-top: 10px; display: flex; align-items: center; gap: 8px; }
.searching[hidden] { display: none; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 3px solid #555; border-top-color: var(--green);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.openlist { list-style: none; padding: 0; margin: 0; }
.openlist li { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; background: var(--panel2); border-radius: 6px; margin-bottom: 6px; }
.rules h2 { margin-top: 0; }
.rules ul { padding-left: 4px; list-style: none; }
.rules li { margin-bottom: 6px; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; }
.dot.guilt { background: var(--guilt); }
.dot.dev { background: var(--dev); }
.dot.berserk { background: var(--berserk); }
.dot.calm { background: var(--calm); }

#game {
  display: flex;
  gap: 20px;
  justify-content: center;
  padding: 16px;
  align-items: flex-start;
}
.boardcol { width: min(640px, 100%, calc(100vh - 170px)); min-width: 280px; }
.pbar { display: flex; align-items: center; gap: 10px; padding: 8px 2px; }
.pname { font-weight: 700; }
.pstat { flex: 1; font-size: 13px; color: var(--muted); }
.clock {
  font: 700 22px ui-monospace, monospace;
  background: #2b2926;
  color: #888;
  padding: 4px 12px;
  border-radius: 5px;
  min-width: 104px;
  text-align: right;
}
.clock:empty { display: none; }
.clock.run { background: #fff; color: #1b1a18; }
.clock.low { background: #c94a3b; color: #fff; }
.boardwrap { position: relative; }
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  container-type: inline-size;
  border-radius: 4px;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; min-height: 0; overflow: hidden; }
.sq.l { background: var(--light); }
.sq.d { background: var(--dark); }
.sq.last.l { background: #f5f682; }
.sq.last.d { background: #b9ca43; }
.sq.sel.l, .sq.sel.d { background: #f6f669; }
.sq.check { background: radial-gradient(circle, #ff3b2f 0%, #e3271a 35%, transparent 75%), var(--dark); }
.sq .coord { position: absolute; font-size: 11px; font-weight: 700; pointer-events: none; }
.sq .coord.f { right: 3px; bottom: 1px; }
.sq .coord.r { left: 3px; top: 1px; }
.sq.l .coord { color: var(--dark); }
.sq.d .coord { color: var(--light); }
.sq.hint::after {
  content: "";
  position: absolute;
  width: 32%; height: 32%;
  border-radius: 50%;
  background: rgba(0, 0, 0, .14);
  pointer-events: none;
}
.sq.hint.cap::after {
  width: 92%; height: 92%;
  background: none;
  border: 6px solid rgba(0, 0, 0, .14);
}
.pc {
  font-size: 10.5cqw;
  line-height: 1;
  cursor: grab;
  transition: transform .12s;
  position: relative;
  z-index: 1;
  font-family: "Segoe UI Symbol", "DejaVu Sans", "Noto Sans Symbols2", sans-serif;
}
.pc.w { color: #fff; text-shadow: 0 0 1px #000, 0 0 2px #000, 0 2px 2px rgba(0,0,0,.5); -webkit-text-stroke: 1px #333; }
.pc.b { color: #2b2a28; text-shadow: 0 0 1px #000, 0 2px 2px rgba(0,0,0,.4); -webkit-text-stroke: 1px #000; }
.pc.dev { opacity: .65; filter: grayscale(.6); }
.pc.drag { position: fixed; pointer-events: none; z-index: 20; transform: translate(-50%, -50%) scale(1.1); }
.badge {
  position: absolute;
  top: 3px; right: 3px;
  min-width: 18px; height: 18px;
  border-radius: 9px;
  font: 800 11px/18px system-ui, sans-serif;
  text-align: center;
  color: #fff;
  padding: 0 4px;
  z-index: 2;
  pointer-events: none;
  box-shadow: 0 1px 2px rgba(0,0,0,.5);
}
.badge.guilt { background: var(--guilt); color: #3a2c00; }
.badge.dev { background: var(--dev); }
.badge.berserk { background: var(--berserk); }
.badge.blood { background: var(--blood); outline: 2px solid var(--berserk); }
.react {
  position: absolute;
  left: 4px; bottom: 4px;
  width: 9px; height: 9px;
  border-radius: 50%;
  z-index: 2;
  pointer-events: none;
  border: 1px solid rgba(0,0,0,.4);
}
.react.devastated { background: var(--dev); }
.react.guilt { background: var(--guilt); }
.react.unaffected { background: var(--calm); }
.react.berserk { background: var(--berserk); }
.sq.extra { box-shadow: inset 0 0 0 4px var(--berserk); }
.sq.shamed::before {
  content: "";
  position: absolute; inset: 0;
  background: repeating-linear-gradient(45deg, rgba(142, 91, 214, .18) 0 6px, transparent 6px 12px);
  pointer-events: none;
}

.promo, .dice {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.45);
  z-index: 10;
  gap: 8px;
}
.promo[hidden], .dice[hidden] { display: none; }
.promo .pc { font-size: 52px; }
.promo button { font-size: 52px; width: 84px; height: 84px; padding: 0; background: var(--light); }
.dice { flex-direction: column; pointer-events: none; }
.die {
  width: 96px; height: 96px;
  background: #fff;
  color: #222;
  border-radius: 16px;
  font: 800 54px/96px system-ui;
  text-align: center;
  box-shadow: 0 6px 0 #bbb, 0 10px 30px rgba(0,0,0,.5);
  animation: roll .7s ease-out;
}
.dice .what { margin-top: 18px; font-size: 22px; font-weight: 800; text-shadow: 0 2px 4px #000; text-align: center; padding: 0 10px; }
@keyframes roll {
  0% { transform: rotate(-540deg) scale(.3); }
  70% { transform: rotate(20deg) scale(1.1); }
  100% { transform: rotate(0) scale(1); }
}

.side { width: 360px; display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - 90px); }
.status { font-weight: 800; font-size: 18px; }
.status small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }
.copyrow { display: flex; gap: 6px; }
.copyrow input { flex: 1; min-width: 0; }
.invite p { margin: 0 0 6px; }
.info { background: var(--panel2); border-radius: 6px; padding: 8px 10px; font-size: 13px; min-height: 40px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.actions button[hidden] { display: none; }
#pass { width: 100%; }
.log {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  margin: 0;
  padding: 6px 8px 6px 32px;
  background: var(--panel2);
  border-radius: 6px;
  font-size: 13px;
}
.log li { margin: 2px 0; }
.log .mv { font-weight: 700; font-family: ui-monospace, monospace; }
.log .ev { color: var(--muted); display: block; font-size: 12px; }
.log .ev.roll { color: var(--guilt); }
.log li.sys { list-style: none; margin-left: -24px; }
.chat { display: flex; flex-direction: column; gap: 6px; }
.chatlog { height: 110px; overflow-y: auto; font-size: 13px; background: var(--panel2); border-radius: 6px; padding: 6px 8px; }
.chatlog .sys { color: var(--muted); font-style: italic; }
#chatin { width: 100%; }
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: #111;
  padding: 10px 18px;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  z-index: 50;
}

@media (max-width: 900px) {
  #home { grid-template-columns: 1fr; }
  #game { flex-direction: column; align-items: center; padding: 8px 16px; }
  .boardcol { width: 100%; }
  .side { width: 100%; max-height: none; }
}
