@font-face {
  font-family: "Mysteron";
  src: url("./assets/Mysteron.ttf") format("truetype");
  font-display: swap;
}

:root {
  --bg-top: #070b12;
  --bg-bottom: #111721;
  --panel-top: rgba(14, 20, 31, 0.95);
  --panel-bottom: rgba(8, 12, 19, 0.96);
  --panel-edge: rgba(164, 212, 221, 0.2);
  --text-main: #f7efdb;
  --text-muted: #9fb0ba;
  --gold-soft: #fff1ae;
  --gold-edge: rgba(255, 210, 68, 0.42);
  --gold-glow: rgba(255, 210, 68, 0.32);
  --silver-edge: rgba(210, 228, 234, 0.14);
  --shadow-fill: rgba(160, 168, 174, 0.76);
  --danger: #ff8a90;
  --success: #80de9a;
  --link: #9cd5dc;
  --hex-clip: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  touch-action: manipulation;
}

body {
  overflow: hidden;
  color: var(--text-main);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 50% 14%, rgba(255, 214, 86, 0.11), transparent 26%),
    radial-gradient(circle at 18% 20%, rgba(156, 213, 220, 0.1), transparent 22%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  background:
    radial-gradient(circle at 50% 70%, rgba(255, 214, 86, 0.08), transparent 24%),
    repeating-linear-gradient(
      120deg,
      rgba(255, 255, 255, 0.02) 0 2px,
      transparent 2px 44px
    ),
    repeating-linear-gradient(
      60deg,
      rgba(255, 255, 255, 0.02) 0 2px,
      transparent 2px 44px
    );
  opacity: 0.55;
}

body::after {
  background:
    radial-gradient(circle at 86% 18%, rgba(255, 196, 53, 0.18), transparent 12%),
    radial-gradient(circle at 14% 84%, rgba(156, 213, 220, 0.12), transparent 13%);
  animation: drift 12s ease-in-out infinite alternate;
}

.app {
  position: relative;
  width: 100%;
  height: 100%;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.5vw, 12px);
  touch-action: manipulation;
}

.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: clamp(8px, 1.8vw, 14px);
  min-height: clamp(56px, 10vw, 76px);
  flex-wrap: nowrap;
}

.scoreboard {
  display: flex;
  flex-direction: column;
  gap: clamp(4px, 1vw, 8px);
  align-items: flex-start;
  justify-content: center;
  padding-left: 2px;
  min-width: 0;
  flex: 1 1 auto;
}

.metric {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: clamp(5px, 1.5vw, 10px);
}

.metric__icon {
  display: inline-grid;
  width: clamp(16px, 4vw, 26px);
  place-items: center;
  color: #ffffff;
  font-family: "Mysteron", "Avenir Next", sans-serif;
  font-size: clamp(14px, 3.8vw, 22px);
  line-height: 1;
  flex: 0 0 auto;
}

.metric strong {
  display: inline-block;
  font-family: "Mysteron", "Avenir Next", sans-serif;
  font-size: clamp(16px, 4.8vw, 30px);
  color: #ffffff;
  line-height: 1;
  letter-spacing: clamp(0.03em, 0.2vw, 0.08em);
}

.actions {
  display: flex;
  gap: clamp(5px, 1.4vw, 10px);
  align-items: center;
  flex-wrap: nowrap;
  flex: 0 0 auto;
}

.hex-button {
  position: relative;
  width: clamp(46px, 12vw, 74px);
  height: clamp(46px, 12vw, 74px);
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #ffffff;
  cursor: pointer;
  flex: 0 0 auto;
}

.hex-button::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("./assets/hex-silver.png") center / 100% 100% no-repeat;
  clip-path: var(--hex-clip);
  filter:
    drop-shadow(0 12px 24px rgba(0, 0, 0, 0.28))
    drop-shadow(0 0 10px rgba(255, 255, 255, 0.05));
  transition: transform 160ms ease, filter 160ms ease;
}

.hex-button:hover::before,
.hex-button:focus-visible::before {
  transform: scale(1.04);
  filter:
    drop-shadow(0 14px 26px rgba(0, 0, 0, 0.32))
    drop-shadow(0 0 14px rgba(255, 255, 255, 0.08));
}

.hex-button:active::before {
  transform: scale(0.96);
}

.hex-button:focus-visible {
  outline: none;
}

.hex-button > * {
  position: relative;
  z-index: 1;
}

