:root {
  --game-bg: #1a2433;
  --panel: #243247;
  --accent: #3d9be9;
  --text: #f3f6fb;
  --muted: #9db0c7;
  --pad: #2e415c;
  --pad-active: #4a6d9a;
  --danger: #e85d5d;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: radial-gradient(1200px 700px at 50% 20%, #243552 0%, var(--game-bg) 55%, #101722 100%);
  color: var(--text);
  font-family: Pretendard, "Noto Sans KR", sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

a {
  color: var(--accent);
  text-decoration: none;
}

#game-shell {
  height: 100%;
  width: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.game-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: rgba(10, 16, 28, 0.55);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-wrap: wrap;
}

.game-top__left,
.game-top__right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.game-title {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
  color: var(--muted);
}

.stat strong {
  color: var(--text);
  font-size: 14px;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.btn:active {
  transform: scale(0.98);
}

.btn-rank {
  background: var(--accent);
  color: #041018;
  font-weight: 800;
}

.btn-accent {
  background: var(--accent);
  color: #041018;
  font-weight: 700;
}

.play-area {
  position: relative;
  display: grid;
  grid-template-columns: minmax(72px, 1fr) auto minmax(72px, 1fr);
  align-items: center;
  justify-items: center;
  gap: 8px;
  min-height: 0;
  padding: 8px;
}

.canvas-wrap {
  position: relative;
  max-width: 100%;
  max-height: 100%;
}

#game-canvas {
  display: block;
  width: min(100%, calc((100vh - 72px) * 15 / 13));
  height: auto;
  max-height: calc(100vh - 72px);
  image-rendering: pixelated;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  background: #000;
}

.touch-side {
  display: none;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.dpad {
  display: grid;
  grid-template-columns: 64px 64px 64px;
  grid-template-rows: 64px 64px 64px;
  gap: 6px;
}

.dpad .gap {
  pointer-events: none;
}

.pad-btn {
  width: 64px;
  height: 64px;
  border: 0;
  border-radius: 16px;
  background: var(--pad);
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25);
}

.pad-btn:active,
.pad-btn.is-active {
  background: var(--pad-active);
}

.action-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.action-btn {
  width: 78px;
  height: 78px;
  border: 0;
  border-radius: 50%;
  font: inherit;
  font-weight: 800;
  color: #fff;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.25);
}

.action-btn[data-action="bomb"] {
  background: linear-gradient(180deg, #5aa7f2, #2f6fbf);
}

.action-btn[data-action="item"] {
  background: linear-gradient(180deg, #f0a35a, #c56a2b);
}

.action-btn:active {
  transform: translateY(2px);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
}

.hint {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.35);
  padding: 4px 10px;
  border-radius: 999px;
  pointer-events: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 12, 20, 0.62);
  border-radius: 10px;
}

.overlay[hidden] {
  display: none !important;
}

.overlay__card {
  text-align: center;
  padding: 22px 26px;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.overlay__card h2 {
  margin: 0 0 10px;
  font-size: 22px;
}

.overlay__card--wide {
  width: min(420px, 92vw);
}

.overlay__score {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.overlay__score strong {
  color: var(--text);
  font-size: 20px;
}

.nick-field {
  display: grid;
  gap: 6px;
  text-align: left;
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
}

.nick-field input,
.nick-field select {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font: inherit;
  padding: 10px 12px;
  outline: none;
  touch-action: manipulation;
  user-select: text;
  -webkit-user-select: text;
}

.nick-field input:focus,
.nick-field select:focus {
  border-color: var(--accent);
}

.overlay__actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.overlay__note {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.rank-list {
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
  max-height: min(42vh, 320px);
  overflow: auto;
  text-align: left;
}

.rank-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: baseline;
  padding: 8px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 14px;
}

.rank-list .rank-pos {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.rank-list .rank-score {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.rank-list .rank-meta {
  grid-column: 2 / -1;
  font-size: 11px;
  color: var(--muted);
}

.btn-tiny {
  padding: 4px 8px;
  font-size: 12px;
  margin-left: 8px;
}

.account-line {
  margin: 0 0 8px;
  font-size: 14px;
}

.menu-hr {
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin: 14px 0;
}

.join-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.join-row input {
  flex: 1;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font: inherit;
  font-size: 18px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  text-align: center;
  padding: 10px 12px;
  touch-action: manipulation;
  user-select: text;
  -webkit-user-select: text;
}

.lobby-code {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 10px;
  border-radius: 8px;
  background: rgba(61, 155, 233, 0.2);
  color: #9fd0ff;
  letter-spacing: 0.18em;
  font-size: 0.9em;
}

.seat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 14px;
  max-height: min(40vh, 280px);
  overflow: auto;
}

.seat {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 6px;
  align-items: center;
  padding: 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 13px;
}

.seat--empty {
  color: var(--muted);
}

.seat--me {
  border-color: rgba(61, 155, 233, 0.55);
}

.seat--ready {
  background: rgba(70, 160, 100, 0.18);
}

.seat__num {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.seat__ready {
  font-size: 11px;
  font-weight: 800;
  color: #9dffa8;
}

.seat--empty .seat__ready,
.seat:not(.seat--ready) .seat__ready {
  color: var(--muted);
  font-weight: 600;
}

/* Mobile / coarse pointer: show touch controls, prefer landscape layout */
@media (max-width: 960px), (pointer: coarse) {
  .touch-side {
    display: flex;
  }

  .hint {
    display: none;
  }

  .play-area {
    grid-template-columns: minmax(100px, 1.1fr) auto minmax(100px, 1.1fr);
  }

  #game-canvas {
    width: min(100%, calc((100vh - 64px) * 15 / 13));
    max-height: calc(100vh - 64px);
  }
}

@media (max-width: 960px) and (orientation: portrait) {
  .play-area {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  .touch-side--left {
    order: 2;
  }
  .canvas-wrap {
    order: 1;
  }
  .touch-side--right {
    order: 3;
  }

  .rotate-tip {
    display: block;
  }
}

.rotate-tip {
  display: none;
  text-align: center;
  color: #ffd28a;
  font-size: 13px;
  padding: 0 12px 8px;
}
