* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #10131a;
  color: #f2f5f8;
}

#app {
  max-width: 980px;
  margin: 0 auto;
  padding: 8px;
}

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

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0.04em;
}

.subtitle {
  margin: 2px 0 0;
  color: #aab3c2;
  font-size: 11px;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
  background: #2d65ff;
  color: white;
  font-weight: 700;
  cursor: pointer;
  font-size: 12px;
}

button:disabled {
  background: #3b4250;
  cursor: default;
}

button.is-paused {
  background: #35b96f;
  color: #061017;
  box-shadow: 0 0 0 3px rgba(66, 211, 146, 0.20), 0 0 14px rgba(66, 211, 146, 0.35);
}

body.game-paused .battle-panel,
body.game-paused .board-panel {
  outline: 2px solid rgba(66, 211, 146, 0.55);
}

.top-actions {
  display: flex;
  gap: 6px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) 320px;
  gap: 10px;
  align-items: start;
}

.battle-panel,
.board-panel {
  background: #171d28;
  border: 1px solid #273044;
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
}

.status-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}

.status-row > div,
.stats-grid > div {
  background: #0f1420;
  border: 1px solid #273044;
  border-radius: 8px;
  padding: 6px;
  text-align: center;
  font-weight: 700;
  font-size: 12px;
}

