:root {
  --space-1: 2px;
  --space-2: 4px;
  --space-3: 8px;
  --space-4: 12px;
  --space-5: 18px;
  --space-6: 24px;

  --font-size-1: 12px;
  --font-size-2: 14px;
  --font-size-3: 18px;
  --font-size-4: 20px;
  --font-size-5: 36px;

  --fg: white;
  --fg2: rgba(255 255 255 / 0.8);
  --fg3: rgba(255 255 255 / 0.25);
  --fg4: rgba(255 255 255 / 0.15);
  --bg: #1c1c1c;

  --radius: 3px;

  --salmon: oklch(0.72 0.16 24);
  --tomato: oklch(0.55 0.17 21.36);
  --burgundy: oklch(0.45 0.1 21);

  --coral: oklch(0.7 0.14 40);
  /* --tangerine: oklch(0.74 0.13 60); */
  --honey: oklch(0.75 0.1 80);
  /* --gold: oklch(0.7 0.08 100); */

  --olive: oklch(0.76 0.11 130);
  --emerald: oklch(0.61 0.13 150);
  --turquoise: oklch(0.72 0.14 170);

  --aqua: oklch(0.7 0.15 205);
  --sapphire: oklch(0.5 0.18 240);
  --indigo: oklch(0.65 0.17 260);

  --plum: oklch(0.6 0.16 290);
  --orchid: oklch(0.7 0.15 310);
  --rose: oklch(0.71 0.15 355);
}

