:root {
  color-scheme: dark;
  --ink: #f8fbff;
  --muted: #9aa8cc;
  --line: rgba(145, 176, 255, 0.22);
  --panel: rgba(9, 15, 47, 0.74);
  --cyan: #58eaff;
  --violet: #a05cff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; min-height: 100%; background: #050719; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -10%, rgba(58, 120, 255, .27), transparent 43%),
    radial-gradient(circle at 12% 78%, rgba(153, 57, 255, .17), transparent 33%),
    radial-gradient(circle at 90% 72%, rgba(0, 225, 255, .12), transparent 30%),
    #050719;
}

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

body::before {
  opacity: .32;
  background-image:
    radial-gradient(circle, #fff 0 1px, transparent 1.3px),
    radial-gradient(circle, #85bdff 0 1px, transparent 1.4px);
  background-position: 0 0, 38px 62px;
  background-size: 97px 97px, 149px 149px;
}

body::after {
  background: linear-gradient(90deg, transparent, rgba(119, 164, 255, .08), transparent);
  transform: rotate(-12deg) scale(1.5);
  filter: blur(30px);
}

button { font: inherit; }
button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.aurora {
  position: fixed;
  z-index: -1;
  width: 54vw;
  height: 54vw;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: conic-gradient(from 90deg, rgba(29, 213, 255, .08), rgba(140, 56, 255, .13), rgba(255, 53, 178, .06), rgba(29, 213, 255, .08));
  filter: blur(55px);
  animation: breathe 8s ease-in-out infinite alternate;
}

.app {
  width: min(1440px, 100%);
  min-height: 100vh;
  min-height: 100svh;
  margin: auto;
  padding: 22px clamp(18px, 4vw, 64px) 16px;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 12px;
}

.brand { position: relative; padding-top: 7px; }
.brand-kicker {
  position: absolute;
  top: 0;
  left: 3px;
  color: #a4c8ff;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .52em;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(27px, 3.3vw, 47px);
  font-style: italic;
  line-height: 1;
  letter-spacing: -.055em;
  text-shadow: 0 0 22px rgba(127, 193, 255, .5), 0 2px 0 #274a91;
}

h1 span {
  color: transparent;
  background: linear-gradient(#eafcff 13%, #6cecff 50%, #8c6dff 78%);
  background-clip: text;
  -webkit-background-clip: text;
  text-shadow: none;
}

.controls { display: flex; align-items: center; gap: 9px; }

.icon-button,
.text-button,
.hint-button {
  min-height: 42px;
  border: 1px solid var(--line);
  color: #eaf5ff;
  background: rgba(12, 22, 62, .64);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.09), 0 7px 20px rgba(0,0,0,.15);
  cursor: pointer;
  transition: border-color .18s, background .18s, transform .18s;
}

.icon-button:hover,
.text-button:hover,
.hint-button:hover { border-color: #66e9ff; background: rgba(24, 48, 107, .8); transform: translateY(-1px); }
.hint-button:disabled { opacity: .45; cursor: wait; transform: none; }
.icon-button { width: 42px; padding: 9px; border-radius: 50%; }
.icon-button svg { width: 100%; height: 100%; fill: currentColor; }
.icon-button.muted { color: #5f6c8d; }
.text-button { border-radius: 20px; padding: 8px 17px; font-size: 13px; font-weight: 750; white-space: nowrap; }

.game-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(150px, 230px) minmax(400px, 710px) minmax(160px, 240px);
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 2.6vw, 40px);
}

.panel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(150deg, rgba(19, 31, 79, .77), rgba(6, 10, 35, .68));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 20px 70px rgba(0,0,0,.22);
  backdrop-filter: blur(15px);
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(120deg, rgba(255,255,255,.06), transparent 35%);
}

.score-panel { padding: 26px 22px 20px; text-align: center; }
.eyebrow { margin: 0 0 7px; color: #8db7ee; font-size: 10px; font-weight: 900; letter-spacing: .28em; }
.score { display: block; font-size: clamp(28px, 3.2vw, 45px); font-weight: 300; line-height: 1.1; letter-spacing: -.055em; }

.level-medallion {
  width: min(128px, 82%);
  aspect-ratio: 1;
  margin: 26px auto;
  display: grid;
  place-content: center;
  border: 1px solid rgba(102, 233, 255, .44);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(60, 156, 255, .22), rgba(29, 21, 87, .45) 55%, transparent 57%), conic-gradient(from 20deg, #56eaff, #795eff, #d050ff, #56eaff);
  box-shadow: inset 0 0 0 8px #0d123a, inset 0 0 25px #33caff, 0 0 32px rgba(83, 138, 255, .35);
}

.level-medallion span { color: #a6c2ed; font-size: 9px; font-weight: 900; letter-spacing: .25em; }
.level-medallion strong { font: italic 700 48px/1 Georgia, serif; text-shadow: 0 0 17px #56d6ff; }

.mini-stats { margin: 0; text-align: left; }
.mini-stats div { display: flex; justify-content: space-between; gap: 8px; padding: 10px 2px; border-top: 1px solid rgba(132, 165, 230, .13); }
.mini-stats dt { color: var(--muted); font-size: 11px; }
.mini-stats dd { margin: 0; color: #dff5ff; font-size: 12px; font-weight: 800; }

.board-column { width: 100%; }
.board-frame {
  position: relative;
  aspect-ratio: 1;
  padding: clamp(7px, 1vw, 12px);
  border: 1px solid rgba(126, 199, 255, .44);
  border-radius: clamp(18px, 2vw, 28px);
  background: linear-gradient(145deg, rgba(107, 189, 255, .32), rgba(43, 21, 114, .5) 17%, rgba(4, 8, 30, .9) 58%, rgba(47, 94, 175, .32));
  box-shadow: inset 0 0 0 3px rgba(7, 11, 38, .8), inset 0 0 28px rgba(61, 151, 255, .2), 0 26px 90px rgba(0,0,0,.48), 0 0 45px rgba(54, 111, 255, .16);
}

.board-frame::before,
.board-frame::after {
  content: "◆";
  position: absolute;
  z-index: 2;
  top: -12px;
  color: #6de5ff;
  font-size: 17px;
  text-shadow: 0 0 10px #2ad8ff;
}
.board-frame::before { left: 17px; }
.board-frame::after { right: 17px; }

.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: clamp(2px, .35vw, 5px);
  padding: clamp(4px, .5vw, 7px);
  overflow: hidden;
  border: 1px solid rgba(125, 175, 255, .24);
  border-radius: clamp(12px, 1.5vw, 19px);
  background: rgba(2, 5, 22, .74);
  box-shadow: inset 0 0 45px rgba(0,0,0,.67);
  touch-action: none;
}

.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 5%;
  border: 0;
  border-radius: 13%;
  background: linear-gradient(145deg, rgba(61, 89, 156, .18), rgba(9, 15, 48, .28));
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.cell:hover:not(:disabled) { background: rgba(83, 145, 230, .16); }
.cell:disabled { cursor: default; }
.cell.selected { z-index: 3; background: rgba(98, 217, 255, .18); box-shadow: inset 0 0 0 2px #b8f6ff, 0 0 18px #3dd7ff; }
.cell.hint { z-index: 3; animation: hint-cell .55s ease-in-out infinite alternate; }
.cell.invalid { animation: reject .18s linear 2; }

.gem {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 7px 5px rgba(0,0,0,.52));
  transition: transform .14s ease, filter .14s ease;
}
.cell:hover:not(:disabled) .gem { transform: translateY(-2px) scale(1.035); filter: drop-shadow(0 9px 6px rgba(0,0,0,.44)) brightness(1.12); }

.gem::before {
  content: "";
  position: absolute;
  inset: 3%;
  background: var(--gem);
  clip-path: var(--shape);
  box-shadow: inset 0 0 12px rgba(255,255,255,.7), inset 0 -12px 18px rgba(0,0,0,.25);
}

.gem::after {
  content: "";
  position: absolute;
  inset: 14% 23% 52% 28%;
  border-radius: 50%;
  background: linear-gradient(145deg, rgba(255,255,255,.92), rgba(255,255,255,0));
  filter: blur(.5px);
  transform: rotate(-18deg);
}

.gem i {
  position: absolute;
  z-index: 2;
  inset: 15%;
  display: block;
  clip-path: var(--shape);
  border: 1px solid rgba(255,255,255,.25);
  background: linear-gradient(135deg, rgba(255,255,255,.18), transparent 38%, rgba(0,0,0,.13) 72%, rgba(255,255,255,.1));
}

.gem-red { --gem: linear-gradient(145deg, #ffb0ba 2%, #ff3153 31%, #ad062d 70%, #5c031c); --shape: polygon(22% 4%, 78% 4%, 96% 25%, 86% 84%, 50% 100%, 14% 84%, 4% 25%); }
.gem-orange { --gem: radial-gradient(ellipse at 37% 27%, #ffe7b1, #ff9c22 32%, #e64b0e 69%, #7a1704); --shape: ellipse(44% 49% at 50% 50%); }
.gem-yellow { --gem: linear-gradient(145deg, #fffed0, #fff033 34%, #e5a800 71%, #7d5300); --shape: polygon(50% 0, 64% 20%, 88% 14%, 82% 39%, 100% 55%, 78% 68%, 78% 94%, 52% 84%, 29% 100%, 24% 72%, 0 59%, 20% 41%, 12% 14%, 38% 20%); }
.gem-green { --gem: linear-gradient(145deg, #c9ffb6, #59eb5a 29%, #139b4b 68%, #07552d); --shape: polygon(22% 3%, 79% 3%, 98% 25%, 79% 97%, 22% 97%, 2% 25%); }
.gem-blue { --gem: linear-gradient(145deg, #e4fcff, #3dcaff 29%, #166cf0 63%, #172b8d); --shape: polygon(50% 0, 96% 34%, 75% 90%, 50% 100%, 25% 90%, 4% 34%); }
.gem-white { --gem: radial-gradient(circle at 34% 25%, #fff, #d9f7ff 27%, #8eb9e7 62%, #53629d); --shape: polygon(50% 0, 85% 14%, 100% 50%, 85% 86%, 50% 100%, 15% 86%, 0 50%, 15% 14%); }
.gem-purple { --gem: linear-gradient(145deg, #f5c0ff, #c34eff 31%, #7b17c5 65%, #38056e); --shape: polygon(50% 0, 96% 85%, 76% 100%, 24% 100%, 4% 85%); }

.special-flame { animation: flame-glow .75s ease-in-out infinite alternate; }
.special-flame i { inset: 5%; border: 2px solid #ffda58; filter: drop-shadow(0 0 5px #ff7a18); }
.special-flame::after { inset: 1%; background: radial-gradient(circle, transparent 35%, #fff26b 40%, #ff6b10 51%, transparent 63%); filter: none; animation: spin 1.6s linear infinite; }

.special-star i { inset: 6%; border: 0; clip-path: polygon(47% 0, 57% 38%, 100% 47%, 59% 57%, 50% 100%, 41% 58%, 0 49%, 40% 40%); background: #fff; filter: drop-shadow(0 0 5px #fff) drop-shadow(0 0 9px #60d7ff); animation: star-pulse .7s ease-in-out infinite alternate; }

.special-hypercube { --shape: circle(47%); animation: cube-pulse 1s ease-in-out infinite alternate; }
.special-hypercube::before { background: conic-gradient(from 30deg, #54f5ff, #735cff, #ff4ab3, #ffed5a, #54f5ff); box-shadow: inset 0 0 15px 8px #050615, 0 0 11px #75eaff; }
.special-hypercube::after { inset: 15%; border-radius: 50%; background: repeating-conic-gradient(#fff 0 4deg, transparent 5deg 18deg); opacity: .75; filter: drop-shadow(0 0 4px #fff); animation: spin 4s linear infinite; }
.special-hypercube i { inset: 26%; border: 2px solid #fff; border-radius: 50%; clip-path: none; background: #111330; box-shadow: 0 0 10px #fff; }

.special-supernova { animation: cube-pulse .55s ease-in-out infinite alternate; }
.special-supernova i { inset: -3%; border: 0; clip-path: circle(48%); background: conic-gradient(transparent 0 12%, #fff 13% 15%, transparent 16% 32%, #6ef4ff 33% 36%, transparent 37% 62%, #fff 63% 66%, transparent 67%); filter: drop-shadow(0 0 6px #fff); animation: spin 1.3s linear infinite; }

.cell.clearing .gem { animation: vanish .27s ease-in forwards; }

.board-message {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%) scale(.8);
  width: max-content;
  max-width: 90%;
  opacity: 0;
  pointer-events: none;
  color: #fff;
  font: italic 800 clamp(25px, 4vw, 48px)/1 Georgia, serif;
  letter-spacing: -.03em;
  text-shadow: 0 0 8px #fff, 0 0 20px #3bd9ff, 0 4px 2px #271465;
}
.board-message.show { animation: message 1s ease both; }

.level-progress { margin: 13px 7px 0; }
.progress-copy { display: flex; justify-content: space-between; margin: 0 4px 6px; color: #9eb2d8; font-size: 10px; font-weight: 800; letter-spacing: .12em; }
.progress-track { position: relative; height: 15px; overflow: hidden; border: 1px solid rgba(131, 204, 255, .32); border-radius: 10px; background: rgba(2,5,24,.84); box-shadow: inset 0 2px 7px rgba(0,0,0,.7), 0 0 15px rgba(53,146,255,.16); }
.progress-fill { position: absolute; inset: 2px auto 2px 2px; width: 0; border-radius: 7px; background: linear-gradient(90deg, #5b55ff, #3be4ff 65%, #fff); box-shadow: 0 0 9px #41dfff; transition: width .35s ease; }
.progress-track i { position: relative; z-index: 2; display: inline-block; width: calc(20% - 3px); height: 100%; border-right: 1px solid rgba(255,255,255,.12); }

.info-panel { padding: 24px 20px 20px; }
.special-list > div { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid rgba(131, 166, 230, .12); }
.special-list p { margin: 0; }
.special-list b { display: block; color: #e7f7ff; font-size: 10px; letter-spacing: .12em; }
.special-list small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.mini-gem { position: relative; flex: 0 0 36px; width: 36px; height: 36px; border-radius: 50%; }
.mini-gem.flame { background: radial-gradient(circle, #fff 7%, #ffda47 22%, #ff5715 48%, #7321a4 67%, transparent 69%); filter: drop-shadow(0 0 6px #ff741e); }
.mini-gem.star { clip-path: polygon(50% 0, 61% 35%, 100% 50%, 63% 61%, 50% 100%, 39% 63%, 0 50%, 37% 39%); background: linear-gradient(135deg,#fff,#53d8ff 48%,#7d4eff); filter: drop-shadow(0 0 5px #5ee1ff); }
.mini-gem.hypercube { border: 5px solid #18183a; background: conic-gradient(#55eaff,#835cff,#ff54c5,#ffe95b,#55eaff); box-shadow: 0 0 7px #67e8ff, inset 0 0 5px #000; }

.hint-button { width: 100%; margin-top: 22px; padding: 10px 14px; display: flex; align-items: center; justify-content: center; gap: 8px; border-radius: 20px; font-size: 12px; font-weight: 850; letter-spacing: .08em; }
.hint-button svg { width: 17px; fill: #ffee80; filter: drop-shadow(0 0 4px #ffdf31); }
.info-tip { margin: 13px 5px 0; color: #7f8eb5; font-size: 10px; line-height: 1.6; text-align: center; }

footer { display: flex; justify-content: space-between; gap: 20px; margin-top: 12px; color: rgba(144,160,200,.56); font-size: 8px; font-weight: 700; letter-spacing: .15em; }

.modal {
  width: min(480px, calc(100% - 30px));
  padding: 0;
  overflow: visible;
  border: 1px solid rgba(112, 217, 255, .48);
  border-radius: 26px;
  color: var(--ink);
  background: linear-gradient(150deg, #17265b, #090d2c 58%, #1b0e43);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12), 0 30px 100px #000, 0 0 40px rgba(54,150,255,.2);
}
.modal::backdrop { background: rgba(1, 3, 14, .78); backdrop-filter: blur(9px); }
.modal form { position: relative; padding: 35px; }
.modal h2 { margin: 3px 0 14px; font: italic 700 33px/1 Georgia, serif; }
.modal p, .modal li { color: #b8c5e1; font-size: 13px; line-height: 1.65; }
.modal ul { padding-left: 20px; }
.modal li { margin: 7px 0; }
.modal li b { color: #effaff; }
.modal-close { position: absolute; top: 13px; right: 15px; width: 36px; height: 36px; border: 0; border-radius: 50%; color: #aab8da; background: rgba(255,255,255,.06); font-size: 24px; cursor: pointer; }
.keyboard-tip { color: #7f91b8 !important; font-size: 11px !important; }
.primary-button { width: 100%; margin-top: 12px; padding: 12px 20px; border: 1px solid #6ee9ff; border-radius: 24px; color: #fff; background: linear-gradient(90deg,#5a5cf2,#228fdc); box-shadow: inset 0 1px 0 rgba(255,255,255,.22), 0 0 20px rgba(50,183,255,.2); font-weight: 800; cursor: pointer; }

.game-over-modal { text-align: center; }
.game-over-gem { width: 82px; height: 82px; margin: -75px auto 17px; clip-path: polygon(50% 0, 96% 34%, 75% 90%, 50% 100%, 25% 90%, 4% 34%); background: linear-gradient(145deg,#fff,#52d8ff 25%,#3457f1 64%,#24166d); filter: drop-shadow(0 0 15px #4edaff); }
.final-score { margin: 21px 0 15px; padding: 17px; border-block: 1px solid rgba(122,177,240,.17); }
.final-score span { display: block; color: #8098c6; font-size: 9px; letter-spacing: .24em; }
.final-score strong { display: block; margin-top: 5px; font-size: 40px; font-weight: 300; }

.visually-hidden { position: fixed; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }

@keyframes breathe { to { transform: translate(-50%,-50%) scale(1.12) rotate(12deg); opacity: .7; } }
@keyframes spin { to { transform: rotate(342deg); } }
@keyframes flame-glow { to { filter: drop-shadow(0 2px 7px #ff5b18) brightness(1.2); transform: scale(1.04); } }
@keyframes star-pulse { to { transform: scale(1.2) rotate(8deg); opacity: .72; } }
@keyframes cube-pulse { to { filter: drop-shadow(0 0 10px #6ff) brightness(1.22); transform: scale(1.04); } }
@keyframes vanish { 45% { transform: scale(1.16); filter: brightness(2.8) drop-shadow(0 0 12px white); } to { transform: scale(.08) rotate(30deg); opacity: 0; } }
@keyframes hint-cell { to { background: rgba(255,240,104,.17); box-shadow: inset 0 0 0 2px #fff176, 0 0 19px #ffce38; } }
@keyframes reject { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes message { 0% { opacity: 0; transform: translate(-50%,-50%) scale(.65); } 22%,70% { opacity: 1; transform: translate(-50%,-50%) scale(1); } 100% { opacity: 0; transform: translate(-50%,-58%) scale(1.08); } }

@media (max-width: 960px) {
  .app { padding-inline: 16px; }
  .game-layout { grid-template-columns: minmax(100px, 150px) minmax(400px, 650px); }
  .info-panel { grid-column: 1 / -1; width: min(650px, calc(100% - 166px)); justify-self: end; display: flex; align-items: center; gap: 16px; padding: 10px 14px; }
  .info-panel .eyebrow, .info-tip { display: none; }
  .special-list { display: flex; flex: 1; }
  .special-list > div { flex: 1; padding: 4px 10px; border: 0; }
  .mini-gem { flex-basis: 29px; width: 29px; height: 29px; }
  .hint-button { width: auto; min-width: 96px; margin: 0; }
}

@media (max-width: 680px) {
  .app { padding: 12px 10px 10px; }
  .topbar { margin-bottom: 12px; }
  .text-button { padding-inline: 12px; }
  .game-layout { display: flex; flex-direction: column; gap: 10px; }
  .board-column { order: 1; }
  .score-panel { order: 0; width: 100%; padding: 10px 14px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
  .score-panel > .eyebrow { display: none; }
  .score { font-size: 25px; text-align: left; }
  .level-medallion { width: 61px; margin: 0 8px; }
  .level-medallion strong { font-size: 25px; }
  .level-medallion span { font-size: 6px; }
  .mini-stats { display: flex; justify-content: flex-end; }
  .mini-stats div { display: none; }
  .mini-stats div:first-child { display: block; padding: 0; border: 0; text-align: right; }
  .mini-stats dt { font-size: 8px; }
  .mini-stats dd { margin-top: 2px; font-size: 11px; }
  .info-panel { order: 2; width: 100%; padding: 9px 11px; }
  .special-list { display: none; }
  .hint-button { width: 100%; }
  footer { margin-top: 10px; justify-content: center; }
  footer span:last-child { display: none; }
  .modal form { padding: 30px 24px 24px; }
}

@media (max-width: 360px) {
  .topbar { gap: 8px; }
  .controls { gap: 5px; }
  .icon-button { width: 38px; min-height: 38px; padding: 8px; }
  .text-button { min-height: 38px; padding-inline: 9px; font-size: 12px; }
}

@media (max-height: 800px) and (min-width: 681px) {
  .app { padding-block: 10px; }
  .game-layout { grid-template-columns: minmax(130px, 190px) minmax(400px, calc(100vh - 155px)) minmax(145px, 200px); gap: 20px; }
  .score-panel, .info-panel { padding: 18px 16px; }
  .level-medallion { width: 100px; margin-block: 17px; }
  .level-medallion strong { font-size: 38px; }
  .special-list > div { padding-block: 9px; }
}

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