.battle-stage {
  min-height: 156px;
  display: grid;
  grid-template-columns: 1fr 42px 1fr;
  align-items: center;
  gap: 8px;
  background: radial-gradient(circle at center, #24314b 0%, #111827 70%);
  border-radius: 12px;
  padding: 10px;
  overflow: hidden;
}

.sprite {
  position: relative;
  min-height: 106px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 2px solid #41506b;
  background: rgba(255, 255, 255, 0.04);
}

.hero-sprite {
  border-color: #42d392;
}

.boss-sprite {
  border-color: #ff5c5c;
}

.sprite-name {
  font-size: 11px;
  color: #cad2df;
}

.sprite-face {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 900;
  background: #263044;
}

.versus {
  text-align: center;
  font-weight: 900;
  color: #ffdc5c;
  font-size: 13px;
}

.hp-area {
  margin-top: 8px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  color: #cad2df;
  font-size: 11px;
  margin: 5px 0 3px;
}

.bar {
  height: 11px;
  border-radius: 999px;
  background: #0c1018;
  border: 1px solid #273044;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 100%;
  transition: width 0.2s ease;
}

.hero-fill {
  background: linear-gradient(90deg, #42d392, #7ef0b4);
}

.boss-fill {
  background: linear-gradient(90deg, #ff5c5c, #ff9f70);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.log {
  min-height: 34px;
  margin-top: 8px;
  padding: 8px;
  border-radius: 10px;
  background: #0f1420;
  color: #dbe3f1;
  border: 1px solid #273044;
  font-size: 12px;
  line-height: 1.35;
}

.board-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-weight: 800;
  font-size: 12px;
}

.next-piece {
  display: flex;
  gap: 3px;
  min-width: 56px;
  justify-content: center;
}

.board {
  width: min(100%, 270px);
  aspect-ratio: 6 / 12;
  margin: 0 auto;
  display: grid;
  gap: 3px;
  background: #0c1018;
  border: 5px solid #283246;
  border-radius: 12px;
  padding: 4px;
}

.cell {
  border-radius: 6px;
  background: #151b27;
  border: 1px solid #252d3e;
  display: grid;
  place-items: center;
  font-size: 9px;
  font-weight: 900;
  color: #061017;
}

.next-piece .cell {
  width: 22px;
  height: 22px;
}

.cell.filled {
  background: var(--cell-color);
  box-shadow: inset 0 -3px rgba(0, 0, 0, 0.18), 0 0 7px rgba(255, 255, 255, 0.10);
}

.cell.active {
  outline: 2px solid #ffffff;
  outline-offset: -1px;
}

.controls-help {
  margin-top: 8px;
  color: #aab3c2;
  font-size: 11px;
  line-height: 1.35;
  text-align: center;
}

.touch-controls {
  display: none;
}

.shake {
  animation: shake 0.18s linear;
}

.attack-motion {
  animation: attackMove 0.18s ease;
}

.attack-motion-reverse {
  animation: attackMoveReverse 0.18s ease;
}

.defeat-flash {
  animation: defeatFlash 0.32s ease;
}

@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
  100% { transform: translateX(0); }
}

@keyframes attackMove {
  0% { transform: translateX(0); }
  50% { transform: translateX(10px); }
  100% { transform: translateX(0); }
}

@keyframes attackMoveReverse {
  0% { transform: translateX(0); }
  50% { transform: translateX(-10px); }
  100% { transform: translateX(0); }
}

@keyframes defeatFlash {
  0% { filter: brightness(1); transform: scale(1); }
  45% { filter: brightness(2.2); transform: scale(1.05); }
  100% { filter: brightness(1); transform: scale(1); }
}

@media (max-width: 820px) {
  #app {
    padding: 8px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .battle-panel {
    order: 1;
  }

  .board-panel {
    order: 2;
  }

  .battle-stage {
    min-height: 138px;
    grid-template-columns: 1fr 34px 1fr;
    padding: 8px;
  }

  .sprite {
    min-height: 92px;
  }

  .sprite-face {
    width: 54px;
    height: 54px;
    font-size: 18px;
  }

  .board {
    width: min(82vw, 285px);
  }

  .status-row,
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .touch-controls {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    margin-top: 8px;
  }

  .touch-controls button {
    padding: 9px 4px;
  }
}

.cell {
  position: relative;
  overflow: hidden;
}

.cell.has-image {
  background: var(--cell-color);
}

.cell-art {
  position: absolute;
  inset: 3px;
  z-index: 3;
  display: block;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  pointer-events: none;
}

.next-cell {
  position: relative;
  overflow: hidden;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--cell-color, #151b27);
  border: 1px solid #252d3e;
  display: grid;
  place-items: center;
  box-shadow: inset 0 -3px rgba(0, 0, 0, 0.18), 0 0 7px rgba(255, 255, 255, 0.10);
}

.next-cell-art {
  position: absolute;
  inset: 2px;
  z-index: 2;
  display: block;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  pointer-events: none;
}

.next-cell-label {
  position: relative;
  z-index: 3;
  font-size: 8px;
  font-weight: 900;
  color: #061017;
}

.next-cell.has-image .next-cell-label {
  display: none;
}


.cell-label {
  position: relative;
  z-index: 4;
}

.cell.has-image .cell-label {
  display: none;
}

.sprite-image {
  width: 74px;
  height: 74px;
  object-fit: contain;
  image-rendering: auto;
  pointer-events: none;
}


.boss-sprite[data-power-tier]:not([data-power-tier="0"]) {
  border-color: #ffdc5c;
  filter: saturate(1.15) brightness(1.05);
}

.boss-sprite[data-power-tier]:not([data-power-tier="0"])::after {
  content: attr(data-power-label);
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(255, 220, 92, 0.92);
  color: #111827;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.03em;
}

.boss-sprite[data-power-tier]:not([data-power-tier="0"]) .sprite-image {
  transform: scale(1.08);
}

.boss-sprite[data-power-tier="1"] {
  box-shadow: 0 0 18px rgba(255, 92, 92, 0.45);
}

.boss-sprite[data-power-tier="2"] {
  box-shadow: 0 0 22px rgba(168, 123, 255, 0.55);
}

.boss-sprite[data-power-tier="3"] {
  box-shadow: 0 0 26px rgba(255, 220, 92, 0.60);
}

@media (max-width: 820px) {
  .sprite-image {
    width: 64px;
    height: 64px;
  }
}

@media (max-width: 820px) {
  .boss-sprite[data-power-tier]:not([data-power-tier="0"])::after {
    content: attr(data-power-short-label);
    top: 4px;
    right: 4px;
    padding: 1px 6px;
    font-size: 8px;
    line-height: 1.35;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
  }

  .boss-sprite[data-power-tier]:not([data-power-tier="0"]) .sprite-name {
    padding-right: 24px;
  }
}

.cell.clearing {
  animation: clearPop 0.18s ease-out forwards;
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.9), inset 0 -3px rgba(0, 0, 0, 0.18);
  z-index: 2;
}

