﻿:root {
  --bg0: #03061b;
  --bg1: #0b1238;
  --panel: rgba(8, 14, 38, 0.8);
  --line: rgba(133, 164, 255, 0.35);
  --text: #e8eeff;
  --muted: #9ca9d9;
  --accent: #5ef2ff;
  --size: min(6.7vh, 4.9vw, 64px);
  --gap: clamp(4px, 0.7vh, 8px);
  --piece1: #e95ec8;
  --piece2: #4bd5c6;
  --piece3: #4f4eab;
  --piece4: #7f5cf4;
  --piece5: #b7b8c4;
  --piece6: #696ee8;
  --piece1-rgb: 233 94 200;
  --piece2-rgb: 75 213 198;
  --piece3-rgb: 79 78 171;
  --piece4-rgb: 127 92 244;
  --piece5-rgb: 183 184 196;
  --piece6-rgb: 105 110 232;
  --piece1-hl: 0.24;
  --piece2-hl: 0.24;
  --piece3-hl: 0.24;
  --piece4-hl: 0.24;
  --piece5-hl: 0.24;
  --piece6-hl: 0.24;
  --highlight-rgb: 255 255 255;
  --theme-saturation: 100;
  --tile-radius: 12px;
  --preview-radius: 9px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Noto Sans JP", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 10%, #1c2a70 0%, transparent 32%),
    radial-gradient(circle at 90% 20%, #5a1a8f 0%, transparent 36%),
    linear-gradient(130deg, var(--bg0), var(--bg1) 58%, #0a1d45 100%);
  overflow-x: hidden;
}

.bg-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(42px);
  opacity: 0.35;
  pointer-events: none;
  z-index: -1;
}

.orb-a {
  width: 280px;
  height: 280px;
  top: -80px;
  left: -60px;
  background: #4de0d6;
}

.orb-b {
  width: 300px;
  height: 300px;
  bottom: -120px;
  right: -40px;
  background: #d75bf0;
}

.orb-c {
  width: 180px;
  height: 180px;
  top: 40%;
  right: 20%;
  background: #8678ff;
}

.layout {
  max-width: 1180px;
  margin: 24px auto;
  padding: 12px;
  display: grid;
  grid-template-columns: 1.2fr 0.9fr;
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  backdrop-filter: blur(8px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.game-panel {
  padding: 14px;
}

.game-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 2px 2px 14px;
}

.game-heading h1,
.theme-panel h2 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.02em;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.game-lead {
  max-width: 300px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.hud {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.hud-item {
  min-width: 104px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 9px;
  padding: 6px 10px;
}

.hud-item.score-item {
  min-width: 88px;
  opacity: 0.76;
}

.label {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.hud strong {
  font-size: 18px;
}

.board-wrap {
  margin-top: 12px;
  padding: 10px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  touch-action: none;
}

.how-to {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 13px;
}

.how-to.is-prominent {
  border-color: rgba(94, 242, 255, 0.55);
  background:
    linear-gradient(120deg, rgba(94, 242, 255, 0.11), rgba(127, 92, 244, 0.12)),
    rgba(255, 255, 255, 0.04);
  box-shadow: 0 0 0 1px rgba(94, 242, 255, 0.08), 0 10px 26px rgba(0, 0, 0, 0.2);
}

.how-to summary {
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.how-to p {
  margin: 8px 0 4px;
  line-height: 1.6;
}

.how-to ul {
  margin: 4px 0 0;
  padding-left: 20px;
  line-height: 1.6;
}

.how-to-dismiss {
  display: block;
  margin: 10px 0 0 auto;
  border-color: rgba(94, 242, 255, 0.48);
  background: linear-gradient(180deg, rgba(94, 242, 255, 0.24), rgba(94, 242, 255, 0.08));
  padding: 7px 12px;
}

.how-to:not(.is-prominent) .how-to-dismiss {
  display: none;
}

.how-to-slot-bottom {
  margin-top: 8px;
}

.how-to-slot-bottom .how-to {
  margin-top: 0;
  padding-block: 8px;
}

.texture-neon .board-wrap {
  background:
    radial-gradient(circle at 50% 0%, rgba(90, 120, 255, 0.1), rgba(0, 0, 0, 0) 58%),
    rgba(0, 0, 0, 0.5);
  border-color: rgba(126, 161, 255, 0.22);
  box-shadow:
    inset 0 0 18px rgba(61, 88, 215, 0.2),
    0 0 24px rgba(65, 105, 220, 0.18);
}

.board {
  width: fit-content;
  margin-inline: auto;
  display: grid;
  grid-template-columns: repeat(8, var(--size));
  grid-template-rows: repeat(8, var(--size));
  gap: var(--gap);
}

.cell {
  width: var(--size);
  height: var(--size);
  border-radius: var(--tile-radius);
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 7px 14px rgba(0, 0, 0, 0.3);
  transition: transform 110ms cubic-bezier(.2,.9,.2,1), filter 110ms ease;
  cursor: grab;
  will-change: transform;
}

.cell:hover {
  transform: translateY(-2px) scale(1.025);
}

.cell.selected {
  outline: 2px solid #fff4b1;
  outline-offset: 2px;
}

.cell.keyboard-focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cell.dragging {
  z-index: 3;
  transition: none;
  cursor: grabbing;
  filter: brightness(1.12) saturate(1.08);
}

.cell.special::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 22px;
  color: #fff8cd;
  text-shadow: 0 0 8px rgba(255, 250, 180, 0.9);
}

.cell.special-row::after {
  content: "⇔";
}

.cell.special-col::after {
  content: "⇕";
}

.cell.special-color::after {
  content: "✦";
}

.cell.special-nova {
  box-shadow:
    0 0 0 2px rgba(255, 246, 166, 0.72),
    0 0 20px rgba(94, 242, 255, 0.72),
    inset 0 0 18px rgba(255, 255, 255, 0.35);
}

.cell.special-nova::after {
  content: "✹";
  font-size: 28px;
  color: #fffbd1;
  text-shadow:
    0 0 8px rgba(255, 246, 166, 0.95),
    0 0 16px rgba(94, 242, 255, 0.9);
}

.cell.explode {
  animation: pop-gone 220ms cubic-bezier(.2,.9,.2,1) forwards;
  box-shadow:
    0 0 0 1px rgb(var(--highlight-rgb) / 0.14),
    0 0 12px rgb(var(--highlight-rgb) / 0.34),
    0 0 22px rgb(var(--highlight-rgb) / 0.24),
    inset 0 0 10px rgb(var(--highlight-rgb) / 0.1);
}

.cell.explode::before {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: calc(var(--tile-radius) + 2px);
  background:
    radial-gradient(circle, rgb(var(--highlight-rgb) / 0.62) 0%, rgb(var(--highlight-rgb) / 0.28) 24%, rgb(var(--highlight-rgb) / 0) 66%),
    conic-gradient(from 0deg, rgb(var(--highlight-rgb) / 0), rgb(var(--highlight-rgb) / 0.20), rgb(var(--highlight-rgb) / 0));
  mix-blend-mode: screen;
  animation: flash-ring 220ms ease-out forwards;
  pointer-events: none;
}

.cell.empty {
  border: 1px dashed rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.03);
  box-shadow: none;
  cursor: default;
  pointer-events: none;
}

.board.busy .cell {
  pointer-events: none;
}

.board.celebrate {
  animation: board-pop 240ms ease-out;
}

@keyframes pop-gone {
  0% {
    transform: scale(1);
    opacity: 1;
    filter: brightness(1) saturate(1);
  }
  35% {
    transform: scale(1.16);
    opacity: 1;
    filter: brightness(1.55) saturate(1.35);
  }
  100% {
    transform: scale(0.36);
    opacity: 0;
    filter: brightness(1.3) saturate(1.2);
  }
}

@keyframes flash-ring {
  0% {
    transform: scale(0.58) rotate(0deg);
    opacity: 0.95;
  }
  100% {
    transform: scale(1.48) rotate(20deg);
    opacity: 0;
  }
}

@keyframes board-pop {
  0% {
    box-shadow: 0 0 0 rgba(111, 247, 255, 0);
  }
  45% {
    box-shadow: 0 0 26px rgba(111, 247, 255, 0.45), inset 0 0 24px rgba(255, 255, 255, 0.08);
  }
  100% {
    box-shadow: 0 0 0 rgba(111, 247, 255, 0);
  }
}

.texture-gloss .cell:not(.empty) {
  background-image: linear-gradient(160deg, rgb(var(--highlight-rgb) / calc(var(--hl-alpha, 0.24) * 0.78)), rgb(var(--highlight-rgb) / calc(var(--hl-alpha, 0.24) * 0.16)) 35%, rgba(0, 0, 0, 0.15));
  filter: saturate(calc(var(--theme-saturation) / 100));
}

.texture-neon .cell:not(.empty) {
  background-image:
    radial-gradient(circle at 24% 20%, rgb(var(--glow-rgb, var(--highlight-rgb)) / calc(var(--hl-alpha, 0.24) * 1.05)), rgb(var(--glow-rgb, var(--highlight-rgb)) / 0) 36%),
    radial-gradient(120% 74% at 50% 100%, rgb(var(--glow-rgb, var(--highlight-rgb)) / calc(var(--hl-alpha, 0.24) * 0.92)), rgb(var(--glow-rgb, var(--highlight-rgb)) / 0) 72%),
    linear-gradient(160deg, rgb(var(--glow-rgb, var(--highlight-rgb)) / calc(var(--hl-alpha, 0.24) * 0.24)), rgba(0, 0, 0, 0.16));
  box-shadow:
    0 0 0 1px rgb(var(--glow-rgb, var(--highlight-rgb)) / 0.36),
    0 0 16px rgb(var(--glow-rgb, var(--highlight-rgb)) / 0.42),
    0 0 30px rgb(var(--glow-rgb, var(--highlight-rgb)) / 0.26),
    0 0 48px rgb(var(--glow-rgb, var(--highlight-rgb)) / 0.13),
    inset 0 10px 14px rgb(var(--glow-rgb, var(--highlight-rgb)) / 0.2),
    inset 0 -7px 10px rgba(0, 0, 0, 0.12);
  border-color: rgb(var(--glow-rgb, var(--highlight-rgb)) / 0.6);
  filter: saturate(calc((var(--theme-saturation) / 100) * 1.14));
}

.texture-glass .cell:not(.empty) {
  background-image:
    linear-gradient(180deg, rgb(var(--glow-rgb, var(--highlight-rgb)) / calc(var(--hl-alpha, 0.24) * 0.94)), rgb(var(--glow-rgb, var(--highlight-rgb)) / calc(var(--hl-alpha, 0.24) * 0.36)) 22%, rgb(var(--glow-rgb, var(--highlight-rgb)) / calc(var(--hl-alpha, 0.24) * 0.11)) 46%, rgba(0, 0, 0, 0.14)),
    linear-gradient(132deg, rgb(var(--highlight-rgb) / calc(var(--hl-alpha, 0.24) * 0.28)), rgb(var(--highlight-rgb) / 0) 62%);
  border-color: rgb(var(--glow-rgb, var(--highlight-rgb)) / 0.4);
  box-shadow:
    0 10px 20px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgb(var(--highlight-rgb) / 0.52),
    inset 0 -10px 16px rgba(0, 0, 0, 0.24);
  filter: saturate(calc(var(--theme-saturation) / 100));
}

.texture-matte .cell:not(.empty) {
  background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.05), rgba(0, 0, 0, 0.22));
  box-shadow: 0 6px 10px rgba(0, 0, 0, 0.35);
  filter: saturate(calc(var(--theme-saturation) / 100));
}

.color-1 { background-color: var(--piece1); --hl-alpha: var(--piece1-hl); --glow-rgb: var(--piece1-rgb); }
.color-2 { background-color: var(--piece2); --hl-alpha: var(--piece2-hl); --glow-rgb: var(--piece2-rgb); }
.color-3 { background-color: var(--piece3); --hl-alpha: var(--piece3-hl); --glow-rgb: var(--piece3-rgb); }
.color-4 { background-color: var(--piece4); --hl-alpha: var(--piece4-hl); --glow-rgb: var(--piece4-rgb); }
.color-5 { background-color: var(--piece5); --hl-alpha: var(--piece5-hl); --glow-rgb: var(--piece5-rgb); }
.color-6 { background-color: var(--piece6); --hl-alpha: var(--piece6-hl); --glow-rgb: var(--piece6-rgb); }

.actions, .theme-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button, input, select {
  font: inherit;
}

button {
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.06));
  color: var(--text);
  padding: 9px 12px;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.12);
}

