:root {
  --bg: #0f1221;
  --panel: #171a2b;
  --ink: #e8ecff;
  --muted: #a9b1d6;
  --accent: #8fd3ff;
  --accent-2: #ffd28f;
  --safe: #2ec27e;
  --water: #7ccaff;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  --radius: 16px;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  background: radial-gradient(
      1000px 600px at 80% -10%,
      rgba(143, 211, 255, 0.18),
      transparent 40%
    ),
    radial-gradient(
      1200px 800px at 0% 120%,
      rgba(255, 210, 143, 0.12),
      transparent 50%
    ),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Noto Sans KR,
    Helvetica, Arial;
}
#app {
  max-width: 1100px;
  margin: 24px auto;
  padding: 16px;
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
h1 {
  margin: 0;
  font-size: 22px;
}
.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.btn {
  appearance: none;
  border: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: linear-gradient(180deg, #222848, #171a2b);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-weight: 700;
  cursor: pointer;
}
.btn.ghost {
  background: transparent;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #1b2043;
  box-shadow: var(--shadow);
  font-weight: 700;
}
.turn-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}
.turn-dot.B {
  background: var(--accent-2);
}

.wrap {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
}
@media (max-width: 980px) {
  .wrap {
    grid-template-columns: 1fr;
  }
}
.card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

/* sticks */
.sticks {
  display: flex;
  gap: 8px;
}
.stick {
  width: 50px;
  height: 18px;
  border-radius: 999px;
  background: #252a4a;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.stick .face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  color: #09121f;
  background: linear-gradient(180deg, #a7e5ff, #7ccaff);
  opacity: 0;
  transition: 0.25s opacity ease;
}
.stick.on .face {
  opacity: 1;
}
.result {
  min-width: 46px;
  font-weight: 800;
}
#status {
  min-height: 22px;
  font-weight: 700;
  color: var(--muted);
}

/* grid */
.board.card {
  padding: 12px;
}
.grid {
  --cell: 74px;
  display: grid;
  grid-template-columns: repeat(10, var(--cell));
  grid-template-rows: repeat(3, var(--cell));
  gap: 8px;
  justify-content: center;
}
@media (max-width: 720px) {
  .grid {
    --cell: 60px;
    gap: 6px;
  }
}
@media (max-width: 520px) {
  .grid {
    --cell: 54px;
    gap: 6px;
  }
}
.cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  border-radius: 14px;
  background: linear-gradient(180deg, #1c2141, #151937);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.cell.safe::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    180px 100px at 50% 120%,
    rgba(46, 194, 126, 0.22),
    transparent 60%
  );
}
.cell.water::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    180px 100px at 50% 120%,
    rgba(143, 211, 255, 0.25),
    transparent 60%
  );
}
.idx {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 11px;
  color: var(--muted);
}
.glyph {
  position: absolute;
  right: 8px;
  top: 6px;
  font-size: 14px;
  opacity: 0.9;
}
.highlight {
  outline: 3px solid rgba(143, 211, 255, 0.75);
}
.target-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.3px;
  color: #00111a;
  background: rgba(143, 211, 255, 0.22);
  border: 2px dashed rgba(143, 211, 255, 0.7);
  border-radius: 12px;
  pointer-events: none;
}