.cell.clearing .cell-art {
  animation: clearImagePop 0.18s ease-out forwards;
}

@keyframes clearPop {
  0% {
    transform: scale(1);
    opacity: 1;
    filter: brightness(1);
  }
  55% {
    transform: scale(1.18);
    opacity: 1;
    filter: brightness(1.8);
  }
  100% {
    transform: scale(0.72);
    opacity: 0;
    filter: brightness(2.1);
  }
}

@keyframes clearImagePop {
  0% { transform: scale(1); opacity: 1; }
  60% { transform: scale(1.14); opacity: 1; }
  100% { transform: scale(0.65); opacity: 0; }
}

.audio-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid #273044;
  border-radius: 10px;
  background: #0f1420;
  color: #cad2df;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.audio-controls label {
  display: flex;
  align-items: center;
  gap: 5px;
}

.audio-controls input[type="range"] {
  width: 74px;
  accent-color: #2d65ff;
}

.audio-controls input[type="checkbox"] {
  accent-color: #2d65ff;
}

@media (max-width: 820px) {
  .audio-controls {
    justify-content: center;
    flex-wrap: wrap;
  }
}

.stat-item {
  display: grid !important;
  grid-template-columns: 22px auto 1fr;
  align-items: center;
  gap: 5px;
  text-align: left !important;
}

.stat-icon {
  width: 22px;
  height: 22px;
  object-fit: contain;
  border-radius: 5px;
  background: rgba(255,255,255,0.08);
}

.stat-icon.is-missing {
  display: none;
}

.stat-label {
  color: #aab3c2;
  font-size: 10px;
  font-weight: 900;
}

.hp-bar-hit {
  animation: hpBarHit 0.22s ease;
}

@keyframes hpBarHit {
  0% { transform: translateX(0); filter: brightness(1); }
  25% { transform: translateX(-5px); filter: brightness(1.6); }
  50% { transform: translateX(5px); filter: brightness(1.8); }
  75% { transform: translateX(-2px); filter: brightness(1.3); }
  100% { transform: translateX(0); filter: brightness(1); }
}

.result-modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.result-modal.is-open {
  opacity: 1;
  pointer-events: auto;
}

.result-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 13, 0.72);
  backdrop-filter: blur(3px);
}

