:root {
  color-scheme: dark;
  --bg-1: #040816;
  --bg-2: #0c1f47;
  --panel: rgba(8, 15, 33, 0.78);
  --panel-border: rgba(164, 207, 255, 0.2);
  --text: #f5f7ff;
  --muted: #9bb4df;
  --accent: #8be3ff;
  --accent-2: #ffd86b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Pretendard", "Noto Sans KR", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(88, 132, 255, 0.32), transparent 30%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg-1) 65%, #010308 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.02) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.02) 50%, rgba(255, 255, 255, 0.02) 75%, transparent 75%, transparent);
  background-size: 40px 40px;
  opacity: 0.15;
  pointer-events: none;
}

.page-shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 24px auto;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 400px);
  gap: 20px;
  align-items: start;
}

.game-panel,
.leaderboard-panel {
  position: relative;
  z-index: 1;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(14px);
}

.game-panel {
  padding: 24px;
}

.leaderboard-panel {
  padding: 22px 18px;
}

.panel-head,
.leaderboard-head {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: start;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: clamp(28px, 4vw, 38px);
  max-width: 12ch;
}

h2 {
  font-size: 26px;
}

h3 {
  font-size: 17px;
  color: #ffffff;
}

.profile-box {
  min-width: 220px;
}

.profile-box label,
.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.profile-meta {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
}

.profile-meta span {
  color: var(--muted);
  font-size: 14px;
}

input,
button {
  font: inherit;
}

input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

button {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 700;
  color: #08111f;
  background: linear-gradient(135deg, var(--accent) 0%, #b8f5ff 100%);
  cursor: pointer;
}

button:hover {
  filter: brightness(1.05);
}

button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.3);
  opacity: 0.65;
}

button.ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.hud {
  margin: 20px 0 16px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.hud strong {
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  text-align: center;
}

.canvas-frame {
  position: relative;
  padding: 16px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(104, 148, 255, 0.24), rgba(5, 12, 24, 0.32));
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 18px;
  border: 1px solid rgba(176, 219, 255, 0.28);
  background: linear-gradient(180deg, #4b74ff 0%, #1b295d 48%, #07101f 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.mobile-controls {
  display: none;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

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

.mobile-controls.arrow-pad {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.touch-button {
  min-height: 56px;
  border-radius: 18px;
  touch-action: manipulation;
  user-select: none;
}

.touch-spacer {
  min-height: 56px;
  visibility: hidden;
}

.touch-button.jump {
  background: linear-gradient(135deg, #ffd86b 0%, #fff0b5 100%);
}

.guide-card {
  margin-top: 16px;
  padding: 16px 18px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
}

.guide-card p {
  margin: 6px 0;
}

.coin-legend,
.my-stats-card {
  margin-top: 16px;
  padding: 16px 18px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
}

.coin-legend-grid,
.my-stats-grid {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

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

.coin-legend-item {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--muted);
}

.coin-legend-item img {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
}

.card-header {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
}

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

.my-stats-grid div {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.stats-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

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

.rank-section + .rank-section {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.leaderboard-list {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  max-height: 280px;
  overflow: auto;
}

.leaderboard-list.secondary {
  max-height: 240px;
}

.leaderboard-item {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.leaderboard-item.top3 {
  background: linear-gradient(135deg, rgba(255, 216, 107, 0.2), rgba(139, 227, 255, 0.08));
  border-color: rgba(255, 216, 107, 0.25);
}

.leaderboard-rank {
  color: var(--accent-2);
  font-weight: 800;
}

.leaderboard-name {
  line-height: 1.2;
}

.leaderboard-name small {
  color: var(--muted);
}

.leaderboard-score {
  color: var(--accent);
  font-weight: 700;
}

.overlay-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 8, 20, 0.78);
  backdrop-filter: blur(8px);
}

.overlay-modal.hidden {
  display: none;
}

.overlay-card {
  width: min(100%, 620px);
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 26px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(180deg, rgba(17, 29, 61, 0.98), rgba(7, 12, 28, 0.96));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}

.overlay-card input + .field-label,
.overlay-card .field-label + input {
  margin-top: 10px;
}

.overlay-card h2 {
  margin-bottom: 14px;
}

.overlay-copy {
  margin: 0 0 14px;
  color: var(--muted);
}

.modal-guide-card {
  margin: 14px 0;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
}

.modal-guide-card p {
  margin: 8px 0 0;
  color: var(--muted);
}

.modal-coin-grid {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.result-summary {
  margin-bottom: 14px;
}

.result-summary p {
  margin: 0 0 8px;
}

.overlay-actions {
  display: flex;
  gap: 10px;
}

.share-card {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
}

.share-copy,
.share-status {
  margin: 10px 0 0;
  color: var(--muted);
}

.share-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.modal-ranking-grid {
  display: grid;
  gap: 16px;
  margin-top: 18px;
}

.rank-section.compact {
  margin-top: 0;
  padding: 14px 14px 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
}

.rank-section.compact + .rank-section.compact {
  margin-top: 0;
}

.modal-ranking-grid .leaderboard-list {
  max-height: 160px;
}

.gameover-ad {
  margin-bottom: 16px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
}

.start-ad-wrap {
  margin-top: 18px;
  margin-bottom: 0;
}

.game-adsense {
  display: block;
  width: 100%;
  min-height: 120px;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.03);
}

@media (max-width: 980px) {
  .page-shell {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .page-shell {
    width: min(100vw - 18px, 100%);
    margin: 10px auto;
    gap: 12px;
  }

  .game-panel,
  .leaderboard-panel {
    border-radius: 20px;
  }

  .game-panel {
    padding: 16px;
  }

  .panel-head,
  .leaderboard-head,
  .overlay-actions {
    flex-direction: column;
  }

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

  .mobile-controls {
    display: grid;
  }

  .coin-legend-grid,
  .my-stats-grid,
  .share-grid {
    grid-template-columns: 1fr;
  }
}
