:root {
  --ink: #141620;
  --ink-2: #262936;
  --red: #ee5064;
  --red-dark: #c93d50;
  --white: #f8f7f3;
  --pale: #c5c6ca;
  --gray: #777a83;
  --line: rgba(255, 255, 255, 0.86);
  --cell: clamp(38px, 8.7vw, 62px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100svh;
  color: var(--white);
  font-family: "Arial Rounded MT Bold", "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  background:
    linear-gradient(180deg, rgba(238, 80, 100, 0.95) 0 70px, transparent 70px),
    radial-gradient(circle at 50% -5%, rgba(255, 255, 255, 0.16), transparent 30%),
    #11131d;
  display: grid;
  place-items: center;
  overflow: hidden;
}

button {
  font: inherit;
}

.shell {
  width: min(100vw, calc(100svh * 9 / 16), 760px);
  height: min(100svh, calc(100vw * 16 / 9));
  max-height: 100svh;
  min-height: 0;
  aspect-ratio: 9 / 16;
  padding: clamp(12px, 2.4vh, 24px) clamp(8px, 2vw, 18px) 12px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
  overflow: hidden;
}

.top-panel {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  align-items: stretch;
  background: rgba(248, 247, 243, 0.98);
  color: var(--ink);
  border: 4px solid var(--ink);
  border-radius: 28px;
  box-shadow: 0 9px 0 rgba(0, 0, 0, 0.16);
  min-height: 126px;
}

.stat {
  position: relative;
  display: grid;
  place-items: center;
  padding: 28px 18px 14px;
  border-right: 3px solid var(--ink);
}

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

.label {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--white);
  border-radius: 12px;
  padding: 8px 22px;
  font-size: clamp(14px, 2vw, 22px);
  letter-spacing: 0;
}

.mission-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: clamp(22px, 3vw, 34px);
}

.gem {
  width: 32px;
  aspect-ratio: 1;
  display: inline-block;
  transform: rotate(45deg);
  border: 4px solid var(--ink);
  border-radius: 7px;
  box-shadow: inset 7px 7px rgba(255, 255, 255, 0.28);
}

.gem.red {
  background: var(--red);
}

.gem.black {
  background: var(--ink-2);
}

.gem.white {
  background: var(--white);
}

.gem.light {
  background: var(--pale);
}

.gem.dark {
  background: var(--gray);
}

.progress {
  width: min(150px, 80%);
  height: 28px;
  background: #8d8f98;
  border-radius: 12px;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--red);
  transition: width 220ms ease;
}

.time-track {
  width: min(132px, 84%);
  height: 12px;
  border-radius: 999px;
  background: #b7b7bd;
  overflow: hidden;
  border: 2px solid var(--ink);
}

.time-track span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--red);
  transition: width 120ms linear;
}

.score-card strong,
.moves {
  font-size: clamp(38px, 6vw, 58px);
  line-height: 1;
}

.moves {
  color: var(--red);
}

.stars {
  display: flex;
  gap: 18px;
  color: var(--ink);
  font-size: 30px;
}

.star.on {
  color: var(--red);
}

.best-list {
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 2px;
  color: #5d6069;
  font-size: 12px;
  line-height: 1.15;
}

.score-card .best-list {
  grid-template-columns: repeat(3, auto);
  justify-content: center;
  gap: 8px;
}

.best-list li:first-child {
  color: var(--red);
}

.icon-btn {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 38px;
  aspect-ratio: 1;
  border-radius: 10px;
  border: 3px solid var(--ink);
  background: var(--white);
  color: var(--ink);
  cursor: pointer;
}

.settings-btn {
  position: absolute;
  right: 10px;
  top: 10px;
  width: 38px;
  aspect-ratio: 1;
  border-radius: 10px;
  border: 3px solid var(--ink);
  background: var(--ink);
  color: var(--white);
  cursor: pointer;
}

