:root {
  --ink: #17201c;
  --paper: #eee9dd;
  --panel: #fffdf7;
  --line: #17201c;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
}

body {
  font-family:
    "Helvetica Neue", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  background-image: radial-gradient(#17201c12 0.7px, transparent 0.7px);
  background-size: 8px 8px;
}

button {
  color: inherit;
  font: inherit;
}

.brandMark {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(2, 16px);
  gap: 3px;
  transform: rotate(-8deg);
}

.brandMark i {
  width: 16px;
  height: 16px;
  display: block;
  border: 1.5px solid var(--line);
}

.brandMark i:nth-child(1) {
  background: #ef476f;
}

.brandMark i:nth-child(2) {
  background: #ffd166;
}

.brandMark i:nth-child(3) {
  background: #06d6a0;
}

.brandMark i:nth-child(4) {
  background: #4d96ff;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  border: 1px solid #17201c38;
}

.stats span {
  min-width: 0;
  height: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font:
    800 20px ui-monospace,
    monospace;
  border-right: 1px solid #17201c38;
  border-bottom: 1px solid #17201c38;
}

.stats span:nth-child(even) {
  border-right: 0;
}

.stats span:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.stats small {
  font:
    700 9px ui-monospace,
    monospace;
  letter-spacing: 0.18em;
  opacity: 0.5;
  margin-bottom: 3px;
}

.gameShell {
  max-width: 1480px;
  height: 100vh;
  margin: auto;
  display: grid;
  grid-template-columns: 320px 1fr;
}

.sidePanel {
  padding: clamp(14px, 2vh, 24px) 32px;
  border-right: 2px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.5vh, 16px);
  background: #fffdf773;
}

h1 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: clamp(22px, 2vw, 27px);
  line-height: 1.06;
  letter-spacing: -0.055em;
  font-weight: 900;
  white-space: nowrap;
}

.intro {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.55;
  font-weight: 600;
  opacity: 0.66;
}