button:focus-visible,
summary:focus-visible,
.board:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.status {
  margin: 12px 2px 0;
  color: #dcf8ff;
  min-height: 24px;
}

.meta {
  margin: 4px 2px 0;
  color: var(--muted);
}

.theme-panel {
  padding: 14px;
}

.theme-panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.theme-panel-toggle {
  flex: 0 0 auto;
  padding: 7px 10px;
  font-size: 12px;
}

.theme-panel-body[hidden] {
  display: none;
}

.sub {
  margin: 6px 0 12px;
  color: var(--muted);
}

.theme-control {
  margin-bottom: 10px;
}

.theme-control label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

.theme-control input,
.theme-control select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(4, 7, 20, 0.66);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
}

.theme-catalog {
  max-height: 280px;
  overflow: auto;
  display: grid;
  gap: 8px;
  padding-right: 2px;
}

.theme-item {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  padding: 8px;
  text-align: left;
  display: grid;
  gap: 6px;
}

.theme-item.active {
  border-color: rgba(94, 242, 255, 0.8);
  box-shadow: 0 0 0 1px rgba(94, 242, 255, 0.35);
}

.theme-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.theme-item-name {
  font-size: 13px;
  color: var(--text);
}

.theme-item-meta {
  font-size: 11px;
  color: var(--muted);
}

