:root {
  --ink: #293748;
  --paper: #fffdf2;
  --blue: #389be6;
  --coral: #ff6855;
  --yellow: #ffdc65;
}
.online-button {
  background: #76c9f5;
  margin-bottom: 14px;
}
.gesture-guide {
  font-size: 12px;
  line-height: 1.7;
  text-align: center;
  margin: 18px 0 8px;
}
#waiting {
  padding: 35px 8px;
  text-align: center;
}
#waiting p {
  line-height: 1.7;
  margin: 18px 0;
}
#waiting button {
  padding: 8px 22px;
}
#board {
  touch-action: none;
  cursor: grab;
}
#board:active {
  cursor: grabbing;
}
#connection {
  position: absolute;
  top: 50px;
  left: 20px;
  right: 20px;
  z-index: 10;
  background: #fff0be;
  color: #293748;
  text-align: center;
  font-size: 12px;
  padding: 5px;
  border-radius: 8px;
  pointer-events: none;
}
.controls button[data-action="cw"],
.controls button[data-action="ccw"] {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex-direction: column;
}
.controls svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.controls small {
  font-size: 9px;
  line-height: 1;
  white-space: nowrap;
}

/* Punipuni keeps the shared layout but changes the hard-stone language to a soft,
   candy-like visual system. */
