:root {
  color-scheme: dark;
  --deep: #06111f;
  --navy: #0a2238;
  --aqua: #7df9ff;
  --kelp: #8effa7;
  --pearl: #f9f7d9;
  --coral: #ff6f91;
  --gold: #ffd166;
  --violet: #8b5cf6;
  --muted: #a8c6d8;
  --line: rgba(125, 249, 255, 0.25);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--deep);
  color: var(--pearl);
  touch-action: none;
}

button {
  font: inherit;
  letter-spacing: 0;
}

#gameRoot {
  position: fixed;
  inset: 0;
  min-width: 320px;
  min-height: 360px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 46%, rgba(125, 249, 255, 0.17), transparent 34%),
    radial-gradient(circle at 72% 72%, rgba(255, 111, 145, 0.12), transparent 32%),
    linear-gradient(180deg, #0b2a44 0%, var(--deep) 62%, #020914 100%);
}

#gameRoot::before {
  content: "";
  position: absolute;
  inset: -20%;
  background:
    repeating-radial-gradient(circle at 50% 48%, transparent 0 68px, rgba(125, 249, 255, 0.07) 70px 73px),
    linear-gradient(110deg, transparent 0 30%, rgba(142, 255, 167, 0.08) 42%, transparent 54% 100%);
  animation: currentDrift 14s linear infinite;
}

@keyframes currentDrift {
  to { transform: translate3d(-44px, 36px, 0) rotate(3deg); }
}

#hud {
  position: absolute;
  inset: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) auto max(12px, env(safe-area-inset-left));
  z-index: 4;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  pointer-events: none;
}

.brand,
.stats div,
#goalDock,
.modal-frame {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(10, 34, 56, 0.84), rgba(6, 17, 31, 0.66));
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.32), inset 0 0 60px rgba(125, 249, 255, 0.04);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  padding: 10px 12px;
}

.brand-gem,
.big-gem {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  background: linear-gradient(135deg, white, var(--aqua) 35%, var(--kelp) 62%, var(--coral));
  clip-path: polygon(50% 0, 92% 24%, 76% 100%, 24% 100%, 8% 24%);
  box-shadow: 0 0 30px rgba(125, 249, 255, 0.52);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: white;
  font-size: clamp(19px, 2.7vh, 31px);
  line-height: 1;
  text-shadow: 0 0 20px rgba(125, 249, 255, 0.32);
}

#objectiveText {
  max-width: min(560px, 52vw);
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: 50vw;
}

.stats div {
  min-width: 104px;
  min-height: 54px;
  padding: 8px 10px;
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.stats b {
  display: block;
  margin-top: 3px;
  color: white;
  font-size: 20px;
}

#boardWrap {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: min(82vh, 740px, calc(100vw - 280px));
  min-width: 480px;
  aspect-ratio: 1;
  transform: translate(-50%, -46%);
  border: 1px solid rgba(125, 249, 255, 0.32);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 50%, rgba(125, 249, 255, 0.16), transparent 62%),
    linear-gradient(145deg, rgba(10, 34, 56, 0.82), rgba(6, 17, 31, 0.86));
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.44), inset 0 0 70px rgba(125, 249, 255, 0.08);
  overflow: hidden;
}

#gameCanvas,
#boardOverlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#gameCanvas {
  display: block;
}

#boardOverlay {
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255,255,255,0.04) 1px, transparent 1px);
  background-size: 12.5% 12.5%;
  mix-blend-mode: screen;
}

#goalDock {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  top: 50%;
  z-index: 5;
  width: 190px;
  display: grid;
  gap: 10px;
  padding: 14px;
  transform: translateY(-40%);
}

.goal {
  min-height: 62px;
  display: grid;
  grid-template-columns: 46px 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid rgba(249, 247, 217, 0.14);
  border-radius: 8px;
  background: rgba(6, 17, 31, 0.46);
}

.goal span {
  width: 42px;
  height: 42px;
  display: block;
  border-radius: 50%;
  box-shadow: 0 0 22px currentColor;
}

