:root {
  --bg1: #2a1847;
  --bg2: #173a5e;
  --panel: rgba(255, 255, 255, 0.1);
  --text: #f4f6ff;
  --muted: #c0bfe6;
  --accent: #ffb938;
  --danger: #ff4d5e;
  --stop: #6fd3ff;
  --red: #ec4d4d;
  --blue: #3f8cff;
  --green: #35b86b;
  --yellow: #f7c62f;
  --purple: #a86be8;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
  color: var(--text);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  /* ダブルタップ拡大・テキスト選択・長押しメニューを無効化 */
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 10px env(safe-area-inset-bottom);
}

.hidden {
  display: none !important;
}

/* ---- ボタン ---- */
.btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 10px 18px;
  font: inherit;
  font-size: 16px;
  font-weight: bold;
  color: var(--text);
  background: rgba(255, 255, 255, 0.16);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  cursor: pointer;
  touch-action: manipulation;
}

.btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

.btn.primary {
  background: var(--accent);
  color: #3a2500;
}

.btn.big {
  font-size: 22px;
  padding: 14px 56px;
}

.btn.rise {
  background: #e0653a;
}

.btn.rise .bonus {
  font-size: 12px;
  opacity: 0.85;
}

/* ---- タイトル ---- */
.title-screen {
  align-items: center;
  justify-content: center;
  gap: 24px;
  text-align: center;
  overflow-y: auto;
}

.title-screen h1 {
  margin: 14px 0 6px;
  font-size: clamp(30px, 9vw, 44px);
  line-height: 1.2;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
}

.title-screen .sub {
  margin: 0;
  color: var(--muted);
}

.logo-blocks {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.logo-blocks .face {
  position: relative;
  inset: auto;
  width: 44px;
  height: 44px;
  font-size: 22px;
}

.logo-blocks .face:nth-child(odd) {
  transform: translateY(-8px);
}

.scores {
  width: 100%;
  max-width: 340px;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--panel);
}

.scores h2 {
  margin: 0 0 6px;
  font-size: 16px;
  color: var(--accent);
}

.score-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 14px;
}

.score-list li {
  display: grid;
  grid-template-columns: 2.6em 1fr 3.6em 6.6em;
  align-items: baseline;
  gap: 6px;
  padding: 4px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.score-list li:first-child {
  border-top: none;
}

.score-list li.empty {
  display: block;
  text-align: center;
  color: var(--muted);
}

.score-list .pts {
  font-weight: bold;
  text-align: right;
}

.score-list .date,
.score-list .rank {
  color: var(--muted);
  font-size: 12px;
}

.score-list .date {
  text-align: right;
}

.back-link {
  color: var(--muted);
  font-size: 14px;
}

/* ---- ゲーム画面の上部 ---- */
.hud {
  padding: 8px 0 6px;
}

.hud-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.stat {
  flex: 1.6;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 6px;
  border-radius: 12px;
  background: var(--panel);
}

.stat.small {
  flex: 1;
}

.stat .value {
  font-size: 22px;
  font-weight: bold;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.label {
  font-size: 10px;
  color: var(--muted);
}

/* せり上がりゲージ */
.gauge {
  --p: 0;
  position: relative;
  height: 22px;
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.gauge-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #ffd25e, #ff8a3d);
  transform-origin: left center;
  transform: scaleX(var(--p));
}

.gauge.danger .gauge-fill {
  background: linear-gradient(90deg, #ff7a7a, var(--danger));
  animation: blink 0.5s ease-in-out infinite alternate;
}

.gauge.stopped .gauge-fill {
  background: linear-gradient(90deg, #9fe3ff, var(--stop));
  animation: none;
}

.gauge-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
  font-variant-numeric: tabular-nums;
}

/* ---- 盤面 ---- */
.board-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board {
  --cell: 40px;
  position: relative;
  width: calc(var(--cols) * var(--cell));
  /* 予告列を半マス分だけ見せる */
  height: calc((var(--rows) + 0.5) * var(--cell));
  touch-action: none;
  cursor: pointer;
}

.board-clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.3);
  box-shadow: inset 0 3px 0 rgba(255, 77, 94, 0.5); /* 天井 */
}

.layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.piece {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cell);
  height: var(--cell);
  transform: translate(calc(var(--x) * var(--cell)), calc(var(--y) * var(--cell)));
}

.cell {
  background: rgba(255, 255, 255, 0.03);
}

.cell.alt {
  background: rgba(255, 255, 255, 0.07);
}

.block {
  transition: transform 250ms cubic-bezier(0.3, 1.25, 0.6, 1);
}