.hex-button__glyph {
  position: absolute;
  inset: 20%;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.hex-button--preview {
  overflow: hidden;
}

.preview-grid {
  position: absolute;
  inset: clamp(5px, 1.4vw, 8px);
  pointer-events: none;
}

.preview-hex {
  position: absolute;
  left: 0;
  top: 0;
  background: url("./assets/hex-ruby.png") center / 100% 100% no-repeat;
  clip-path: var(--hex-clip);
  filter: drop-shadow(0 0 10px rgba(222, 73, 82, 0.28));
}

.button-icon {
  width: 100%;
  height: 100%;
  display: block;
  fill: currentColor;
  color: inherit;
}

.button-icon--play {
  display: none;
}

#pauseButton[data-state="pause"] .button-icon--pause {
  display: none;
}

#pauseButton[data-state="pause"] .button-icon--play {
  display: block;
}

.playfield {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  border-radius: 32px;
  border: 1px solid var(--panel-edge);
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 214, 86, 0.05), transparent 28%),
    linear-gradient(180deg, var(--panel-top), var(--panel-bottom));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.03),
    0 26px 42px rgba(0, 0, 0, 0.28);
}

.playfield::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 24%),
    radial-gradient(circle at 50% 100%, rgba(255, 214, 86, 0.04), transparent 32%);
  pointer-events: none;
}

.board {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: center bottom;
}

.board.is-impact {
  animation: board-impact 220ms ease;
}

.hex {
  position: absolute;
  left: 0;
  top: 0;
  clip-path: var(--hex-clip);
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  transition:
    left 140ms ease,
    top 140ms ease,
    transform 140ms ease,
    opacity 180ms ease,
    filter 180ms ease,
    box-shadow 180ms ease;
}

.hex--cell {
  background-image: none;
  filter: none;
}

.hex--cell.is-border {
  background-image: url("./assets/hex-silver.png");
  filter: none;
}

.hex--cell.is-filled {
  background-image: url("./assets/hex-gold.png");
  filter: drop-shadow(0 0 16px var(--gold-edge));
}

.hex--cell.is-ghost {
  background-image: url("./assets/hex-silver.png");
  filter: grayscale(0.08) brightness(0.48) saturate(0.1);
  opacity: 0.8;
  z-index: 2;
}

.hex--cell.is-clearing {
  animation: pulse-clear 520ms ease-in-out infinite alternate;
  z-index: 3;
}

.hex--cell.is-active {
  background-image: url("./assets/hex-gold.png");
  filter:
    brightness(1.08) saturate(1.04)
    drop-shadow(0 0 24px var(--gold-glow))
    drop-shadow(0 0 12px rgba(255, 214, 86, 0.44));
  z-index: 4;
}

.burst {
  position: absolute;
  left: 50%;
  bottom: 28px;
  margin: 0;
  transform: translateX(-50%) translateY(12px);
  color: var(--gold-soft);
  font-family: "Mysteron", "Avenir Next", sans-serif;
  font-size: clamp(14px, 3.6vw, 22px);
  letter-spacing: 0.08em;
  opacity: 0;
  pointer-events: none;
  text-transform: uppercase;
  text-shadow: 0 0 18px rgba(255, 214, 86, 0.32);
}

.burst.is-live {
  animation: burst-up 840ms ease;
}

.level-badge {
  display: none;
}

.modal-layer {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 20;
}

.modal-layer[hidden] {
  display: none !important;
}

.modal-layer.is-tap-dismiss {
  cursor: pointer;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(420px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  overflow: auto;
  padding: 24px 22px;
  border-radius: 28px;
  border: 1px solid var(--panel-edge);
  background:
    linear-gradient(180deg, rgba(21, 28, 39, 0.96), rgba(9, 13, 20, 0.98));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.03),
    0 28px 44px rgba(0, 0, 0, 0.34);
}

.modal-card--hero {
  width: min(320px, calc(100vw - 28px));
  min-height: min(320px, calc(100vw - 28px));
  max-height: none;
  padding: 34px 38px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.modal-card--hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("./assets/hex-silver.png") center / contain no-repeat;
  clip-path: var(--hex-clip);
  filter:
    drop-shadow(0 24px 40px rgba(0, 0, 0, 0.34))
    drop-shadow(0 0 18px rgba(255, 255, 255, 0.04));
}

.modal-card--hero > * {
  position: relative;
  z-index: 1;
}

