:root {
  --paper: #fbf6ea;
  --ink: #3a342c;
  --muted: #8a8175;
  --red: #e05252;
  --blue: #3d6fe0;
  --line: #d9c9ae;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: "Comic Sans MS", "Segoe Print", "Bradley Hand", "Chalkboard SE", cursive, sans-serif;
  color: var(--ink);
  background: var(--paper);
  background-image:
    linear-gradient(rgba(0,0,0,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,0.025) 1px, transparent 1px);
  background-size: 22px 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 16px;
  user-select: none;
}

.screen {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.hidden { display: none !important; }

.title {
  font-size: 2.2rem;
  text-align: center;
  transform: rotate(-1.5deg);
}
.title.small { font-size: 1.6rem; }

.subtitle { color: var(--muted); font-size: 0.95rem; text-align: center; }

.card {
  width: 100%;
  background: #fffdf7;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.06);
  transform: rotate(0.6deg);
}

.card label { font-size: 0.95rem; color: var(--muted); }

input {
  font-family: inherit;
  font-size: 1rem;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
  width: 100%;
}
input:focus { border-color: var(--blue); }

.room-id { text-transform: uppercase; letter-spacing: 2px; text-align: center; }

.row { display: flex; gap: 8px; }

.btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 11px 18px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}
.btn:hover { box-shadow: 2px 2px 0 rgba(0,0,0,0.15); }
.btn:active { transform: translate(1px, 1px); box-shadow: none; }
.btn.primary { background: var(--ink); color: #fff; }

.divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 0.85rem;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.err { color: var(--red); font-size: 0.9rem; min-height: 1.2em; text-align: center; }

.room-info {
  font-size: 1.05rem; text-align: center;
}
.copy { color: var(--blue); cursor: pointer; font-size: 0.8rem; }

.players {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 8px;
}
.player {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 2px solid transparent;
}
.player.active { border-color: var(--line); background: #fffdf7; }
.mark { font-size: 1.6rem; line-height: 1; }
.mark-x { color: var(--red); }
.mark-o { color: var(--blue); }
.pname { font-size: 0.9rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pscore { font-size: 0.78rem; color: var(--muted); }
.pscore::before { content: "Побед: "; }

.turn-box { text-align: center; flex: 1.2; }
.turn { font-size: 0.95rem; }
.timer {
  font-size: 1.8rem; font-weight: 700;
  transition: color 0.2s;
}
.timer.low { color: var(--red); animation: pulse 0.5s infinite alternate; }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.15); } }

.board-wrap {
  position: relative;
  width: min(82vw, 340px);
  aspect-ratio: 1;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  background: #fffdf7;
  border: 3px solid var(--ink);
  border-radius: 8px;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.08);
  overflow: hidden;
}

.cell {
  position: relative;
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.cell:nth-child(3n) { border-right: none; }
.cell:nth-child(n+7) { border-bottom: none; }

.mark-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.strike {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.strike-line {
  stroke: #f4b400;
  stroke-width: 14;
  stroke-linecap: round;
  opacity: 0.85;
  stroke-dasharray: 600;
  stroke-dashoffset: 600;
  animation: draw 0.5s ease-out forwards;
}

.stroke {
  fill: none;
  stroke-width: 9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mark-svg.x .stroke { stroke: var(--red); }
.mark-svg.o .stroke { stroke: var(--blue); }

.stroke.d1 {
  stroke-dasharray: 700;
  stroke-dashoffset: 700;
  animation: draw 0.3s ease-out forwards;
}
.stroke.d2 {
  stroke-dasharray: 700;
  stroke-dashoffset: 700;
  animation: draw 0.3s ease-out 0.14s forwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } }

.result {
  font-size: 1.3rem;
  text-align: center;
  color: var(--ink);
  background: #fffdf7;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 12px 18px;
  transform: rotate(0.8deg);
}