.result-card {
  position: relative;
  width: min(440px, 100%);
  max-height: calc(100vh - 28px);
  overflow: auto;
  border-radius: 18px;
  border: 1px solid #344158;
  background: linear-gradient(180deg, #1b2333, #111827);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
  padding: 16px;
  transform: scale(0.98) translateY(6px);
  transition: transform 0.22s ease;
}

.result-modal.is-open .result-card {
  transform: scale(1) translateY(0);
}

.result-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.result-reason {
  color: #ffdc5c;
  font-weight: 900;
  letter-spacing: 0.08em;
  font-size: 12px;
}

.result-card h2 {
  margin: 2px 0 0;
  font-size: 21px;
}

.result-close {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  padding: 0;
  background: #273044;
  font-size: 20px;
  line-height: 1;
}


.result-score {
  margin-top: 12px;
  border: 1px solid #344158;
  border-radius: 14px;
  background: #0f1420;
  padding: 12px;
  text-align: center;
}

.result-score span {
  display: block;
  color: #aab3c2;
  font-size: 11px;
  font-weight: 900;
}

.result-score strong {
  display: block;
  margin-top: 2px;
  color: #fff;
  font-size: 34px;
  line-height: 1;
  letter-spacing: 0.03em;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.result-grid div {
  background: #0f1420;
  border: 1px solid #273044;
  border-radius: 10px;
  padding: 8px 6px;
  text-align: center;
}

.result-grid span {
  display: block;
  color: #aab3c2;
  font-size: 9px;
  font-weight: 900;
}

.result-grid strong {
  display: block;
  margin-top: 2px;
  font-size: 15px;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.secondary-result-button {
  background: #273044;
  color: #f2f5f8;
}


@media (max-width: 820px) {
  body {
    overflow-x: hidden;
  }

  #app {
    min-height: 100svh;
    padding: 5px;
  }

  .topbar {
    gap: 5px;
    margin-bottom: 5px;
  }

  h1 {
    font-size: 17px;
  }

  .subtitle,
  .controls-help,
  .log {
    display: none;
  }

  .top-actions button {
    padding: 7px 8px;
    font-size: 11px;
  }

  .audio-controls {
    padding: 5px 6px;
    gap: 6px;
    font-size: 10px;
  }

  .audio-controls input[type="range"] {
    width: 58px;
  }

  .game-layout {
    gap: 5px;
  }

  .battle-panel,
  .board-panel {
    padding: 6px;
    border-radius: 12px;
  }

  .battle-panel {
    order: 1;
  }

  .board-panel {
    order: 2;
  }

  .status-row {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    margin-bottom: 5px;
  }

  .status-row > div {
    padding: 4px 3px;
    font-size: 10px;
  }

  .battle-stage {
    min-height: 86px;
    grid-template-columns: 1fr 26px 1fr;
    gap: 4px;
    padding: 5px;
  }

  .sprite {
    min-height: 72px;
    gap: 2px;
    border-radius: 9px;
  }

  .sprite-name {
    font-size: 9px;
  }

  .sprite-face {
    width: 42px;
    height: 42px;
    font-size: 14px;
  }

  .sprite-image {
    width: 50px;
    height: 50px;
  }

  .versus {
    font-size: 10px;
  }

  .hp-area {
    margin-top: 5px;
  }

  .bar-label {
    font-size: 9px;
    margin: 3px 0 2px;
  }

  .bar {
    height: 9px;
  }

  .stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 3px;
    margin-top: 5px;
  }

  .stats-grid > div {
    padding: 4px 3px;
    font-size: 10px;
  }

  .stat-item {
    grid-template-columns: 18px 1fr;
    gap: 2px;
    text-align: center !important;
  }

  .stat-icon {
    width: 18px;
    height: 18px;
    grid-row: span 2;
  }

  .stat-label {
    font-size: 8px;
  }

  .board-header {
    margin-bottom: 4px;
    font-size: 10px;
  }

  .next-piece .next-cell {
    width: 18px;
    height: 18px;
  }

  .board {
    width: min(76vw, 310px, calc(100svh - 315px));
    min-width: 220px;
    gap: 2px;
    border-width: 4px;
    border-radius: 10px;
    padding: 3px;
  }

  .cell {
    border-radius: 5px;
    font-size: 8px;
  }

  .touch-controls {
    display: grid;
    grid-template-columns: 1fr 1.25fr 1fr 1fr;
    gap: 8px;
    width: min(100%, 360px);
    margin: 7px auto 0;
  }

  .touch-controls button {
    min-height: 56px;
    border-radius: 14px;
    padding: 0;
    font-size: 18px;
    touch-action: manipulation;
    user-select: none;
  }

  .touch-drop {
    background: #ff8a3d;
    color: #10131a;
    font-size: 13px !important;
    letter-spacing: 0.04em;
  }

  .result-card {
    width: min(390px, 100%);
    padding: 12px;
    border-radius: 15px;
  }

  .result-card h2 {
    font-size: 17px;
  }

  .result-reason {
    font-size: 11px;
  }

  .result-score {
    margin-top: 8px;
    padding: 9px;
  }

  .result-score strong {
    font-size: 27px;
  }

  .result-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    margin-top: 8px;
  }

  .result-grid div {
    padding: 6px 4px;
  }

  .result-grid span {
    font-size: 8px;
  }

  .result-grid strong {
    font-size: 13px;
  }

  .result-actions {
    margin-top: 8px;
  }

  .result-actions button {
    padding: 9px 6px;
    font-size: 11px;
  }
}