body {
  margin: 0 auto;
  padding: 0 var(--space-4);
  color: var(--fg);
  background-color: var(--bg);
  font-family: system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

h2 {
  margin: 0;
  font-family: "Rubik", system-ui, sans-serif;
  font-weight: 700;
  font-size: var(--font-size-5);
  text-transform: uppercase;
  text-align: center;
}

strong {
  font-weight: 700;
  letter-spacing: 1px;
  color: rgba(255 255 255 / 0.85);
}

button {
  padding: var(--space-4) var(--space-6);
  border: none;
  background-color: #444;
  font-weight: 600;
  color: #fff;
  border-radius: 8px;
  border-top: 1px solid rgba(255 255 255 / 0.1);
  border-bottom: 4px solid rgba(0 0 0 / 0.5);
  width: 100%;

  &:enabled {
    pointer-events: auto;
    cursor: pointer;
  }

  &:enabled:hover {
    filter: brightness(1.1);
  }

  &:enabled:active {
    border-bottom-width: 0px;
    margin-top: 4px;
  }

  &:disabled {
    opacity: 0.6;
  }
}

/* HOME */

.home {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  gap: var(--space-6);
}

.box {
  display: grid;
  gap: var(--space-5);
  background-color: #2a2a2a;
  padding: var(--space-6);
  border-radius: 8px;
  min-width: 350px;
}

.divider {
  position: relative;
  text-align: center;
  font-style: italic;
  font-size: var(--font-size-3);
  color: var(--fg2);

  &::before,
  &::after {
    content: "";
    position: absolute;
    top: 50%;
    width: 100px;
    height: 0;
    border-top: 1px solid var(--fg3);
  }

  &::before {
    right: 58%;
  }

  &::after {
    left: 58%;
  }
}

.error {
  section {
    margin: 0 auto;
    pointer-events: none;
  }
}

form {
  display: grid;
  gap: var(--space-5);
}

input {
  --transition: 0.2s ease-in-out;

  width: 100%;
  padding: var(--space-3);
  border-radius: var(--radius);
  outline: 0;
  transition:
    background-color var(--transition),
    border-color var(--transition),
    color var(--transition);
}

[type="text"] {
  padding: var(--space-4);
  color: var(--fg);
  background: var(--bg);
  border: 2px solid transparent;

  &::placeholder {
    color: color-mix(in srgb, currentColor 60%, transparent);
  }

  &:active,
  &:focus {
    border: 2px solid var(--fg3);
  }
}

[type="radio"] {
  --accent-h: 190;
  appearance: none;
  width: 22px;
  height: 22px;
  cursor: pointer;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px #9f9f9f;
  color: oklch(0.69 0.13 var(--accent-h));
  transition: box-shadow 300ms ease-out;
  animation: rainbow 40s infinite alternate;

  &:checked {
    box-shadow: inset 0 0 0 7px currentColor;
  }
}

label {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.size-picker {
  position: relative;

  .glider {
    position: absolute;
    inset: 0;
    width: 100%;
    height: calc(100% / 4);
    border-radius: var(--radius);
    background: rgba(255 255 255 / 0.09);
    transition: transform 400ms cubic-bezier(0.5, 1.6, 0.4, 1);
  }

  label:nth-child(2):has(:checked) ~ .glider {
    transform: translateY(100%);
  }

  label:nth-child(3):has(:checked) ~ .glider {
    transform: translateY(200%);
  }

  label:nth-child(4):has(:checked) ~ .glider {
    transform: translateY(300%);
  }
}

.muted {
  color: var(--fg3);
}

@property --accent-h {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

@keyframes rainbow {
  from {
    --accent-h: 190;
  }
  to {
    --accent-h: 550; /* 360 + 190 */
  }
}

/* BOARD */

.board {
  position: relative;
  width: max-content;
  margin: 0 auto;
  margin-top: 40px;
}

#grid {
  --cell-height: 34px;
  --cell-width: 29.4449px;
  --hex-row: 25.5px;
  --row-offset: -14.7224px;
  --hex-shape: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);

  display: grid;
  width: max-content;
  padding: var(--space-5);
  gap: 1px;
  grid-template-columns: repeat(var(--w), var(--cell-width));
  grid-auto-rows: var(--hex-row);
  cursor: default;
  user-select: none;
  font-family: "Rubik", system-ui, sans-serif;
  font-weight: 700;
  font-size: var(--font-size-4);
  contain: layout paint;

  > div {
    --delay: 0;
    --row-shift: 0px;

    position: relative;
    display: grid;
    place-items: center;
    width: var(--cell-width);
    height: var(--cell-height);
    isolation: isolate;
    background: transparent;
    transform: translateX(var(--row-shift));
    transition: transform 300ms;

    &::before,
    &::after {
      content: "";
      position: absolute;
      inset: 0;
      clip-path: var(--hex-shape);
    }

    &::before {
      background: var(--p);
      z-index: -1;
    }

    &.fail::before {
      background: none;
    }

    &.odd-row {
      --row-shift: var(--row-offset);
    }

    &:hover {
      filter: brightness(1.15);
    }

    &:active {
      transform: translateX(var(--row-shift)) scale(0.9);
    }

    &::after {
      background: #666;
      z-index: 1;
      transition:
        transform 300ms,
        opacity 300ms;
      transition-delay: calc(var(--delay) * 69ms);
    }

    &.x2::after,
    &.x3::after {
      content: "×2";
      color: #3f3f3f;
      text-shadow: 0px 1px #888;
      display: grid;
      place-items: center;
      font-size: var(--font-size-3);
    }

    &.x3::after {
      content: "×3";
    }

    &.mine.x2::after,
    &.mine.x3::after {
      content: "";
    }

    svg {
      position: relative;
      z-index: 2;
      width: 100%;
      height: 100%;
    }
  }

  .show,
  .flag,
  .mine {
    pointer-events: none !important;
  }

  .show::after,
  .flag::after {
    transform: scale(0);
    opacity: 0;
  }

  .mine {
    padding: 3px;

    &::after {
      background: var(--fg);
      border-radius: 50%;
      transform: scale(2.5);
      aspect-ratio: 1;
    }
  }

  .flag {
    color: var(--p);
    padding: 5px;
  }

  .flag::before {
    background: #383838;
  }

  .boom {
    transform: translateX(var(--row-shift))
      translate(calc(var(--bx) * 1px), calc(var(--by) * 1px))
      rotate(calc(var(--rot) * 1deg));
    transition: transform 150ms ease-out;
    transition-delay: 50ms;
    z-index: 1;
    filter: drop-shadow(1px 1px 2px #2a2a2a);

    &:hover {
      filter: drop-shadow(1px 1px 2px #2a2a2a) brightness(1.15);
    }

    &:active {
      transform: translateX(var(--row-shift))
        translate(calc(var(--bx) * 1px), calc(var(--by) * 1px))
        rotate(calc(var(--rot) * 1deg)) scale(0.92);
    }
  }

  .fail {
    position: relative;
    background: none;

    &::after {
      color: var(--fg);
      background: var(--fg);
    }

    span {
      position: absolute;
      inset: 0;
      z-index: 2;
      display: grid;
      place-items: center;
      background: var(--p);

      &:nth-child(1) {
        clip-path: polygon(50% 0, 100% 25%, 100% 52%, 0 52%, 0 25%);
        transform: translate(-1px, -1px) rotate(10deg);
      }

      &:nth-child(2) {
        clip-path: polygon(0 48%, 100% 48%, 100% 75%, 50% 100%, 0 75%);
        transform: translate(1px, 1px) rotate(4deg);
      }
    }
  }
}

.gameover {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  place-content: center;
  gap: var(--space-6);
  background: color-mix(in oklab, var(--bg) 85%, transparent);
  backdrop-filter: blur(2px);
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  animation: card-in 690ms ease-out forwards;

  .winner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
  }
}

/* LEADERBOARD */

table {
  margin: var(--space-3) auto;
  border-collapse: collapse;
  font-size: var(--font-size-2);

  th {
    padding: var(--space-3);
    border-bottom: 1px solid var(--fg3);
    text-align: left;
    text-transform: uppercase;
    font-size: var(--font-size-1);
    font-weight: 400;
    letter-spacing: 0.5px;
    color: var(--fg2);
  }

  td {
    padding: var(--space-3) var(--space-4);
  }

  tbody tr {
    border-bottom: 1px solid var(--fg4);
  }

  .score {
    font-weight: 700;
  }
}

.name {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-weight: 500;
  text-transform: capitalize;
}

.swatch {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: var(--radius);
}

.debug {
  display: none;
}

aside {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-2);
  gap: var(--space-3);
  margin-top: var(--space-3);
  color: rgba(255 255 255 / 0.7);
}

@font-face {
  font-family: "Rubik";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(font.woff2) format("woff2");
}

@keyframes card-in {
  to {
    opacity: 1;
  }
}