.palette {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.colorBtn {
  position: relative;
  height: 58px;
  border: 1.5px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: 28px 1fr;
  align-items: center;
  padding: 6px;
  text-align: left;
  transition: 0.15s;
  box-shadow: 0 0 0 var(--line);
}

.colorBtn:hover {
  transform: translateY(-2px);
  box-shadow: 3px 3px 0 var(--line);
}

.colorBtn.active {
  box-shadow: 4px 4px 0 var(--line);
  transform: translate(-2px, -2px);
}

.colorBtn span {
  grid-column: 1/3;
  width: 100%;
  height: 24px;
  background: var(--color);
  border: 1.5px solid var(--line);
}

.colorBtn b {
  align-self: center;
  font:
    800 11px ui-monospace,
    monospace;
}

.colorBtn em {
  align-self: center;
  justify-self: end;
  font-size: 10px;
  font-style: normal;
  opacity: 0.5;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.actions button {
  height: 38px;
  border: 1.5px solid var(--line);
  background: var(--panel);
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
}

.actions button:hover,
.difficulty button:hover {
  background: #fff;
  box-shadow: 2px 2px 0 var(--line);
  transform: translate(-1px, -1px);
}

.actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.actions .primary {
  grid-column: 1/3;
  background: var(--ink);
  color: #fff;
}

.difficulty {
  border-top: 1px solid #17201c38;
  border-bottom: 1px solid #17201c38;
  padding: 8px 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.difficulty span {
  margin-right: auto;
  font-weight: 800;
  font-size: 11px;
}

.difficulty button {
  padding: 6px 7px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}

.difficulty button.selected {
  background: #ffd166;
  border-color: var(--line);
}

.desktopAd {
  width: 100%;
  aspect-ratio: 1;
  flex: 0 0 auto;
  margin-inline: auto;
  overflow: hidden;
}

.tip {
  margin: auto 0 0;
  font-size: 10px;
  line-height: 1.6;
  opacity: 0.62;
  border-left: 3px solid #ffd166;
  padding-left: 10px;
}

.tip span {
  font:
    900 9px ui-monospace,
    monospace;
  display: block;
}

.boardWrap {
  padding: clamp(8px, 1.5vh, 16px) clamp(20px, 3.5vw, 48px);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.board {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
  border: 2px solid var(--line);
  background: #ddd7c9;
  box-shadow: 8px 8px 0 #17201c;
  overflow: hidden;
}

.board svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
}

polygon {
  stroke: var(--line);
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition:
    fill 0.18s,
    filter 0.15s;
  outline: none;
}

polygon:hover,
polygon:focus {
  filter: brightness(1.08);
  stroke-width: 5;
}

polygon.rejected {
  animation: rejected 0.16s 3;
}

polygon.hinted {
  animation: hint 0.45s 3;
}

.placementMessage {
  position: absolute;
  z-index: 3;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  border: 1.5px solid var(--line);
  background: #fffdf7;
  box-shadow: 4px 4px 0 var(--line);
  font-size: 14px;
  font-weight: 800;
  text-align: center;
}

.placementMessage[hidden] {
  display: none;
}

@keyframes rejected {
  50% {
    transform: translateX(5px);
    filter: saturate(1.4);
    stroke: #ef476f;
    stroke-width: 8;
  }
}

@keyframes hint {
  50% {
    filter: brightness(1.5);
    stroke-width: 8;
  }
}

.progress {
  position: relative;
  height: 28px;
  margin-top: 10px;
  border: 1.5px solid var(--line);
  background: #fffdf7;
  overflow: hidden;
}

.progress i {
  position: absolute;
  inset: 0 auto 0 0;
  background: #06d6a0;
  border-right: 1.5px solid var(--line);
  transition: width 0.25s;
}

.progress span {
  position: relative;
  display: grid;
  place-items: center;
  height: 100%;
  font:
    900 9px ui-monospace,
    monospace;
  letter-spacing: 0.13em;
}

.win {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #fffdf7ed;
  backdrop-filter: blur(8px);
  animation: appear 0.25s;
  z-index: 4;
  text-align: center;
}

.win[hidden] {
  display: none;
}

.win.gameOver {
  background: #fffdf7a8;
  backdrop-filter: blur(2px);
}

@keyframes appear {
  from {
    opacity: 0;
    transform: scale(1.04);
  }
}

.win .confetti {
  color: #ef476f;
  letter-spacing: 1em;
  animation: float 1s infinite alternate;
}

@keyframes float {
  to {
    transform: translateY(-8px) rotate(4deg);
  }
}

.win>p {
  font:
    900 11px ui-monospace,
    monospace;
  letter-spacing: 0.25em;
  margin: 18px 0 4px;
}

.win h2 {
  font-size: clamp(42px, 7vw, 82px);
  letter-spacing: -0.08em;
  margin: 0 0 22px;
}

.win>div:not(.confetti) {
  display: flex;
  gap: 44px;
  margin-bottom: 28px;
}

.win>div span {
  font:
    900 28px ui-monospace,
    monospace;
}

.win small {
  display: block;
  font: 700 9px sans-serif;
  opacity: 0.5;
  margin-top: 4px;
}

.win button {
  padding: 13px 35px;
  background: var(--ink);
  color: white;
  border: 0;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 5px 5px 0 #ffd166;
}
.gameOver .confetti {
  color: #ef476f;
  letter-spacing: .45em;
}
.gameOver h2 {
  font-size: clamp(34px, 6vw, 68px);
}
.gameOver > div:not(.confetti) {
  font-weight: 700;
  line-height: 1.7;
}

.gameOver button {
  background: #17201cb8;
}

@media (max-width: 850px) {
  .gameShell {
    height: 100svh;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .sidePanel {
    border-right: 0;
    border-bottom: 2px solid var(--line);
    padding: 10px 18px;
    gap: 8px;
  }

  .sidePanel>div:first-child {
    display: block;
  }

  h1 {
    font-size: clamp(22px, 5.8vw, 28px);
  }

  .palette {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }

  .colorBtn {
    min-width: 0;
    height: 58px;
    grid-template-columns: 20px minmax(0, 1fr);
    grid-template-rows: 1fr 1fr;
    gap: 0 4px;
    padding: 6px;
  }

  .colorBtn span {
    grid-column: 1;
    grid-row: 1/3;
    width: 20px;
    height: 40px;
  }

  .colorBtn b,
  .colorBtn em {
    grid-column: 2;
    min-width: 0;
    justify-self: start;
    white-space: nowrap;
  }

  .actions {
    grid-template-columns: 2fr 1fr 1fr;
  }

  .actions .primary {
    grid-column: auto;
  }

  .tip {
    display: none;
  }

  .desktopAd {
    display: none;
  }

  .gameOver {
    position: fixed;
    inset: 0;
    min-height: 100dvh;
    background: #fffdf7b8;
    backdrop-filter: blur(2px);
    padding:
      max(20px, env(safe-area-inset-top))
      max(20px, env(safe-area-inset-right))
      max(20px, env(safe-area-inset-bottom))
      max(20px, env(safe-area-inset-left));
    overflow-y: auto;
    z-index: 20;
  }

  .gameOver > p {
    margin-top: 10px;
  }

  .gameOver h2 {
    margin-bottom: 14px;
    font-size: clamp(30px, 10vw, 48px);
  }

  .gameOver > div:not(.confetti) {
    margin-bottom: 18px;
  }

  .boardWrap {
    padding: 12px 14px 18px;
    min-height: 0;
  }

  .board {
    min-height: 0;
    box-shadow: 5px 5px 0 var(--line);
  }

  .board svg {
    min-height: 0;
  }
}

@media (max-width: 480px) {
  .stats span {
    font-size: 17px;
  }
}

@media (min-width: 851px) and (max-height: 650px) {

  .intro,
  .tip {
    display: none;
  }

  .stats span {
    height: 44px;
  }

  .colorBtn {
    height: 50px;
  }

  .colorBtn span {
    height: 34px;
  }

  .desktopAd {
    width: min(100%, max(80px, calc(100vh - 460px)));
  }
}

@media (min-width: 851px) and (min-height: 651px) and (max-height: 850px) {
  .desktopAd {
    width: min(100%, max(80px, calc(100vh - 570px)));
  }
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