/* Start screen */
.start-screen {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 22px;
  background: radial-gradient(circle at 50% 24%, #263553 0%, #111827 54%, #080b10 100%);
  color: #f2f5f8;
  transition: opacity 0.18s ease, visibility 0.18s ease;
}

.start-screen.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.start-card {
  width: min(460px, 100%);
  border: 1px solid #344158;
  border-radius: 22px;
  padding: 24px 20px;
  background: rgba(15, 20, 32, 0.88);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  text-align: center;
}

.start-card h1 {
  font-size: clamp(30px, 8vw, 48px);
  margin-bottom: 10px;
}

.start-copy {
  margin: 0 auto 20px;
  max-width: 330px;
  color: #dbe3f1;
  line-height: 1.55;
  font-weight: 800;
}

.start-screen-button {
  width: min(260px, 80%);
  padding: 14px 18px;
  border-radius: 14px;
  font-size: 18px;
  letter-spacing: 0.08em;
}

.start-note {
  margin: 16px 0 0;
  color: #aab3c2;
  font-size: 12px;
}

.sound-btn {
  background: #273044;
}

.sound-btn.is-open {
  background: #35b96f;
  color: #061017;
}

@media (max-width: 820px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  body {
    overscroll-behavior: none;
  }

  #app {
    height: 100dvh;
    max-width: none;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow: hidden;
  }

  .topbar {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 6px;
    margin-bottom: 0;
  }

  .topbar h1 {
    font-size: 14px;
    line-height: 1;
    letter-spacing: 0.03em;
  }

  .subtitle {
    display: none;
  }

  .top-actions {
    gap: 4px;
    justify-content: end;
  }

  .top-actions button {
    padding: 7px 8px;
    border-radius: 9px;
    font-size: 10px;
  }

  .audio-controls {
    position: fixed;
    z-index: 60;
    left: 8px;
    right: 8px;
    top: 46px;
    display: none;
    justify-content: center;
    padding: 8px;
    box-shadow: 0 14px 34px rgba(0,0,0,0.36);
  }

  body.sound-open .audio-controls {
    display: flex;
  }

  .audio-controls input[type="range"] {
    width: 86px;
  }

  .game-layout {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow: hidden;
  }

  .battle-panel,
  .board-panel {
    border-radius: 12px;
    padding: 6px;
    box-shadow: none;
  }

  .battle-panel {
    flex: 0 0 auto;
  }

  .board-panel {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .status-row {
    gap: 4px;
    margin-bottom: 5px;
  }

  .status-row > div {
    padding: 5px 3px;
    border-radius: 8px;
    font-size: 11px;
  }

  .battle-stage {
    min-height: 76px;
    grid-template-columns: 1fr 26px 1fr;
    gap: 5px;
    padding: 6px;
    border-radius: 10px;
  }

  .sprite {
    min-height: 58px;
    gap: 2px;
    border-width: 2px;
    border-radius: 10px;
  }

  .sprite-name {
    font-size: 9px;
  }

  .sprite-face {
    width: 34px;
    height: 34px;
    font-size: 15px;
  }

  .sprite-image {
    width: 42px;
    height: 42px;
  }

  .versus {
    font-size: 11px;
  }

  .hp-area {
    margin-top: 4px;
  }

  .bar-label {
    font-size: 10px;
    margin: 3px 0 2px;
  }

  .bar {
    height: 8px;
  }

  .stats-grid {
    display: flex;
    gap: 4px;
    margin-top: 5px;
  }

  .stats-grid > div {
    flex: 1 1 0;
    min-width: 0;
    padding: 4px 3px;
    border-radius: 8px;
    font-size: 10px;
  }

  .stat-item {
    grid-template-columns: 18px 1fr;
    gap: 3px;
  }

  .stat-icon {
    width: 18px;
    height: 18px;
  }

  .stat-label {
    display: none;
  }

  .log,
  .controls-help {
    display: none;
  }

  .board-header {
    flex: 0 0 auto;
    margin-bottom: 4px;
    font-size: 11px;
  }

  .next-piece .next-cell {
    width: 20px;
    height: 20px;
  }

  .board {
    flex: 0 1 auto;
    width: min(62vw, 218px);
    max-height: calc(100dvh - 300px);
    min-height: 260px;
    margin: 0 auto;
    border-width: 4px;
    border-radius: 10px;
    padding: 3px;
    gap: 3px;
  }

  .cell {
    border-radius: 6px;
    font-size: 8px;
  }

  .touch-controls {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 1fr 1.25fr 1fr 1fr;
    gap: 8px;
    margin-top: 6px;
    padding: 0 10px max(6px, env(safe-area-inset-bottom));
  }

  .touch-controls button {
    min-height: 48px;
    padding: 7px 4px;
    border-radius: 14px;
    font-size: 16px;
    box-shadow: 0 5px 0 rgba(0,0,0,0.26);
    touch-action: manipulation;
  }

  .touch-drop {
    font-size: 13px !important;
    letter-spacing: 0.02em;
  }

  .result-modal {
    padding: 8px;
  }

  .result-card {
    max-height: calc(100dvh - 16px);
    padding: 12px;
    border-radius: 16px;
  }

  .result-card h2 {
    font-size: 17px;
  }

  .result-reason {
    font-size: 11px;
  }

  .result-score {
    margin: 10px 0;
    padding: 9px;
  }

  .result-score strong {
    font-size: 26px;
  }

  .result-grid {
    gap: 5px;
    grid-template-columns: repeat(3, 1fr);
  }

  .result-grid div {
    padding: 7px 4px;
  }

  .result-grid span {
    font-size: 9px;
  }

  .result-grid strong {
    font-size: 13px;
  }

  .result-actions {
    gap: 6px;
    margin-top: 10px;
  }

  .result-actions button {
    padding: 9px 8px;
    font-size: 11px;
  }
}

@media (max-width: 380px) {
  .board {
    width: min(60vw, 202px);
    max-height: calc(100dvh - 292px);
  }

  .touch-controls button {
    min-height: 44px;
  }

  .top-actions button {
    padding: 6px 6px;
    font-size: 9px;
  }
}


/* v12 mobile layout refinements */
.menu-panel {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.menu-section {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.menu-heading {
  width: 100%;
  color: #ffdc5c;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.button-order-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
}

.button-order-select {
  min-width: 0;
  border: 1px solid #344158;
  border-radius: 9px;
  background: #0f1420;
  color: #f2f5f8;
  padding: 7px 4px;
  font-weight: 900;
  text-align: center;
}

.secondary-button {
  background: #273044;
}

.secondary-button:disabled {
  opacity: 0.45;
}

@media (max-width: 820px) {
  #app {
    align-items: center;
  }

  .topbar,
  .game-layout {
    width: min(100%, 430px);
    margin-left: auto;
    margin-right: auto;
  }

  .battle-panel,
  .board-panel {
    width: 100%;
  }

  .board {
    width: min(86vw, 300px, calc((100dvh - 332px) / 2));
    min-width: 188px;
    max-height: none;
  }

  .touch-controls {
    width: 100%;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    padding-left: 0;
    padding-right: 0;
    margin-left: auto;
    margin-right: auto;
  }

  .touch-controls button {
    width: 100%;
    min-width: 0;
    min-height: 50px;
    display: grid;
    place-items: center;
    text-align: center;
    white-space: nowrap;
  }

  .touch-drop {
    font-size: 13px !important;
    text-align: center;
  }

  .audio-controls.menu-panel {
    left: 50%;
    right: auto;
    width: min(calc(100vw - 16px), 414px);
    transform: translateX(-50%);
    max-height: calc(100dvh - 64px);
    overflow: auto;
  }

  .menu-section {
    justify-content: center;
  }

  .menu-layout-section,
  .menu-result-section {
    width: 100%;
  }

  .menu-result-section .secondary-button {
    width: 100%;
  }
}

@media (max-width: 380px) {
  .board {
    width: min(84vw, 280px, calc((100dvh - 320px) / 2));
    min-width: 176px;
  }

  .touch-controls {
    gap: 8px;
  }

  .touch-controls button {
    min-height: 46px;
    border-radius: 12px;
  }
}

/* v14 title flow and help UI */

#startBtn.is-ready {
  background: #35b96f;
  color: #061017;
  box-shadow: 0 0 0 3px rgba(66, 211, 146, 0.2), 0 0 16px rgba(66, 211, 146, 0.38);
}

#startBtn.is-running {
  background: #3b4250;
  color: #aab3c2;
}

