:root {
  --bg: #2b1d14;
  --bg2: #3a281c;
  --text: #f6ead9;
  --muted: #c9b49a;
  --accent: #e9a23b;
  --accent-text: #2b1d14;
  --light: #ecd3a8;
  --dark: #8a5a35;
  --dark-sel: #c48b3f;
  --target: rgba(120, 230, 120, .85);
  --last: rgba(255, 214, 90, .35);
  --err: #ff8a7a;
  --ok: #67d46b;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }

.screen {
  min-height: 100%;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 16px);
  display: flex; flex-direction: column; align-items: center;
}

/* ---------- главный экран ---------- */
#home { justify-content: center; gap: 12px; max-width: 420px; margin: 0 auto; }
h1 { margin: 4px 0 10px; font-size: 40px; letter-spacing: 1px; }
.logo { display: flex; gap: 10px; }
.logo .pc { position: relative; width: 64px; height: 64px; transform: none; }
.name { width: 100%; color: var(--muted); font-size: 15px; display: flex; flex-direction: column; gap: 6px; }
input {
  font: inherit; color: var(--text); background: var(--bg2); border: 1px solid #5a4330;
  border-radius: 12px; padding: 12px 14px; outline: none; width: 100%;
  -webkit-user-select: text; user-select: text;
}
input:focus { border-color: var(--accent); }
.big {
  width: 100%; padding: 15px; border-radius: 14px; font-size: 18px; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
}
.big:active { filter: brightness(.9); }
.big.alt { background: var(--bg2); color: var(--text); border: 1px solid #5a4330; }
.join { display: flex; gap: 8px; width: 100%; }
.join input { width: 96px; flex: none; text-align: center; font-size: 22px; letter-spacing: 3px; }
.join .big { flex: 1; }
.err { color: var(--err); min-height: 1.3em; margin: 0; text-align: center; }
.hint { color: var(--muted); font-size: 14px; text-align: center; margin: 0; }

/* ---------- игра ---------- */
#game { gap: 10px; }
.bar { width: 100%; max-width: 560px; display: flex; align-items: center; gap: 8px; min-height: 48px; }
.icon { font-size: 34px; line-height: 1; width: 44px; height: 44px; background: none; color: var(--muted); padding: 0 0 4px; }
.who { flex: 1; min-width: 0; }
.line { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 7px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #777; flex: none; }
.dot.on { background: var(--ok); }
.score { color: var(--muted); font-size: 14px; }
.tag { color: var(--muted); font-size: 14px; background: var(--bg2); padding: 4px 10px; border-radius: 8px; }
.tag:empty { display: none; }
.net { width: 100%; max-width: 560px; background: #6b2b20; color: #ffd9d2; text-align: center; border-radius: 10px; padding: 6px; font-size: 14px; }

.boardwrap { width: 100%; max-width: 560px; }
.board {
  position: relative; width: 100%; aspect-ratio: 1;
  border-radius: 10px; overflow: hidden;
  box-shadow: 0 0 0 6px #5b3a22, 0 10px 30px rgba(0, 0, 0, .5);
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
}
.sq { background: var(--light); position: relative; }
.sq.d { background: var(--dark); }
.sq.last::after { content: ""; position: absolute; inset: 0; background: var(--last); }
.sq.sel { background: var(--dark-sel); }
.sq.tgt::before {
  content: ""; position: absolute; left: 50%; top: 50%; width: 32%; height: 32%;
  transform: translate(-50%, -50%); border-radius: 50%; background: var(--target); z-index: 3;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, .15);
}

.pc {
  position: absolute; width: 12.5%; height: 12.5%; left: 0; top: 0;
  transition: transform .18s ease-out, opacity .25s;
  pointer-events: none; z-index: 2;
}
.pc::before {
  content: ""; position: absolute; inset: 9%; border-radius: 50%;
  box-shadow: 0 3px 4px rgba(0, 0, 0, .45), inset 0 -3px 0 rgba(0, 0, 0, .25);
}
.pc::after {
  content: ""; position: absolute; inset: 24%; border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, .18);
}
.pc.w::before { background: radial-gradient(circle at 35% 30%, #fffdf6, #e9e0cc 60%, #cbbd9f); }
.pc.b::before { background: radial-gradient(circle at 35% 30%, #6a4a3a, #2d1c14 60%, #170d08); }
.pc.b::after { border-color: rgba(255, 255, 255, .12); }
.pc.k::after {
  inset: 22%; border: 0;
  background: center / 100% no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23d99a2b' d='M3 18h18l-1.5-10-4.5 4-3-7-3 7-4.5-4z'/%3E%3C/svg%3E");
}
.pc.cap { opacity: .35; }
.pc.gone { opacity: 0; }
.pc.must::before { box-shadow: 0 0 0 3px var(--accent), 0 3px 4px rgba(0, 0, 0, .45); }
.pc.moving { z-index: 4; }

.status { font-size: 20px; font-weight: 600; text-align: center; min-height: 1.4em; }
.status.mine { color: var(--accent); }
.wait { text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bigcode { font-size: 54px; font-weight: 700; letter-spacing: 8px; color: var(--text); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; width: 100%; max-width: 560px; }
.small {
  padding: 11px 16px; border-radius: 12px; background: var(--bg2); border: 1px solid #5a4330; font-size: 16px;
}
.small.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.small:active { filter: brightness(.9); }
.small:disabled { opacity: .45; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%);
  background: #000c; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px; z-index: 10;
  max-width: calc(100% - 32px); text-align: center;
}

/* альбомная ориентация / планшет: доска поменьше, чтобы влезала по высоте */
@media (orientation: landscape) and (max-height: 600px) {
  .boardwrap { max-width: calc(100vh - 150px); }
}