/* pieces */
.piece {
  position: absolute;
  inset: 8px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 900;
  letter-spacing: 0.3px;
  user-select: none;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.piece.W {
  background: linear-gradient(180deg, #e6f0ff, #cfe0ff);
  color: #09121f;
}
.piece.B {
  background: linear-gradient(180deg, #2b2f4f, #1c203b);
  color: #e7eaff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}
.piece.dim {
  opacity: 0.55;
  filter: saturate(0.5);
}
.piece.can-move {
  box-shadow: 0 0 0 3px rgba(143, 211, 255, 0.8),
    0 0 18px rgba(143, 211, 255, 0.45);
  transform: translateY(-2px);
}

/* floating animation token */
.float-piece {
  position: fixed;
  z-index: 9999;
  width: 58px;
  height: 58px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 900;
}

dialog {
  border: 0;
  border-radius: 16px;
  padding: 0;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  max-width: 720px;
  width: min(92vw, 720px);
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}
.modal {
  padding: 18px;
}
.modal header {
  margin-bottom: 8px;
}
.modal h2 {
  margin: 0;
  font-size: 20px;
}
.modal .body {
  color: var(--muted);
  font-size: 14px;
}
.modal footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
/* 클릭 문제 해결: 특수칸 오버레이가 말 클릭을 가로채지 않도록 */
.cell.safe::after,
.cell.water::after {
  pointer-events: none;
  z-index: 0;
}
.piece {
  z-index: 1;
}
.idx,
.glyph {
  z-index: 2;
  pointer-events: none;
}
/* === Responsive Enhancements === */
/* Fluid board sizing with safe clamps */
.grid {
  --cell: clamp(46px, 8.6vw, 74px);
  gap: clamp(4px, 1.2vw, 8px);
}
.cell {
  border-radius: clamp(10px, 2vw, 14px);
}
.piece {
  inset: clamp(6px, 1.2vw, 8px);
  border-radius: clamp(10px, 2vw, 14px);
}
.target-label {
  border-radius: clamp(10px, 2vw, 12px);
  font-size: clamp(10px, 2.1vw, 11px);
}
.idx {
  font-size: clamp(10px, 1.9vw, 11px);
}
.glyph {
  font-size: clamp(12px, 2.2vw, 14px);
}
header {
  flex-wrap: wrap;
}
.wrap {
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 1020px) {
  .wrap {
    grid-template-columns: 1fr;
  }
}
/* Compact controls on small screens */
@media (max-width: 640px) {
  #app {
    padding: 12px;
  }
  h1 {
    font-size: 18px;
  }
  .btn {
    padding: 9px 10px;
    border-radius: 10px;
  }
  .sticks {
    gap: 6px;
  }
  .stick {
    width: 44px;
    height: 16px;
  }
  .result {
    min-width: 40px;
  }
}
/* Prevent overflow: allow panel to scroll if needed */
.board.card {
  overflow: auto;
}
/* Make overlays non-blocking and ensure pieces get clicks even on small screens */
.cell.safe::after,
.cell.water::after {
  pointer-events: none;
  z-index: 0;
}
.piece {
  z-index: 1;
}
.idx,
.glyph {
  z-index: 2;
  pointer-events: none;
}
/* === Responsive Enhancements === */
/* Board should never exceed screen width */
.board.card {
  overflow: auto;
  max-width: 100%;
}
.grid {
  --cell: 72px;
  gap: 8px;
  justify-content: center;
  max-width: 100%;
}
.grid {
  width: 100%;
}
@media (max-width: 1020px) {
  .wrap {
    grid-template-columns: 1fr;
  }
}
.wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.card {
  width: 100%;
  max-width: 720px;
}
/* Compact controls on small screens */
@media (max-width: 640px) {
  #app {
    padding: 12px;
  }
  h1 {
    font-size: 18px;
  }
  .btn {
    padding: 9px 10px;
    border-radius: 10px;
  }
  .sticks {
    gap: 6px;
  }
  .stick {
    width: 44px;
    height: 16px;
  }
  .result {
    min-width: 40px;
  }
}
.cell.safe::after,
.cell.water::after {
  pointer-events: none;
  z-index: 0;
}
.piece {
  z-index: 1;
}
.idx,
.glyph {
  z-index: 2;
  pointer-events: none;
}
/* === Layout preference: vertical stack & board width cap === */
.wrap {
  grid-template-columns: 1fr !important;
}
.board.card {
  overflow: visible;
}
.grid {
  width: 100%;
  max-width: min(100vw - 32px, 860px); /* never exceed viewport width */
  margin: 0 auto; /* centered board */
  grid-template-columns: repeat(10, minmax(0, 1fr)) !important;
  gap: clamp(6px, 0.9vw, 10px);
}
/* square cells that scale with container width */
.cell {
  width: 100% !important;
  height: auto !important;
  aspect-ratio: 1 / 1;
}
/* pieces & labels scale softly with cell size */
.piece {
  inset: clamp(4px, 0.8vw, 8px);
  border-radius: clamp(8px, 1.6vw, 14px);
}
.idx {
  font-size: clamp(10px, 1.6vw, 12px);
}
.glyph {
  font-size: clamp(12px, 1.8vw, 14px);
}

.main-container {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
}

.welcome-section {
  text-align: center;
  margin-bottom: 40px;
}

.welcome-section h1 {
  font-size: 2.5rem;
  margin-bottom: 10px;
  color: var(--primary);
}

.welcome-section p {
  font-size: 1.1rem;
  color: var(--muted);
  margin-bottom: 30px;
}

.game-options {
  display: grid;
  gap: 20px;
  margin-bottom: 40px;
}

.option-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.option-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.option-card h3 {
  margin: 0 0 12px 0;
  color: var(--text);
}

.option-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.room-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
}

.room-section h3 {
  margin: 0 0 16px 0;
  color: var(--text);
}

.room-form {
  display: grid;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-weight: 500;
  color: var(--text);
}

.form-group input {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary);
}

.room-list {
  display: grid;
  gap: 12px;
}

.room-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: all 0.2s ease;
}

.room-item:hover {
  border-color: var(--primary);
}

.room-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.room-name {
  font-weight: 500;
  color: var(--text);
}

.room-status {
  font-size: 14px;
  color: var(--muted);
}

.player-count {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}

.player-dots {
  display: flex;
  gap: 4px;
}

.player-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.player-dot.active {
  background: var(--primary);
}

.btn-join {
  padding: 8px 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s ease;
}

.btn-join:hover {
  background: var(--primary-dark);
}

.btn-join:disabled {
  background: var(--muted);
  cursor: not-allowed;
}

.hidden {
  display: none;
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--muted);
}

.error {
  background: #fee;
  border: 1px solid #fcc;
  color: #c33;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 16px;
}

.success {
  background: #efe;
  border: 1px solid #cfc;
  color: #3c3;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 16px;
}