body.game-ready .battle-panel,
body.game-ready .board-panel {
  outline: 2px solid rgba(66, 211, 146, 0.55);
}

.info-modal {
  position: fixed;
  inset: 0;
  z-index: 125;
  display: grid;
  place-items: center;
  padding: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.info-modal.is-open {
  opacity: 1;
  pointer-events: auto;
}

.info-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 13, 0.72);
  backdrop-filter: blur(3px);
}

.info-card {
  position: relative;
  width: min(440px, 100%);
  max-height: calc(100dvh - 28px);
  overflow: auto;
  border-radius: 18px;
  border: 1px solid #344158;
  background: linear-gradient(180deg, #1b2333, #111827);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
  padding: 16px;
  transform: scale(0.98) translateY(6px);
  transition: transform 0.2s ease;
}

.info-modal.is-open .info-card {
  transform: scale(1) translateY(0);
}

.info-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.info-kicker {
  color: #ffdc5c;
  font-weight: 900;
  letter-spacing: 0.08em;
  font-size: 12px;
}

.info-card h2 {
  margin: 2px 0 0;
  font-size: 21px;
}

.help-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.help-list p {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #273044;
  border-radius: 12px;
  background: #0f1420;
  color: #dbe3f1;
  font-size: 13px;
  line-height: 1.45;
  font-weight: 700;
}


@media (max-width: 820px) {
  .topbar,
  .game-layout {
    width: min(100%, 430px);
  }

  .top-actions button#startBtn.is-ready {
    min-width: 74px;
  }

  .info-card {
    width: min(390px, 100%);
    padding: 12px;
    border-radius: 15px;
  }

  .info-card h2 {
    font-size: 17px;
  }

  .info-kicker {
    font-size: 11px;
  }

  .help-list p {
    padding: 8px 10px;
    font-size: 12px;
  }
}