.game-layout {
  min-height: 0;
  width: 100%;
  display: grid;
  grid-template-columns: 82px auto 76px;
  justify-content: center;
  align-items: stretch;
  gap: 14px;
}

.side {
  border: 4px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, #0f1016, #1d202c);
  display: grid;
  align-content: start;
  justify-items: center;
  gap: 24px;
  padding: 20px 8px;
  overflow: hidden;
}

.side-box {
  width: 100%;
  min-height: 230px;
  border-radius: 16px;
  display: grid;
  justify-items: center;
  gap: 20px;
}

.side-title {
  font-size: 18px;
}

.next-preview {
  display: grid;
  gap: 8px;
}

.mini-city {
  margin-top: auto;
  width: 100%;
  height: 90px;
  display: flex;
  align-items: end;
  gap: 8px;
  opacity: 0.92;
}

.mini-city span {
  flex: 1;
  background: var(--white);
  border-radius: 10px 10px 2px 2px;
}

.mini-city span:nth-child(1) { height: 45%; }
.mini-city span:nth-child(2) { height: 75%; }
.mini-city span:nth-child(3) { height: 56%; }

.board-wrap {
  position: relative;
  min-height: 0;
  padding: 12px;
  border: 4px solid var(--white);
  border-radius: 0 0 34px 34px;
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.12));
  box-shadow: inset 0 0 0 2px rgba(20, 22, 32, 0.9);
}

.idol {
  position: relative;
  width: clamp(150px, 24vw, 184px);
  height: clamp(150px, 24vw, 184px);
  z-index: 5;
  justify-self: center;
  transform-origin: 50% 100%;
  transition: transform 280ms cubic-bezier(0.18, 0.9, 0.25, 1.35), filter 220ms ease;
}

.idol img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.idol-bounce { transform: translateY(-10px) scale(1.05); }
.idol-super { transform: translateY(-20px) scale(1.12) rotate(-4deg); filter: drop-shadow(0 0 10px rgba(238, 80, 100, 0.8)); }
.idol-mega { transform: translateY(-30px) scale(1.2) rotate(5deg); filter: drop-shadow(0 0 16px rgba(255, 255, 255, 0.9)); }

.burst-particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  pointer-events: none;
  z-index: 6;
  animation: burst 520ms ease-out forwards;
}

.burst-particle.red { background: var(--red); }
.burst-particle.black { background: var(--ink-2); }
.burst-particle.white { background: var(--white); }
.burst-particle.light { background: var(--pale); }
.burst-particle.dark { background: var(--gray); }
.burst-particle.skill { background: var(--red); }

@keyframes burst {
  to {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0.2);
  }
}

.board {
  display: grid;
  grid-template-columns: repeat(7, var(--cell));
  grid-template-rows: repeat(12, var(--cell));
  gap: 6px;
  touch-action: manipulation;
}

.tile {
  width: var(--cell);
  height: var(--cell);
  border: 0;
  border-radius: 11px;
  color: inherit;
  cursor: pointer;
  position: relative;
  box-shadow:
    inset 0 5px rgba(255, 255, 255, 0.18),
    inset 0 -4px rgba(0, 0, 0, 0.12),
    0 2px 0 rgba(0, 0, 0, 0.28);
  transition: transform 120ms ease, filter 120ms ease, opacity 180ms ease;
}

.tile::after {
  content: attr(data-mark);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(20, 22, 32, 0.22);
  font-size: calc(var(--cell) * 0.44);
}

.tile.white {
  background: var(--white);
}

.tile.red {
  background: var(--red);
}

.tile.light {
  background: var(--pale);
}

.tile.dark {
  background: var(--gray);
}

.tile.black {
  background: var(--ink-2);
}

.tile.skill {
  background: repeating-linear-gradient(135deg, var(--white) 0 10px, var(--red) 10px 20px);
  outline: 3px solid var(--ink);
  outline-offset: -5px;
}