.theme-item-swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.theme-item-swatches span {
  height: 12px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

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

.inline-controls small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.theme-preview {
  --preview-size: 38px;
  display: grid;
  grid-template-columns: repeat(3, var(--preview-size));
  grid-template-rows: repeat(3, var(--preview-size));
  gap: 6px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  width: fit-content;
}

.preview-cell {
  width: var(--preview-size);
  height: var(--preview-size);
  border-radius: var(--preview-radius);
  border: 1px solid rgba(255, 255, 255, 0.26);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.28);
}

.theme-preview.texture-gloss .preview-cell {
  background-image: linear-gradient(160deg, rgb(var(--highlight-rgb) / calc(var(--hl-alpha, 0.24) * 0.78)), rgb(var(--highlight-rgb) / calc(var(--hl-alpha, 0.24) * 0.16)) 35%, rgba(0, 0, 0, 0.15));
  filter: saturate(calc(var(--theme-saturation) / 100));
}

.theme-preview.texture-neon .preview-cell {
  background-image:
    radial-gradient(circle at 24% 20%, rgb(var(--glow-rgb, var(--highlight-rgb)) / calc(var(--hl-alpha, 0.24) * 1.05)), rgb(var(--glow-rgb, var(--highlight-rgb)) / 0) 36%),
    radial-gradient(120% 74% at 50% 100%, rgb(var(--glow-rgb, var(--highlight-rgb)) / calc(var(--hl-alpha, 0.24) * 0.92)), rgb(var(--glow-rgb, var(--highlight-rgb)) / 0) 72%),
    linear-gradient(160deg, rgb(var(--glow-rgb, var(--highlight-rgb)) / calc(var(--hl-alpha, 0.24) * 0.24)), rgba(0, 0, 0, 0.16));
  box-shadow:
    0 0 0 1px rgb(var(--glow-rgb, var(--highlight-rgb)) / 0.38),
    0 0 10px rgb(var(--glow-rgb, var(--highlight-rgb)) / 0.4),
    0 0 18px rgb(var(--glow-rgb, var(--highlight-rgb)) / 0.24),
    inset 0 6px 8px rgb(var(--glow-rgb, var(--highlight-rgb)) / 0.18),
    inset 0 -4px 8px rgba(0, 0, 0, 0.1);
  filter: saturate(calc((var(--theme-saturation) / 100) * 1.12));
}

