:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #cbd5e1;
  --x: #1d4ed8;
  --o: #dc2626;
  --win: #fde68a;
  --btn: #0f172a;
  --btn-hover: #1e293b;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(130deg, #e2e8f0, var(--bg));
  color: var(--text);
}

body {
  padding: 12px;
}

.app {
  width: min(980px, 100%);
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.09);
  padding: 14px;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.top-bar h1 {
  margin: 0;
  font-size: 1.35rem;
}

.pre-join-gr {
  display: flex;
  gap: 8px;
  width: min(640px, 100%);
}

.rule-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #cbd5e1;
  transition: background-color 0.2s ease;
  cursor: pointer;
}

.slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.22);
  transition: transform 0.2s ease;
}

.switch input:checked + .slider {
  background: #0ea5e9;
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

.post-join-gr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: min(420px, 100%);
}

.hidden {
  display: none !important;
}

.room-pill {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: .5rem;
  padding: .5rem;
  background: #f8fafc;
  font-weight: 600;
}

.room-pill span {
  letter-spacing: 0.06em;
}

input,
button {
  font: inherit;
  border-radius: 8px;
  padding: 10px 12px;
}

input {
  flex: 1;
  min-width: 120px;
  border: 1px solid var(--border);
}

button {
  border: 0;
  background: var(--btn);
  color: #fff;
  cursor: pointer;
}

button:hover {
  background: var(--btn-hover);
}

#leave-room-btn {
  background: #b91c1c;
  white-space: nowrap;
}

#leave-room-btn:hover {
  background: #991b1b;
}

.status {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(200px, 1fr));
  gap: 6px 14px;
}

.status p {
  margin: 0;
}

.turn-line {
  visibility: hidden;
  min-height: 24px;
}

.turn-line.visible {
  visibility: visible;
}

.ratio-line {
  grid-column: 1 / -1;
  text-align: center;
}

.ratio-x {
  color: var(--x);
  font-weight: 700;
}

.ratio-o {
  color: var(--o);
  font-weight: 700;
}

.board-wrap {
  margin-top: 14px;
  max-height: calc(100vh - 260px);
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}

.board {
  --size: 15;
  --cell: 34px;
  width: fit-content;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(var(--size), var(--cell));
  grid-template-rows: repeat(var(--size), var(--cell));
  border: 1px solid var(--border);
}

.cell {
  border: 1px solid var(--border);
  display: flex;
  justify-content: center;
  place-items: center;
  font-size: 1rem;
  font-weight: 700;
  background: #fff;
  user-select: none;
  cursor: pointer;
}

.cell.x {
  color: var(--x);
}

.cell.o {
  color: var(--o);
}

.cell.win {
  background: var(--win);
}

.afk-wrap {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 8px;
  background: #e5e7eb;
  z-index: 40;
}

.afk-bar {
  width: 100%;
  height: 100%;
  background: hsl(120, 85%, 40%);
  transition: width 0.3s linear, background-color 0.3s linear;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 10px 14px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.toast.show {
  opacity: 1;
}

@media (max-width: 768px) {
  .app {
    padding: 10px;
  }

  .pre-join-gr,
  .post-join-gr,
  .rule-option {
    width: 100%;
  }

  .pre-join-gr {
    flex-wrap: wrap;
  }

  #create-room-btn,
  #join-room-btn,
  input {
    width: 100%;
  }

  .status {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status p:nth-child(1),
  .status p:nth-child(2) {
    grid-column: 1;
  }

  .status p:nth-child(3),
  .status p:nth-child(4) {
    grid-column: 2;
  }

  .board {
    --cell: min(6.1vw, 30px);
  }

  .board-wrap {
    max-height: calc(100vh - 300px);
  }
}