:root { --ink:#30425d; --paper:#fffdf6; --blue:#77d8f1; --coral:#ff86b2; --yellow:#ffe57a; }
body { background: radial-gradient(circle at 12% 8%, #fff9d7 0 12%, transparent 34%), linear-gradient(135deg,#bff4ff,#ffd9eb 52%,#d6f6bd); }
.main-card { background: linear-gradient(180deg,#fffef9,#fff4fb); border-radius:40px; }
.brand h1 { color:#30425d; text-shadow:0 3px 0 #ffb6d0; }
.cover { border-radius:32px; background:linear-gradient(145deg,#c9f7ff,#ffe4f1); }
.features span { border-radius:999px; background:#fff2a9; }
.primary { background:linear-gradient(180deg,#ff9bc0,#ff78a9); }
.online-button { background:linear-gradient(180deg,#8ce6c1,#62d4a7); }
.connect-preview { display:flex; align-items:center; justify-content:center; gap:0; min-height:58px; margin:10px 0 4px; position:relative; }
.connect-preview .blob { width:34px; height:34px; border:3px solid var(--ink); border-radius:50%; margin-left:-7px; box-shadow:inset 5px 5px 0 #ffffff99; }
.connect-preview .blob:first-child { margin-left:0; }
.connect-preview .pink { background:#ff9fc2; }
.connect-preview .mint { background:#aeea80; }
.connect-preview .blue { background:#7ddcf5; }
.connect-preview b { font-size:10px; margin-left:8px; color:#30425d; }
.connect-preview b:last-child { color:#e45c91; margin-left:14px; }
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  color: var(--ink);
  font-family: "Outfit", "Zen Maru Gothic", "Noto Sans KR", sans-serif;
  background:
    radial-gradient(ellipse at 10% 10%, #effcff 0, transparent 45%),
    repeating-linear-gradient(135deg, #a0dfed 0 70px, #a9e4ef 70px 140px);
  min-height: 100vh;
}
button,
select,
a {
  -webkit-tap-highlight-color: transparent;
}
button,
select {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  border: 3px solid var(--ink);
  border-radius: 15px;
  background: white;
  font-weight: 900;
  min-height: 44px;
  box-shadow: 0 4px 0 var(--ink);
  touch-action: manipulation;
}
button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}
button:focus-visible,
a:focus-visible,
select:focus-visible {
  outline: 3px solid #e25719;
  outline-offset: 3px;
}
main {
  max-width: 620px;
  margin: 0 auto;
  padding: 18px 14px 30px;
}
#surrender { display:none; }
body.playing #surrender { display:block; background:#ffe1de; }
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 17px;
}
header a {
  font-size: 12px;
  font-weight: 900;
  color: inherit;
  text-decoration: none;
}
header div {
  display: flex;
  gap: 6px;
}
header button {
  font-size: 10px;
  padding: 4px 9px;
  min-height: 36px;
}
#sound {
  min-width: 92px;
  background: #e7ebef;
  transition: background-color 0.18s ease, color 0.18s ease;
}
#sound.is-on {
  background: #fff09b;
  color: #24384c;
}
select {
  border: 2px solid var(--ink);
  border-radius: 9px;
  background: white;
  max-width: 87px;
  font-size: 11px;
}
.main-card {
  padding: 24px;
  border: 4px solid var(--ink);
  border-radius: 34px;
  background: var(--paper);
  box-shadow: 0 10px 0 var(--ink);
}
.brand {
  text-align: center;
  margin: 0 0 18px;
}
.brand > span {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 2px;
}
.brand h1 {
  font-size: clamp(32px, 8vw, 50px);
  margin: 3px 0;
  text-shadow: 0 3px 0 #ffdc65;
  letter-spacing: -2px;
}
.brand p {
  font-size: 13px;
  margin: 4px 0;
}
.cover {
  aspect-ratio: 1;
  position: relative;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 24px;
  background: radial-gradient(circle at 50% 55%, #fff7c0, #ffb944 75%);
  isolation: isolate;
}
.cover-art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.level-picker {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  font-weight: 900;
}
.level-picker select {
  max-width: none;
  min-height: 44px;
  padding: 8px 16px;
  font-size: 16px;
  background: #fff2b4;
}
body.playing {
  overflow: hidden;
  overscroll-behavior: none;
}
body.playing main {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  max-width: 620px;
  padding: max(5px, env(safe-area-inset-top)) 8px
    max(5px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
  --bh: min(
    calc(
      100dvh - 280px - env(safe-area-inset-top) - env(safe-area-inset-bottom)
    ),
    calc((100vw - 75px) * 1.22),
    580px
  );
}
body.playing .ranking-section,
body.playing #hubAccountCardGame,
body.playing #resultModal {
  display: none !important;
}
body.playing header {
  margin: 0;
  flex-shrink: 0;
}
body.playing .main-card {
  padding: 10px;
  border-radius: 22px;
  flex: 1;
  min-height: 0;
  box-shadow: 0 4px 0 var(--ink);
}
body.playing .brand {
  display: none;
}
body.playing details,
body.playing footer,
body.playing #battle > .note {
  display: none;
}
body.playing .matchbar {
  margin-bottom: 8px;
  padding: 7px 10px;
}
body.playing .matchbar [data-cpu-name] {
  font-size: 11px;
}
body.playing .arena {
  height: calc(var(--bh) + 22px);
  grid-template-columns: calc(var(--bh) / 2) calc(var(--bh) * 0.29);
  justify-content: center;
  gap: 10px;
}
body.playing .player-panel > canvas {
  height: var(--bh);
  width: 100%;
}
body.playing .arena aside {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
body.playing .next {
  height: 55px;
  flex-shrink: 0;
  margin: 0;
  justify-content: center;
}
body.playing .next canvas {
  width: 38px;
  height: 46px;
}
body.playing .enemy-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
body.playing .enemy-panel .board-label {
  width: 100%;
  flex-shrink: 0;
}
body.playing .enemy-panel canvas {
  height: calc(100% - 22px);
  width: auto;
  max-width: 100%;
  object-fit: contain;
}
body.playing .enemy-status {
  font-size: 9px;
  line-height: 1.2;
  min-height: 0;
  margin: 0;
}
body.playing .controls {
  margin-top: 10px;
  gap: 12px 7px;
}
body.playing .controls button {
  min-height: 52px;
  height: auto;
  font-size: 24px;
}
body.playing .controls .drop {
  font-size: 14px;
}
@media (orientation: landscape) and (max-height: 600px) {
  body.playing main {
    max-width: 900px;
    --bh: calc(
      100dvh - 150px - env(safe-area-inset-top) - env(safe-area-inset-bottom)
    );
  }
  body.playing #battle {
    display: grid;
    grid-template-columns: 1fr 180px;
    column-gap: 14px;
  }
  body.playing .matchbar {
    grid-column: 1/-1;
  }
  body.playing .controls {
    align-content: center;
    margin: 0;
    grid-template-columns: 1fr 1.5fr 1fr;
  }
  body.playing .next {
    height: 38px;
  }
  body.playing .next canvas {
    height: 30px;
    width: 25px;
  }
}
.burst {
  position: absolute;
  inset: -60%;
  background: repeating-conic-gradient(
    from 0deg,
    #fff6 0 12deg,
    transparent 12deg 30deg
  );
  transform: rotate(12deg);
}
.cover > strong {
  position: absolute;
  left: 6%;
  top: 8%;
  z-index: 2;
  font-size: clamp(38px, 10vw, 68px);
  font-weight: 900;
  line-height: 0.9;
  transform: rotate(-8deg);
  color: white;
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  text-shadow: 3px 5px var(--ink);
}
.cover em {
  font-style: normal;
  color: #ff684c;
  font-size: 0.7em;
}
.hero-rock {
  position: absolute;
  width: 38%;
  height: 37%;
  border: 5px solid var(--ink);
  border-radius: 24% 35% 22% 30%;
  box-shadow:
    inset 8px 9px #fff8,
    inset -10px -13px #0002,
    5px 10px #29374833;
  transform: rotate(-14deg);
  background: var(--coral);
  bottom: 13%;
  left: 7%;
}
.hero-rock.blue {
  background: #46b9f7;
  left: 51%;
  bottom: 20%;
  transform: rotate(18deg);
}
.hero-rock.gold {
  background: #c59beb;
  width: 23%;
  height: 22%;
  left: 48%;
  bottom: 3%;
  transform: rotate(4deg);
}
.hero-rock i:before,
.hero-rock i:after {
  content: "";
  position: absolute;
  top: 40%;
  width: 13%;
  height: 17%;
  border-radius: 4px;
  background: var(--ink);
  border-top: 5px solid white;
}
.hero-rock i:before {
  left: 24%;
  transform: rotate(-16deg);
}
.hero-rock i:after {
  right: 24%;
  transform: rotate(16deg);
}
.hero-rock b {
  position: absolute;
  left: 37%;
  top: 69%;
  width: 27%;
  border-top: 4px solid var(--ink);
  transform: rotate(-8deg);
}
.sticker {
  position: absolute;
  right: 4%;
  top: 7%;
  border: 3px solid var(--ink);
  border-radius: 50%;
  padding: 15px 7px;
  background: #fff8d5;
  font-size: 12px;
  font-weight: 900;
  text-align: center;
  transform: rotate(12deg);
}
.features {
  display: flex;
  justify-content: space-between;
  gap: 5px;
  margin: 19px 0;
  font-size: 12px;
  font-weight: 900;
}
.primary {
  width: 100%;
  background: var(--coral);
  font-size: 23px;
  padding: 13px;
}
.note {
  text-align: center;
  font-size: 11px;
  line-height: 1.6;
  color: #626b75;
  margin: 14px 0;
}
details {
  border-top: 2px dashed #ced0c9;
  margin-top: 20px;
  padding-top: 16px;
  font-size: 13px;
}
summary {
  font-weight: 900;
  cursor: pointer;
}
details p {
  line-height: 1.9;
}
footer {
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  margin-top: 28px;
  letter-spacing: 2px;
}
[hidden] {
  display: none !important;
}
.matchbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--ink);
  color: white;
  border-radius: 14px;
  padding: 10px 13px;
  margin-bottom: 12px;
  font-size: 11px;
}
.matchbar b {
  display: flex;
  gap: 8px;
  align-items: center;
}
.matchbar b span {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}
.versus {
  color: var(--yellow);
  font-size: 18px;
  font-weight: 900;
}
.arena {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.58fr);
  gap: 12px;
  position: relative;
}
.player-panel,
.enemy-panel {
  position: relative;
  min-width: 0;
}
.board-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  margin-bottom: 6px;
}
.board-label span {
  min-width: 28px;
  border-radius: 20px;
  background: #e4e9ed;
  text-align: center;
  padding: 2px 5px;
  font-weight: 900;
}
.board-label span.danger {
  background: var(--coral);
  color: white;
}
canvas {
  display: block;
  width: 100%;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: #273b52;
  aspect-ratio: 1/2;
}
.next {
  display: flex;
  align-items: center;
  gap: 3px;
  background: #e7f1ee;
  border: 2px solid var(--ink);
  border-radius: 12px;
  margin-bottom: 10px;
  padding: 5px;
}
.next small {
  font-size: 10px;
  font-weight: 900;
  writing-mode: vertical-rl;
}
.next canvas {
  border: 0;
  background: transparent;
  width: min(calc(100% - 20px), 80px);
  aspect-ratio: 5/6;
  height: auto;
  max-height: none;
}
.enemy-status {
  font-size: 10px;
  text-align: center;
  min-height: 27px;
  margin: 8px 0;
}
aside > button {
  width: 100%;
  font-size: 11px;
}
.controls {
  display: grid;
  grid-template-columns: 1fr 1.5fr 1fr;
  grid-template-areas: "left rotate right" "left drop right";
  grid-template-rows: repeat(2, minmax(52px, auto));
  gap: 8px;
  margin-top: 14px;
  user-select: none;
  touch-action: none;
}
.controls button {
  font-size: 27px;
  background: #e2f3ff;
  min-height: 50px;
  touch-action: none;
}
.controls button[data-action="left"] { grid-area: left; }
.controls button[data-action="right"] { grid-area: right; }
.controls button[data-action="cw"] {
  grid-area: rotate;
  background: var(--yellow);
}
.controls .drop {
  grid-area: drop;
  font-size: 16px;
  min-height: 44px;
  background: #a8dfaa;
}
.controls button[data-action="cw"] small,
.controls .hard {
  font-weight: 900;
}
.controls button[data-action="cw"] svg { stroke-width: 3.5; }
.cpu-choice {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin: 14px 0;
  align-items: stretch;
}
.cpu-choice .level-picker {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  margin: 0;
  padding: 8px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: #fff0ba;
  font-size: 12px;
}
.cpu-choice .level-picker select { width: 100%; min-width: 0; }
.cpu-choice #start {
  margin: 0;
  width: 100%;
  background: #ffcfad;
  font-size: clamp(14px, 4vw, 20px);
}
.overlay {
  position: absolute;
  inset: 0;
  background: #21364bdd;
  border: 3px solid var(--ink);
  border-radius: 14px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px;
  gap: 14px;
  text-align: center;
  color: white;
}
.overlay > strong {
  font-size: clamp(35px, 8vw, 58px);
  font-weight: 900;
  color: var(--yellow);
  text-shadow: 0 5px #172637;
}
.overlay > strong.countdown-pop {
  animation: countdown-pop 420ms cubic-bezier(0.18, 0.82, 0.24, 1.2) both;
}
@keyframes countdown-pop {
  0% { transform: scale(0.52) rotate(-9deg); opacity: 0.2; }
  68% { transform: scale(1.22) rotate(3deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
.overlay p {
  margin: 0;
  font-size: 13px;
}
.result-ranking {
  display: none;
  width: min(100%, 440px);
  grid-template-columns: minmax(0, 1fr);
  gap: 9px;
  margin: 16px auto 0;
  padding: 16px;
  border: 3px solid var(--ink);
  border-radius: 20px;
  background: #fffef9;
  color: var(--ink);
  box-shadow: 0 5px 0 #30425d;
}
.result-ranking.active { display: grid; }
.result-ranking > strong {
  color: #30425d;
  font-size: 20px;
  font-weight: 900;
  text-align: center;
}
.result-ranking label { font-size: 12px; font-weight: 900; }
.result-ranking input {
  width: 100%;
  min-height: 42px;
  padding: 7px 10px;
  border: 2px solid #aab8ca;
  border-radius: 10px;
  background: #fff;
  color: #253449;
  font: inherit;
}
.result-ranking button { min-height: 46px; padding: 7px 12px; }
.result-ranking #resRank { min-height: 1em; color: #426341; font-size: 12px; font-weight: 900; }
.overlay button {
  padding: 7px 25px;
  color: var(--ink);
  background: var(--yellow);
}
.overlay a {
  color: white;
  font-size: 13px;
}
.chain-pop {
  position: absolute;
  top: 35%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: clamp(20px, 5vw, 34px);
  font-weight: 900;
  color: #ffeb7d;
  text-shadow: 2px 3px var(--ink);
  pointer-events: none;
}
.ranking-section {
  align-self: center;
  margin-top: 28px;
  color: #293748 !important;
  width: min(100%, 440px);
}
.ranking-section .ranking-card {
  background: #fffef9 !important;
  border: 4px solid #30425d !important;
  border-radius: 28px;
  padding: 24px 20px;
  color: #293748 !important;
  box-shadow: 0 8px 0 #30425d !important;
}
.ranking-section .ranking-card h3 { color: #293748 !important; }
.ranking-section .ranking-card h4 {
  color: #60430a !important;
  background: #fff0b9 !important;
}
.ranking-section .ranking-list { padding: 0; color: #293748 !important; }
.ranking-section .ranking-item {
  color: #293748 !important;
  border-bottom-color: #d9e0e7 !important;
}
.ranking-section .rank-num { color: #e95468 !important; }
.ranking-section .rank-name { color: #293748 !important; }
.ranking-section .rank-score { color: #315575 !important; }
.ranking-section .ranking-empty {
  padding: 18px 8px;
  color: #53677c !important;
  font-size: 14px;
  font-weight: 800;
  list-style: none;
}
.chain-pop.pop {
  animation: pop 0.65s both;
}
.enemy-panel .chain-pop {
  font-size: 18px;
}
@keyframes pop {
  0% {
    transform: scale(0.4);
    opacity: 0;
  }
  25% {
    transform: scale(1.3);
    opacity: 1;
  }
  70% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: translateY(-25px);
    opacity: 0;
  }
}
body.playing .brand {
  margin-bottom: 12px;
}
body.playing .brand > span,
body.playing .brand p {
  display: none;
}
body.playing .brand h1 {
  font-size: 27px;
}
@media (max-width: 400px) {
  main {
    padding: 12px 9px 24px;
  }
  .main-card {
    padding: 15px;
    border-radius: 26px;
  }
  .arena {
    gap: 9px;
  }
  .features {
    font-size: 10px;
  }
  .matchbar {
    padding: 8px;
  }
  .matchbar b span {
    font-size: 17px;
  }
  .controls {
    gap: 7px;
  }
  .next canvas {
    width: min(calc(100% - 20px), 62px);
  }
}
@media (prefers-reduced-motion: reduce) {
  .overlay > strong.countdown-pop {
    animation: none;
  }
  .chain-pop.pop {
    animation: none;
    opacity: 1;
  }
}