.theme-preview.texture-glass .preview-cell {
  background-image:
    linear-gradient(180deg, rgb(var(--glow-rgb, var(--highlight-rgb)) / calc(var(--hl-alpha, 0.24) * 0.94)), rgb(var(--glow-rgb, var(--highlight-rgb)) / calc(var(--hl-alpha, 0.24) * 0.36)) 22%, rgb(var(--glow-rgb, var(--highlight-rgb)) / calc(var(--hl-alpha, 0.24) * 0.11)) 46%, rgba(0, 0, 0, 0.14)),
    linear-gradient(132deg, rgb(var(--highlight-rgb) / calc(var(--hl-alpha, 0.24) * 0.28)), rgb(var(--highlight-rgb) / 0) 62%);
  box-shadow:
    0 7px 14px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgb(var(--highlight-rgb) / 0.52),
    inset 0 -8px 12px rgba(0, 0, 0, 0.24);
  filter: saturate(calc(var(--theme-saturation) / 100));
}

.theme-preview.texture-matte .preview-cell {
  background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.05), rgba(0, 0, 0, 0.22));
  filter: saturate(calc(var(--theme-saturation) / 100));
}

.color-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.color-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 8px;
}

.color-item span {
  flex: 1;
  font-size: 12px;
  color: var(--muted);
}

