:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  --bg: #f4f7fb;
  --ink: #172024;
  --muted: #66727a;
  --panel: #ffffff;
  --panel-2: #eef4f2;
  --line: #d7e0e4;
  --field: #294b43;
  --field-dark: #1c332e;
  --tile-a: #f3e58c;
  --tile-b: #7fc9a1;
  --bad: #d94545;
  --good: #1f9f6f;
  --accent: #f06d53;
  --accent-2: #5a83f1;
  --shadow: 0 14px 35px rgb(31 49 58 / 13%);
  --game-width: min(100%, 840px, max(320px, calc((100svh - 250px) * 1.4)));
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 88%), rgb(232 239 245 / 68%)),
    var(--bg);
  color: var(--ink);
}

button {
  border: 0;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: min(100%, 960px);
  min-height: 100svh;
  margin: 0 auto;
  padding:
    calc(10px + env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    calc(14px + env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto auto;
  align-content: start;
  justify-items: center;
  gap: 14px;
}

.hud {
  width: var(--game-width);
  display: grid;
  grid-template-columns: minmax(180px, 0.82fr) minmax(150px, 0.7fr) minmax(0, 1.15fr);
  align-items: stretch;
  overflow: hidden;
  background: rgb(255 255 255 / 90%);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
  padding: 10px 12px;
  border-right: 1px solid var(--line);
}

.brand > div:last-child {
  min-width: 0;
}

.mark {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background:
    radial-gradient(circle at 30% 26%, rgb(255 255 255 / 64%) 0 13%, transparent 14%),
    radial-gradient(circle at 62% 66%, rgb(0 0 0 / 13%) 0 26%, transparent 27%),
    linear-gradient(145deg, #72ddb0 0%, #31aa78 48%, #218a63 100%);
  box-shadow:
    inset 0 -7px 0 rgb(0 0 0 / 13%),
    0 4px 8px rgb(30 55 40 / 16%);
}

h1 {
  margin: 0;
  overflow: hidden;
  font-size: 1.35rem;
  line-height: 1;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 0;
  border-right: 1px solid var(--line);
}

.stat {
  min-width: 0;
  padding: 10px 12px;
  border-right: 1px solid var(--line);
}

.stat:last-child {
  border-right: 0;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  white-space: nowrap;
}

.stat strong {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  font-size: 1.32rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.controls {
  display: none;
}

.tool {
  min-width: 0;
  min-height: 42px;
  border-radius: 8px;
  color: var(--ink);
  background: transparent;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition:
    transform 120ms ease,
    background 120ms ease,
    color 120ms ease;
}

.tool {
  padding: 0 13px;
  background: var(--panel-2);
}

.tool.primary {
  background: var(--ink);
  color: #fff;
}

.tool:active {
  transform: translateY(1px);
}

.tool:focus-visible {
  outline: 3px solid rgb(90 131 241 / 45%);
  outline-offset: 2px;
}

.play {
  position: relative;
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  align-items: start;
  min-height: 0;
  gap: 8px;
}

.board {
  --cols: 9;
  --gap: 4px;
  --board-pad: 8px;
  position: relative;
  width: var(--game-width);
  min-width: 0;
  justify-self: center;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: var(--gap);
  padding: var(--board-pad);
  border: 1px solid rgb(35 73 52 / 32%);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgb(255 255 255 / 7%), rgb(0 0 0 / 12%)),
    var(--field);
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
}

.play-footer {
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 6px;
  padding: 8px 8px 8px 10px;
}

.time-meter {
  min-width: 0;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
}

.time-meter-head {
  display: contents;
}

.time-meter-head span {
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.time-meter-head strong {
  font-size: 1.05rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.time-bar {
  height: 10px;
  min-width: 80px;
  overflow: hidden;
  border-radius: 999px;
  background: #dce6df;
}

.time-bar span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--time-color, #3ebf86);
  transition:
    width 80ms linear,
    background-color 180ms linear,
    background 180ms linear;
}

.icon-tool {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  transition:
    transform 120ms ease,
    background 120ms ease;
}

.icon-tool svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-tool:active {
  transform: translateY(1px);
}

.icon-tool:focus-visible {
  outline: 3px solid rgb(90 131 241 / 45%);
  outline-offset: 2px;
}

.icon-tool[aria-pressed="false"] {
  background: var(--panel-2);
  color: var(--muted);
}

.solution-overlay {
  position: absolute;
  inset: var(--board-pad);
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: var(--gap);
  pointer-events: none;
}

.solution-cell {
  min-width: 0;
  min-height: 0;
  border: 0 solid rgb(255 255 255 / 88%);
  background: color-mix(in srgb, var(--solution-color) 16%, transparent);
  box-shadow: inset 0 0 0 1px rgb(23 32 36 / 16%);
}

.solution-cell.edge-top {
  border-top-width: 3px;
}

.solution-cell.edge-right {
  border-right-width: 3px;
}

.solution-cell.edge-bottom {
  border-bottom-width: 3px;
}

.solution-cell.edge-left {
  border-left-width: 3px;
}

.solution-cell.anchor {
  box-shadow:
    inset 0 0 0 2px rgb(23 32 36 / 55%),
    inset 0 0 0 999px rgb(255 255 255 / 8%);
}

.burst {
  position: absolute;
  z-index: 4;
  transform: translate(-50%, -50%);
  padding: 6px 9px;
  border-radius: 999px;
  background: rgb(23 32 36 / 90%);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 950;
  line-height: 1;
  pointer-events: none;
  animation: burst-pop 620ms ease-out forwards;
  box-shadow: 0 8px 18px rgb(0 0 0 / 22%);
}

.cell {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background:
    linear-gradient(145deg, rgb(255 255 255 / 40%), rgb(255 255 255 / 0%)),
    linear-gradient(135deg, var(--tile-a), var(--tile-b));
  box-shadow:
    inset 0 -4px 0 rgb(37 73 51 / 13%),
    inset 0 1px 0 rgb(255 255 255 / 46%);
  transition:
    opacity 70ms ease,
    transform 70ms ease,
    background 70ms ease,
    box-shadow 70ms ease;
}

.cell.removed {
  opacity: 0.08;
  transform: scale(0.86);
  background: var(--field-dark);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 4%);
}

.cell.selected {
  box-shadow:
    inset 0 0 0 3px rgb(23 32 36 / 62%),
    inset 0 -4px 0 rgb(37 73 51 / 13%);
}

.cell.selected.valid {
  background:
    linear-gradient(145deg, rgb(255 255 255 / 48%), rgb(255 255 255 / 0%)),
    linear-gradient(135deg, #bff0bd, #39c686);
}

.cell.selected.invalid {
  background:
    linear-gradient(145deg, rgb(255 255 255 / 38%), rgb(255 255 255 / 0%)),
    linear-gradient(135deg, #ffd5c8, #ef6f5f);
}

.bubble {
  position: relative;
  width: 72%;
  height: 72%;
  min-width: 20px;
  min-height: 20px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 32% 26%, rgb(255 255 255 / 56%) 0 15%, transparent 16%),
    radial-gradient(circle at 60% 72%, rgb(0 0 0 / 11%) 0 34%, transparent 35%),
    var(--bubble, #2ca6a4);
  box-shadow:
    inset 0 -7px 0 rgb(0 0 0 / 10%),
    inset 0 2px 0 rgb(255 255 255 / 26%),
    0 6px 10px rgb(30 55 40 / 18%);
  color: #fff;
  font-size: 0.98rem;
  line-height: 1;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgb(0 0 0 / 14%);
}

.bubble::before {
  content: "";
  position: absolute;
  top: 16%;
  left: 18%;
  width: 30%;
  height: 20%;
  border-radius: 999px;
  transform: rotate(-22deg);
  background: rgb(255 255 255 / 34%);
  pointer-events: none;
}

.toast {
  width: var(--game-width);
  min-height: 34px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 900;
  text-align: center;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(23 32 29 / 58%);
}

.overlay[hidden] {
  display: none;
}

.result {
  width: min(320px, 100%);
  display: grid;
  gap: 16px;
  padding: 22px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
}

.result span {
  color: var(--muted);
  font-weight: 900;
  text-transform: uppercase;
}

.result strong {
  font-size: 3rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

@keyframes burst-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -45%) scale(0.72);
  }

  22% {
    opacity: 1;
    transform: translate(-50%, -72%) scale(1);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -132%) scale(0.94);
  }
}

@media (max-width: 380px) {
  .app {
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }

  .hud {
    grid-template-columns: 48px minmax(96px, 0.8fr) minmax(0, 1.2fr);
  }

  .brand {
    justify-content: center;
    padding: 8px;
  }

  .brand > div:last-child {
    display: none;
  }

  .mark {
    width: 32px;
    height: 32px;
  }

  h1 {
    font-size: 1.18rem;
  }

  .stat {
    padding: 9px 8px;
  }

  .stat strong {
    font-size: 1.12rem;
  }

  .tool {
    min-height: 40px;
    font-size: 0.82rem;
  }

  .tool {
    padding: 0 10px;
  }

  .board {
    --gap: 3px;
    --board-pad: 7px;
  }
}

@media (min-width: 620px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .board {
    --gap: 5px;
    --board-pad: 10px;
  }

  .bubble {
    font-size: 1.16rem;
  }
}

@media (min-width: 860px) {
  .app {
    width: min(940px, calc(100vw - 40px));
    padding: 24px 0;
    gap: 18px;
  }

  .hud {
    grid-template-columns: 220px 260px minmax(0, 1fr);
  }

  .brand {
    gap: 12px;
    padding: 12px 14px;
  }

  .mark {
    width: 44px;
    height: 44px;
  }

  h1 {
    font-size: 1.85rem;
  }

  .stat {
    padding: 12px 16px;
  }

  .stat strong {
    font-size: 1.55rem;
  }

  .tool {
    min-height: 38px;
    font-size: 0.95rem;
  }

  .tool {
    padding: 0 15px;
  }

  .play {
    grid-template-columns: minmax(280px, 1fr);
    gap: 8px;
  }

  .board {
    --gap: 5px;
    --board-pad: 12px;
  }

  .cell {
    border-radius: 8px;
  }

  .bubble {
    font-size: 1.35rem;
  }

  .toast {
    min-height: 44px;
  }
}

@media (max-height: 700px) and (max-width: 620px) {
  .brand {
    padding-block: 8px;
  }

  .mark {
    width: 34px;
    height: 34px;
  }

  :root {
    --game-width: min(100%, max(260px, calc((100svh - 260px) * 1.4)));
  }
}