.goal.blue { color: var(--aqua); }
.goal.pearl { color: var(--pearl); }
.goal.coral { color: var(--coral); }
.goal.gold { color: var(--gold); }
.goal.blue span { background: radial-gradient(circle at 35% 28%, white, var(--aqua) 48%, #12617a); clip-path: polygon(50% 0, 92% 28%, 74% 100%, 26% 100%, 8% 28%); }
.goal.pearl span { background: radial-gradient(circle at 35% 28%, white, var(--pearl) 52%, #97b6c7); }
.goal.coral span { background: radial-gradient(circle at 35% 28%, white, var(--coral) 48%, #7c1d3a); clip-path: polygon(50% 0, 100% 38%, 78% 100%, 50% 76%, 22% 100%, 0 38%); }
.goal.gold span { background: radial-gradient(circle at 35% 28%, white, var(--gold) 48%, #9a5b10); clip-path: polygon(50% 0, 62% 34%, 100% 50%, 62% 66%, 50% 100%, 38% 66%, 0 50%, 38% 34%); }

.goal b {
  color: white;
  font-size: 28px;
}

#shuffleButton,
#modalPrimary {
  min-height: 48px;
  border: 1px solid rgba(249, 247, 217, 0.3);
  border-radius: 8px;
  color: #06111f;
  background: linear-gradient(135deg, var(--gold), var(--kelp));
  box-shadow: 0 14px 38px rgba(255, 209, 102, 0.2);
  font-weight: 950;
  cursor: pointer;
}

#modal {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 50%, rgba(125, 249, 255, 0.12), transparent 36%),
    rgba(2, 9, 20, 0.56);
  backdrop-filter: blur(6px);
}

.modal-frame {
  width: min(540px, calc(100vw - 28px));
  padding: 24px;
  text-align: center;
}

.big-gem {
  width: 86px;
  height: 86px;
  display: inline-grid;
  margin-bottom: 12px;
}

.modal-frame > p {
  color: var(--aqua);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

.modal-frame h2 {
  margin-top: 4px;
  color: white;
  font-size: clamp(42px, 8vw, 68px);
  line-height: 0.92;
  text-shadow: 0 0 26px rgba(125, 249, 255, 0.32);
}

.quick-rules {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 18px;
}

.quick-rules span {
  min-height: 48px;
  display: grid;
  place-items: center;
  padding: 8px;
  border: 1px solid rgba(249, 247, 217, 0.15);
  border-radius: 8px;
  color: #e4fbff;
  background: rgba(6, 17, 31, 0.5);
  font-size: 12px;
  font-weight: 850;
}

#modalPrimary {
  width: 100%;
  min-height: 62px;
  margin-top: 18px;
  font-size: 18px;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  #hud {
    display: grid;
    grid-template-columns: 1fr;
  }

  .brand {
    padding: 8px 10px;
  }

  .brand-gem {
    width: 34px;
    height: 34px;
  }

  #objectiveText {
    max-width: calc(100vw - 88px);
    font-size: 12px;
  }

  .stats {
    max-width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stats div {
    min-width: 0;
    min-height: 44px;
    padding: 7px 8px;
  }

  .stats b {
    font-size: 16px;
  }

  #boardWrap {
    width: min(calc(100vw - 22px), calc(100vh - 256px));
    min-width: 0;
    transform: translate(-50%, -43%);
  }

  #goalDock {
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    top: auto;
    bottom: max(10px, env(safe-area-inset-bottom));
    width: auto;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: stretch;
    transform: none;
    padding: 8px;
  }

  .goal {
    min-height: 54px;
    grid-template-columns: 30px 1fr;
    gap: 6px;
    padding: 6px;
  }

  .goal span {
    width: 28px;
    height: 28px;
  }

  .goal b {
    font-size: 20px;
  }

  #shuffleButton {
    min-height: 54px;
    font-size: 12px;
  }

  .quick-rules {
    grid-template-columns: 1fr;
  }
}