.tile.skill::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: rgba(20, 22, 32, 0.9);
}

.tile.skill::after {
  color: var(--white);
  z-index: 1;
}

.tile.selected {
  outline: 4px solid var(--red);
  outline-offset: -4px;
  transform: translateY(-4px) scale(1.03);
  z-index: 2;
}

.tile.clearing {
  opacity: 0;
  transform: scale(0.2) rotate(12deg);
}

.combo-banner {
  position: absolute;
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%) scale(0.9);
  color: var(--red);
  background: rgba(248, 247, 243, 0.95);
  border: 4px solid var(--ink);
  border-radius: 16px;
  padding: 10px 18px;
  font-size: clamp(24px, 5vw, 48px);
  opacity: 0;
  pointer-events: none;
  z-index: 4;
  transition: opacity 180ms ease, transform 180ms ease;
}

.combo-banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.tool {
  position: relative;
  width: min(58px, 100%);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.46);
  background: #191b25;
  color: var(--white);
  font-size: 32px;
}

.tool small {
  position: absolute;
  right: -7px;
  bottom: 0;
  width: 32px;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--red);
  font-size: 18px;
}

.tool.active {
  border-color: var(--red);
  transform: translateY(-3px);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(10, 11, 17, 0.72);
  backdrop-filter: brightness(0.82);
}

.overlay.hidden {
  display: none;
}

.modal {
  width: min(88vw, 390px);
  max-height: min(92svh, 720px);
  overflow-y: auto;
  color: var(--ink);
  background: var(--white);
  border: 5px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 14px 0 rgba(0, 0, 0, 0.24);
  padding: 30px 24px 24px;
  text-align: center;
  position: relative;
}

.modal-label {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--white);
  background: var(--ink);
  border-radius: 12px;
  padding: 8px 20px;
}

.modal h1,
.modal h2 {
  margin: 10px 0 14px;
  font-size: clamp(34px, 8vw, 52px);
}

.modal p {
  margin: 10px 0;
  color: #444750;
  line-height: 1.55;
}

.mode-select {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 18px 0;
}

.skill-help {
  margin: 14px 0;
  padding: 10px 12px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: #ededee;
  text-align: left;
}

.skill-help > span {
  display: block;
  margin-bottom: 6px;
  color: var(--red);
  text-align: center;
}

.skill-help ol {
  margin: 0;
  padding-left: 24px;
  color: #444750;
  line-height: 1.45;
}

.mode-button {
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--white);
  color: var(--ink);
  padding: 10px 8px;
  cursor: pointer;
}

.mode-button.active {
  background: var(--ink);
  color: var(--white);
}

.best-box {
  margin: 14px auto 18px;
  padding: 10px 12px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: #ededee;
}

.best-box > span {
  display: block;
  margin-bottom: 5px;
  color: var(--red);
}

.best-box .best-list {
  font-size: 16px;
  color: var(--ink);
}

.title-character {
  position: relative;
  width: min(44vw, 210px);
  height: min(44vw, 210px);
  margin: 8px auto 0;
}

.title-character img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.settings-modal {
  text-align: left;
}

.settings-modal h2 {
  text-align: center;
}

.volume-row {
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: 14px;
  margin: 16px 0;
  color: var(--ink);
}

.volume-row input {
  width: 100%;
  accent-color: var(--red);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

.modal strong {
  display: block;
  margin: 8px 0 20px;
  color: var(--red);
  font-size: clamp(48px, 12vw, 76px);
  line-height: 1;
}

.modal-button {
  border: 4px solid var(--ink);
  border-radius: 14px;
  background: var(--red);
  color: var(--white);
  padding: 12px 28px;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--red-dark);
}

.modal-button.secondary {
  background: var(--ink);
  box-shadow: 0 5px 0 #07080d;
}

.score-drop {
  animation: scoreDrop 680ms cubic-bezier(0.16, 0.9, 0.25, 1.18) both;
}

