:root {
  --bg-1: #06111e;
  --bg-2: #0d1f34;
  --panel: rgba(8, 17, 31, 0.9);
  --panel-border: rgba(128, 203, 255, 0.25);
  --text: #e9f6ff;
  --muted: #9fc0d8;
  --accent: #2ce2b1;
  --accent-2: #20b4ff;
  --danger: #ff6f5d;
  --btn-dark: #10243b;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(43, 170, 255, 0.28), transparent 60%),
    radial-gradient(700px 520px at 95% 8%, rgba(44, 226, 177, 0.2), transparent 62%),
    linear-gradient(165deg, var(--bg-2), var(--bg-1));
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 10px;
}

.top-bar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 8px;
  align-items: center;
  background: linear-gradient(180deg, rgba(14, 35, 56, 0.9), rgba(7, 18, 32, 0.88));
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px;
  font-size: 0.88rem;
  box-shadow: inset 0 0 0 1px rgba(20, 64, 102, 0.45), 0 8px 20px rgba(0, 0, 0, 0.35);
}

.actions {
  display: flex;
  gap: 6px;
}

.game-area {
  position: relative;
  flex: 1;
  min-height: 320px;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.01)),
    radial-gradient(700px 240px at 50% 0%, rgba(32, 180, 255, 0.16), transparent 70%);
  border: 1px solid rgba(103, 189, 255, 0.34);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 12px 26px rgba(2, 8, 19, 0.55);
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

button {
  border: 1px solid transparent;
  color: var(--text);
  border-radius: 11px;
  padding: 10px 14px;
  font-size: 0.94rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

button:active {
  transform: scale(0.98);
}

.small-btn {
  background: linear-gradient(180deg, #ff887b, var(--danger));
  color: #330905;
  border-color: rgba(255, 255, 255, 0.28);
}

.mini-btn {
  background: linear-gradient(180deg, #1c3f63, #12304e);
  border-color: rgba(135, 210, 255, 0.35);
  padding: 8px 10px;
  font-size: 0.8rem;
}

.primary-btn {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: #04251e;
  border-color: rgba(255, 255, 255, 0.52);
  box-shadow: 0 8px 18px rgba(27, 151, 195, 0.28);
}

.secondary-btn {
  background: linear-gradient(180deg, #163754, var(--btn-dark));
  border-color: rgba(120, 199, 255, 0.34);
}

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 20px;
  z-index: 10;
  background:
    radial-gradient(circle at 50% -20%, rgba(44, 226, 177, 0.14), transparent 45%),
    rgba(2, 9, 16, 0.88);
  backdrop-filter: blur(4px);
}

.overlay.visible {
  display: grid;
}

.panel {
  width: min(500px, 100%);
  max-height: 92dvh;
  overflow: auto;
  background: linear-gradient(180deg, rgba(14, 34, 54, 0.95), rgba(8, 19, 34, 0.95));
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.42);
}

.panel h1,
.panel h2 {
  margin-top: 4px;
  letter-spacing: 0.02em;
}

.panel h1 {
  font-size: 2rem;
  background: linear-gradient(120deg, #8ce2ff, #47ffc8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.panel p {
  color: var(--muted);
  margin-bottom: 12px;
}

.panel button {
  width: 100%;
  margin-top: 10px;
}

.text-input {
  width: 100%;
  border: 1px solid rgba(133, 204, 255, 0.3);
  background: rgba(2, 10, 22, 0.86);
  color: var(--text);
  border-radius: 9px;
  padding: 10px;
  margin-top: 8px;
}

.text-input::placeholder {
  color: #7aa3c0;
}

.compact {
  width: 90px;
}

.status-text {
  font-size: 0.9rem;
  color: #bde4ff;
  min-height: 20px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.level-btn {
  background: linear-gradient(180deg, rgba(33, 72, 107, 0.96), rgba(16, 43, 70, 0.96));
  border: 1px solid rgba(130, 208, 255, 0.3);
  padding: 10px;
  border-radius: 9px;
}

.level-btn.locked {
  opacity: 0.45;
}

.leaderboard-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
}

.leaderboard-table-wrap {
  max-height: 280px;
  overflow: auto;
  border: 1px solid rgba(130, 208, 255, 0.25);
  border-radius: 10px;
  background: rgba(6, 16, 28, 0.7);
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 8px;
  border-bottom: 1px solid rgba(143, 213, 255, 0.15);
  text-align: left;
}

.leaderboard-table thead {
  background: rgba(23, 54, 83, 0.8);
}

.controls {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.middle-row {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  gap: 8px;
}

.control-btn {
  width: 56px;
  height: 56px;
  background: linear-gradient(180deg, rgba(27, 59, 90, 0.94), rgba(15, 39, 61, 0.94));
  border: 1px solid rgba(146, 216, 255, 0.25);
  font-size: 1.35rem;
}

.hidden {
  display: none;
}

@media (max-width: 640px) {
  .top-bar {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "level time"
      "user actions";
  }

  .top-bar > div:nth-child(1) {
    grid-area: level;
  }

  .top-bar > div:nth-child(2) {
    grid-area: time;
  }

  .top-bar > div:nth-child(3) {
    grid-area: user;
  }

  .actions {
    grid-area: actions;
    justify-self: end;
  }
}

@media (min-width: 768px) {
  .app {
    max-width: 640px;
    margin: 0 auto;
  }
}
