:root {
  --bg: #0d0d0d;
  --panel: rgba(18, 18, 32, 0.92);
  --panel-strong: rgba(12, 12, 25, 0.92);
  --accent: #ffdd57;
  --accent-strong: #f5515f;
  --text: #f4f4f8;
  --muted: #8685a4;
  --outline: rgba(255, 255, 255, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Pretendard", "Noto Sans KR", sans-serif;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 12px;
  background: var(--panel);
}

.hidden {
  display: none !important;
}

.app {
  width: min(1030px, 100%);
  background: var(--panel-strong);
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 18px;
  align-items: center;
}

.app-header h1 {
  margin: 0;
  font-size: 1.7rem;
}

.room-info p {
  margin: 4px 0 0;
  color: var(--muted);
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.control-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

#readyButton {
  padding: 10px 20px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #f5515f, #9f041b);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.3px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#readyButton:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
  box-shadow: none;
}

#readyButton:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(245, 81, 95, 0.35);
}

.countdown {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0;
}

.player-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.player-list h2 {
  margin: 0;
  font-size: 1.1rem;
}

.player-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.player-list li {
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.2;
}

.player-list li.ready {
  border: 1px solid var(--accent);
}

.player-list li.playing {
  border: 1px solid rgba(129, 199, 132, 0.6);
}

.layout {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.primary-area {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
}

.side-column {
  flex: 0 0 320px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.match-area {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.board-card {
  flex: 0 0 auto;
  background: var(--panel);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: inset 0 0 0 1px var(--outline);
}

.board-card.primary {
  width: 370px;
}

.board-card.rival,
.spectator-panel {
  width: 100%;
}

.board-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.board-content {
  display: flex;
  align-items: flex-start;
  gap: 2px;
}

.board-frame {
  position: relative;
  padding: 10px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.65), rgba(0, 0, 0, 0.35));
  box-shadow: inset 0 0 25px rgba(0, 0, 0, 0.5);
  flex: 0 0 auto;
}

.board-frame canvas {
  display: block;
  height: auto;
}

.board-frame--primary canvas {
  width: 240px;
}

.board-frame--opponent canvas {
  width: 150px;
}

.board-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 90px;
  align-items: center;
}

.next {
  background: rgba(0, 0, 0, 0.35);
  border-radius: 12px;
  padding: 8px;
  text-align: center;
}

.next h3,
.next h4 {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.next canvas {
  margin: 8px auto 0;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 2px;
  display: block;
  width: auto;
  max-width: 60px;
  height: auto;
}

.next.mini {
  padding: 8px;
}

.status {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: center;
}

.status.mini {
  font-size: 0.85rem;
}

.status p {
  margin: 0;
}

.waiting {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
  background: rgba(10, 10, 24, 0.7);
  border-radius: 12px;
}

.spectator-panel {
  background: var(--panel);
  border-radius: 18px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: inset 0 0 0 1px var(--outline);
}

.spectator-title h2 {
  margin: 0;
  font-size: 1.1rem;
}

.spectator-grid {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.spectator-card {
  flex: 1 1 0;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 14px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.spectator-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slot-name {
  margin: 0;
  font-size: 1rem;
}

.slot-status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.spectator-content {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.spectator-frame {
  padding: 6px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.4);
  box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.45);
}

.spectator-frame canvas {
  display: block;
  width: 150px;
  height: auto;
}

.spectator-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 90px;
}

.spectator-card.win {
  box-shadow: 0 0 0 2px rgba(129, 199, 132, 0.6);
}

.spectator-card.lose {
  opacity: 0.78;
}

#soloButton {
  padding: 10px 16px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #36d1dc, #5b86e5);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#soloButton:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(54, 209, 220, 0.35);
}

#soloButton.hidden {
  display: none;
}

.solo-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  min-height: 1.2em;
  text-align: center;
}

.solo-status.highlight {
  color: var(--accent);
}

.match-status {
  margin: 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.chat-panel {
  background: var(--panel);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: inset 0 0 0 1px var(--outline);
  min-height: 240px;
  flex: 1 1 auto;
  min-width: 450px;
}

.chat-panel h2 {
  margin: 0;
  font-size: 1.15rem;
}

#chatMessages {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 220px;
  height: 220px;
  overflow-y: auto;
}

#chatMessages li {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 0.95rem;
  line-height: 1.35;
  display: flex;
  gap: 8px;
}

#chatMessages li span {
  display: inline-block;
}

#chatMessages li .nickname {
  font-weight: 600;
  color: var(--accent);
}

#chatMessages li .message {
  color: var(--text);
  word-break: break-word;
}

#chatMessages li .time {
  display: none;
}

#chatForm {
  display: flex;
  gap: 8px;
}

#chatInput {
  flex: 1;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
  font-size: 0.95rem;
}

#chatForm button {
  padding: 10px 16px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, #5b86e5, #36d1dc);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.result-banner {
  margin: 0;
  text-align: center;
  background: rgba(255, 221, 87, 0.12);
  color: var(--accent);
  font-size: 1.2rem;
  font-weight: 600;
  padding: 12px;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(255, 221, 87, 0.1);
}

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

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

#overlay.hidden,
.app.hidden {
  display: none;
}

.dialog {
  background: rgba(20, 20, 35, 0.95);
  padding: 32px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(360px, 90vw);
  text-align: center;
}

.dialog input {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  font-size: 1rem;
}

.dialog button {
  padding: 12px;
  border-radius: 8px;
  border: none;
  background: linear-gradient(135deg, #36d1dc, #5b86e5);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  font-weight: 600;
}

.dialog .error {
  margin-top: 8px;
  color: #ff6b6b;
  font-weight: 600;
  white-space: pre-line;
}

.dialog .note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 860px) {
  .app-header {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .controls {
    align-items: center;
  }

  .layout {
    flex-direction: column;
    align-items: center;
  }

  .primary-area,
  .side-column {
    width: 100%;
  }

  .side-column {
    flex: 0 0 auto;
  }

  .board-card.primary {
    width: 100%;
    max-width: 360px;
  }

  .board-card.rival,
  .spectator-panel {
    max-width: 360px;
    margin: 0 auto;
  }
}

@media (max-width: 640px) {
  body {
    padding: 16px 8px;
  }

  .app {
    padding: 18px;
  }

  .player-list ul {
    justify-content: center;
  }

  .board-content {
    flex-direction: column;
    align-items: center;
  }

  .board-frame--primary canvas {
    width: 200px;
  }

  .board-frame--opponent canvas {
    width: 130px;
  }

  .board-side {
    width: 100%;
    flex-direction: row;
    justify-content: center;
    align-items: stretch;
    gap: 16px;
  }

  .status {
    align-items: center;
  }

  .spectator-content {
    flex-direction: column;
    align-items: center;
  }

  .spectator-side {
    flex-direction: row;
    justify-content: center;
    gap: 16px;
  }

  .spectator-panel {
    width: 100%;
  }

  .spectator-grid {
    flex-wrap: wrap;
    justify-content: center;
  }

  .spectator-card {
    flex: 1 1 160px;
  }
}