.modal-title {
  margin: 0 0 14px;
  color: var(--text-main);
  font-family: "Mysteron", "Avenir Next", sans-serif;
  font-size: 28px;
  letter-spacing: 0.08em;
  text-align: center;
}

.modal-card--hero .modal-title {
  margin: 0 0 10px;
  color: #161a22;
  font-size: 30px;
}

.modal-title.is-hidden {
  display: none;
}

.modal-body {
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1.55;
}

.modal-body p {
  margin: 0;
}

.modal-copy {
  max-width: 210px;
  color: #1d232d;
  font-family: "Mysteron", "Avenir Next", sans-serif;
  font-size: 18px;
  line-height: 1.35;
  letter-spacing: 0.03em;
}

.modal-copy--accent {
  color: #b01419;
}

.modal-actions {
  margin-top: 20px;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.modal-body:empty,
.modal-actions:empty {
  display: none;
}

.modal-actions:empty {
  margin-top: 0;
}

.modal-action {
  min-width: 132px;
  padding: 12px 18px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #fff2b0, #f0c945);
  color: #121824;
  cursor: pointer;
  font-family: "Mysteron", "Avenir Next", sans-serif;
  font-size: 16px;
  letter-spacing: 0.08em;
  box-shadow: 0 14px 24px rgba(0, 0, 0, 0.22);
}

.modal-action--secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  box-shadow: none;
}

.modal-card--hero .modal-body {
  color: #1d232d;
}

.modal-card--hero .modal-actions {
  margin-top: 14px;
}

.modal-card--hero .modal-action,
.modal-card--hero .modal-action--secondary {
  min-width: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
  color: #b01419;
  font-size: 26px;
}

.settings-grid {
  display: grid;
  gap: 12px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 14px;
  border: 1px solid var(--silver-edge);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
}

.settings-row--static {
  align-items: flex-start;
}

.settings-copy {
  min-width: 0;
}

.settings-copy span {
  display: block;
  margin-bottom: 3px;
  color: var(--text-muted);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.settings-copy strong {
  display: block;
  color: var(--text-main);
  font-size: 15px;
  line-height: 1.35;
}

.settings-copy .settings-value--good {
  color: var(--success);
}

.settings-copy .settings-value--bad {
  color: var(--danger);
}

.settings-toggle {
  flex: 0 0 auto;
  padding: 10px 14px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  cursor: pointer;
  font-family: "Mysteron", "Avenir Next", sans-serif;
  font-size: 13px;
  letter-spacing: 0.08em;
}

.settings-links {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-top: 2px;
}

.settings-links a {
  color: var(--link);
  text-decoration: none;
  font-family: "Mysteron", "Avenir Next", sans-serif;
  font-size: 14px;
  letter-spacing: 0.05em;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 780px) {
  .topbar {
    min-height: clamp(52px, 12vw, 68px);
  }

  .actions {
    justify-content: flex-end;
  }

  .scoreboard {
    padding-top: 0;
  }
}

@media (max-width: 520px) {
  .app {
    gap: 6px;
  }

  .topbar {
    gap: 6px;
    min-height: 48px;
  }

  .metric__icon {
    width: 14px;
    font-size: 13px;
  }

  .metric strong {
    font-size: 14px;
    letter-spacing: 0.02em;
  }

  .hex-button {
    width: 42px;
    height: 42px;
  }

  .preview-grid {
    inset: 4px;
  }

  .modal-card--hero {
    width: min(300px, calc(100vw - 22px));
    min-height: min(300px, calc(100vw - 22px));
    padding: 32px 30px;
  }

  .modal-copy {
    font-size: 16px;
  }
}

@media (hover: none) and (pointer: coarse) {
  body::after {
    animation: none;
  }

  .modal-backdrop {
    background: rgba(0, 0, 0, 0.74);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

@keyframes drift {
  from {
    transform: translate3d(0, 0, 0);
  }

  to {
    transform: translate3d(0, -18px, 0);
  }
}

@keyframes board-impact {
  0% {
    transform: scale(1);
  }

  45% {
    transform: scale(1.014);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes pulse-clear {
  from {
    transform: scale(1);
    filter: brightness(1.08);
  }

  to {
    transform: scale(0.88);
    filter: brightness(1.36);
  }
}

@keyframes burst-up {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(12px);
  }

  18%,
  74% {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }

  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px);
  }
}