.color-item input {
  width: 52px;
  height: 32px;
  padding: 0;
  border: none;
  background: transparent;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
    margin: 8px auto;
    padding: 4px;
  }

  :root {
    --size: min(10vw, 6.5vh, 58px);
    --gap: 5px;
  }

  .game-panel,
  .theme-panel {
    padding: 10px;
  }

  .game-heading {
    align-items: start;
    margin-bottom: 10px;
  }

  .game-lead {
    max-width: 190px;
    font-size: 12px;
  }

  .board-wrap {
    padding: 6px;
  }

  .actions button,
  .theme-actions button {
    min-width: 0;
    max-width: 100%;
  }

  .theme-panel-header {
    align-items: center;
  }

  .theme-panel h2 {
    font-size: 24px;
  }

  .theme-panel-header .sub {
    margin-bottom: 0;
  }
}

@media (max-width: 600px) {
  .board {
    width: 100%;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-template-rows: none;
  }

  .cell {
    width: auto;
    height: auto;
    aspect-ratio: 1;
    border-radius: min(var(--tile-radius), 2.4vw);
  }

  .game-heading {
    display: block;
  }

  .game-lead {
    max-width: none;
    margin-top: 6px;
    text-align: left;
  }

  .hud {
    display: grid;
    grid-template-columns: 0.78fr 1fr 1fr;
  }

  .hud-item,
  .hud-item.score-item {
    min-width: 0;
    gap: 4px;
    padding: 5px 7px;
  }

  .hud strong {
    font-size: 17px;
  }

  .how-to {
    padding: 9px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