/* v15 board start/resume overlay and unified menu popover */
.topbar {
  position: relative;
}

.audio-controls.menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 95;
  width: min(390px, calc(100vw - 16px));
  display: none;
  align-items: stretch;
  white-space: normal;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.42);
}

body.sound-open .audio-controls.menu-panel {
  display: flex;
}

.board {
  position: relative;
  cursor: pointer;
}

.board::before,
.board::after {
  pointer-events: none;
}

body.game-ready .board::before,
body.game-paused .board::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 5;
  border-radius: 7px;
  background: rgba(5, 8, 13, 0.38);
  backdrop-filter: blur(1px);
}

body.game-ready .board::after,
body.game-paused .board::after {
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: 6;
  transform: translate(-50%, -50%);
  min-width: 72%;
  padding: 12px 14px;
  border: 1px solid rgba(255, 220, 92, 0.55);
  border-radius: 14px;
  background: rgba(15, 20, 32, 0.78);
  color: #f2f5f8;
  text-align: center;
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1.35;
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.34);
  animation: boardPromptPulse 1.45s ease-in-out infinite;
}

body.game-ready .board::after {
  content: "TAP TO START";
}

body.game-paused .board::after {
  content: "PAUSED\A TAP TO RESUME";
  white-space: pre;
}

@keyframes boardPromptPulse {
  0%, 100% { opacity: 0.82; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.025); }
}

@media (max-width: 820px) {
  .audio-controls.menu-panel {
    position: fixed;
    top: 46px;
    left: 50%;
    right: auto;
    width: min(calc(100vw - 16px), 414px);
    transform: translateX(-50%);
    max-height: calc(100dvh - 64px);
    overflow: auto;
  }

  body.game-ready .board::after,
  body.game-paused .board::after {
    min-width: 78%;
    padding: 10px 12px;
    font-size: 12px;
    border-radius: 12px;
  }
}