.board.rising .block {
  transition: transform 200ms ease-out;
}

.board.no-anim .piece,
.board.no-anim .face {
  transition: none !important;
}

.face {
  position: absolute;
  inset: 6%;
  border-radius: 22%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * 0.42);
  color: rgba(255, 255, 255, 0.92);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.22), inset 0 3px 0 rgba(255, 255, 255, 0.3);
  transition: transform 200ms ease-in, opacity 200ms ease-in;
}

.face .sym {
  line-height: 1;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}

.face.red { background: var(--red); }
.face.blue { background: var(--blue); }
.face.green { background: var(--green); }
.face.yellow { background: var(--yellow); color: rgba(90, 60, 0, 0.85); }
.face.yellow .sym { text-shadow: none; }
.face.purple { background: var(--purple); }

.block.removing .face {
  transform: scale(0.2);
  opacity: 0;
}

.face.shake {
  animation: shake 0.3s ease-in-out;
}

/* 予告列：盤面の下に暗く半分だけ見せる */
.preview-shade {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--cell) * 0.5);
  background: rgba(10, 8, 25, 0.62);
  border-top: 2px dashed rgba(255, 255, 255, 0.25);
  pointer-events: none;
}

/* ピンチ列の赤い点滅 */
.pinch {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--cell);
  height: calc(var(--rows) * var(--cell));
  transform: translateX(calc(var(--x) * var(--cell)));
  background: linear-gradient(180deg, rgba(255, 60, 80, 0.75), rgba(255, 60, 80, 0.15));
  opacity: 0;
}

.pinch.on {
  animation: blink 0.45s ease-in-out infinite alternate;
}

/* ストップ中のオーバーレイ */
.stop-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(111, 211, 255, 0.18);
  color: #e6f8ff;
  font-size: calc(var(--cell) * 0.9);
  font-weight: bold;
  text-shadow: 0 2px 6px rgba(0, 60, 120, 0.8);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

/* 獲得点・コンボ・各種表示 */
.fx {
  z-index: 2;
}

.popup {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cell);
  height: var(--cell);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: calc(var(--cell) * 0.42);
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  transform: translate(calc(var(--x) * var(--cell)), calc(var(--y) * var(--cell)));
  animation: popup 0.9s ease-out forwards;
}

.popup .combo {
  font-size: calc(var(--cell) * 0.34);
  color: var(--accent);
}

.float {
  position: absolute;
  left: 50%;
  top: 38%;
  padding: 8px 20px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  font-weight: bold;
  font-size: 20px;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  animation: fade 1s ease-out forwards;
}

.float.bonus {
  top: 85%;
  color: #ffb08a;
}

.float.stop {
  color: var(--stop);
  font-size: 26px;
}

.float.level {
  top: 25%;
  color: var(--accent);
}

/* ---- 下部 ---- */
.bar.bottom {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 8px 0 12px;
}

/* ---- 重ねて表示する画面 ---- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 10, 30, 0.65);
  animation: fadein 0.2s ease-out;
}

.overlay.clear {
  background: rgba(10, 10, 30, 0.35);
}

.countdown {
  font-size: 120px;
  font-weight: bold;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
}

.card {
  width: 100%;
  max-width: 340px;
  padding: 24px 20px;
  border-radius: 20px;
  background: #33306b;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  text-align: center;
  animation: popin 0.3s cubic-bezier(0.3, 1.4, 0.6, 1);
}

.card h2 {
  margin: 0 0 10px;
  font-size: 26px;
}

.rank-msg {
  color: var(--accent);
  font-weight: bold;
  font-size: 20px;
  min-height: 0;
}

.result {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: center;
  gap: 6px 16px;
  margin: 12px 0 20px;
  text-align: left;
}

.result dt {
  color: var(--muted);
}

.result dd {
  margin: 0;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}

.card-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---- アニメーション ---- */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-12%); }
  40% { transform: translateX(10%); }
  60% { transform: translateX(-7%); }
  80% { transform: translateX(4%); }
}

@keyframes blink {
  from { opacity: 0.25; }
  to { opacity: 1; }
}

@keyframes popup {
  0% { opacity: 0; margin-top: 0; }
  20% { opacity: 1; }
  100% { opacity: 0; margin-top: calc(var(--cell) * -1.2); }
}

@keyframes fade {
  0% { opacity: 0; }
  15%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes fadein {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popin {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@media (max-height: 640px) {
  .stat .value { font-size: 18px; }
  .hud-row { margin-bottom: 4px; }
  .bar.bottom { padding: 6px 0 8px; }
  .btn { padding: 7px 14px; font-size: 14px; }
}