@keyframes scoreDrop {
  0% {
    opacity: 0;
    transform: translateY(-90vh) scale(0.92);
  }
  70% {
    opacity: 1;
    transform: translateY(24px) scale(1.02);
  }
  86% {
    transform: translateY(-10px) scale(0.99);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.bottom-bar {
  min-height: 150px;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 18px;
  border-top: 4px solid var(--red);
  background: rgba(12, 13, 19, 0.92);
  padding: 10px 16px;
  border-radius: 0 0 18px 18px;
}

.pause {
  width: 70px;
  aspect-ratio: 1;
  border: 4px solid var(--ink);
  border-radius: 18px;
  background: var(--red);
  color: var(--white);
  font-size: 34px;
  cursor: pointer;
}

.sound {
  width: 46px;
  aspect-ratio: 1;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--white);
  color: var(--ink);
  cursor: pointer;
}

.sound.off {
  opacity: 0.45;
}


#status {
  margin: 0;
  min-width: 170px;
  color: var(--pale);
  text-align: right;
}

.paused .board,
.paused .side {
  filter: grayscale(1) brightness(0.7);
}

@media (max-width: 760px) {
  :root {
    --cell: min(10.4vw, 42px);
  }

  .shell {
    padding: max(6px, env(safe-area-inset-top)) 6px max(6px, env(safe-area-inset-bottom));
    gap: 6px;
  }

  .top-panel {
    min-height: 92px;
    border-radius: 20px;
  }

  .stat {
    padding: 24px 6px 8px;
  }

  .label {
    padding: 6px 10px;
    border-radius: 9px;
  }

  .mission-row {
    gap: 5px;
  }

  .gem {
    width: 24px;
    border-width: 3px;
  }

  .stars {
    gap: 8px;
    font-size: 22px;
  }

  .game-layout {
    grid-template-columns: minmax(46px, 58px) minmax(0, max-content) minmax(46px, 58px);
    gap: 6px;
  }

  .bottom-bar {
    min-height: 116px;
    gap: 8px;
    padding: 6px 8px;
  }

  .idol {
    width: min(28vw, 128px);
    height: min(28vw, 128px);
  }

  .pause {
    width: 54px;
  }

  .sound {
    width: 40px;
  }

  #status {
    min-width: 88px;
    font-size: 12px;
  }

  .score-card .best-list {
    display: none;
  }

  .side {
    display: grid;
    border-width: 3px;
    border-radius: 16px;
    gap: 12px;
    padding: 12px 4px;
  }

  .side-box {
    min-height: 136px;
    gap: 10px;
  }

  .side-title {
    font-size: 13px;
  }

  .next-preview {
    gap: 5px;
  }

  .tool {
    width: 42px;
    border-width: 3px;
    font-size: 24px;
  }

  .tool small {
    right: -3px;
    width: 22px;
    font-size: 12px;
  }

  .board-wrap {
    justify-self: center;
  }

  .board {
    gap: 5px;
  }

  .side-left .side-box {
    min-height: 136px;
  }

  .modal {
    width: min(92vw, 390px);
    max-height: 94svh;
    padding: 22px 18px 18px;
  }

  .modal h1,
  .modal h2 {
    margin: 4px 0 8px;
    font-size: clamp(32px, 10vw, 48px);
  }

  .modal p {
    margin: 6px 0;
    line-height: 1.35;
    font-size: 13px;
  }

  .skill-help {
    margin: 8px 0;
    padding: 8px 10px;
  }

  .skill-help ol {
    line-height: 1.32;
    font-size: 13px;
  }

  .title-character {
    width: min(34vw, 150px);
    height: min(34vw, 150px);
    margin-top: 2px;
  }

  .mode-select {
    margin: 8px 0;
  }

  .best-box {
    margin: 8px auto 10px;
  }

  .modal-button {
    padding: 10px 22px;
  }
}
