/* Color Block: base theme, portrait shell, glossy blocks (CSS gradients only). */
:root {
  --bg: #12141c;
  --board-well: #1b1f2b;
  --grid-line: #262b3a;
  --text: #e9ecf5;
  --text-dim: #8b92a8;
  --c1: #ff6b5e;
  --c2: #ffb63d;
  --c3: #8bd94a;
  --c4: #2ec4b6;
  --c5: #45a7f5;
  --c6: #7b6cf6;
  --c7: #d468e8;
  --c8: #ff5c9a;
  --cell: 40px;
  --mini: 24px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  overflow: hidden;
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 16px 20px 8px;
}

.hud-score { display: flex; flex-direction: column; }
.hud-high { align-items: flex-end; }
.hud-label { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-dim); }
.hud-value { font-size: 32px; font-weight: 700; font-variant-numeric: tabular-nums; }

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  min-height: 0;
  padding: 0 12px;
}

.board {
  width: min(100%, calc(100dvh - var(--safe-top) - var(--safe-bottom) - 260px));
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  background: var(--board-well);
  border-radius: 12px;
  box-shadow: 0 0 0 1px var(--grid-line), 0 8px 24px rgba(0, 0, 0, 0.45);
  touch-action: none;
}

.cell {
  position: relative;
  margin: 1.5px;
  border-radius: 22%;
  background: rgba(255, 255, 255, 0.035);
  box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.25);
}

/* Glossy recipe: base color + top-left radial highlight + lighter top edge + inner bottom shadow. */
.cell:not([data-color="0"]) {
  background:
    radial-gradient(circle at 28% 24%, rgba(255, 255, 255, 0.55) 0, rgba(255, 255, 255, 0) 55%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.18) 0, rgba(255, 255, 255, 0) 45%),
    var(--c);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.38),
    inset 0 -3px 0 rgba(0, 0, 0, 0.28),
    0 1px 2px rgba(0, 0, 0, 0.4);
}

.cell[data-color="1"] { --c: var(--c1); }
.cell[data-color="2"] { --c: var(--c2); }
.cell[data-color="3"] { --c: var(--c3); }
.cell[data-color="4"] { --c: var(--c4); }
.cell[data-color="5"] { --c: var(--c5); }
.cell[data-color="6"] { --c: var(--c6); }
.cell[data-color="7"] { --c: var(--c7); }
.cell[data-color="8"] { --c: var(--c8); }

/* Ghost preview and clear-line highlight (driven by T07). */
.cell[data-ghost="1"] { --gc: var(--c1); }
.cell[data-ghost="2"] { --gc: var(--c2); }
.cell[data-ghost="3"] { --gc: var(--c3); }
.cell[data-ghost="4"] { --gc: var(--c4); }
.cell[data-ghost="5"] { --gc: var(--c5); }
.cell[data-ghost="6"] { --gc: var(--c6); }
.cell[data-ghost="7"] { --gc: var(--c7); }
.cell[data-ghost="8"] { --gc: var(--c8); }
.cell.ghost::after,
.cell.ghost-bad::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--gc, #fff);
  opacity: 0.45;
}
.cell.ghost-bad::after { opacity: 0.2; }
.cell.hl { outline: 2px solid rgba(255, 255, 255, 0.7); outline-offset: -2px; }

@keyframes pop { 0% { transform: scale(0.85); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes clear-out {
  0% { transform: scale(1); opacity: 1; filter: none; }
  30% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(0); opacity: 0; }
}
.cell.pop { animation: pop 90ms ease-out; }
.cell.clearing { animation: clear-out 380ms ease-in both; animation-delay: var(--delay, 0ms); }

.tray {
  width: min(100%, calc(100dvh - var(--safe-top) - var(--safe-bottom) - 260px));
  height: 132px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  touch-action: none;
}

.slot {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.piece {
  display: grid;
  grid-template-columns: repeat(var(--pw), var(--mini));
  grid-template-rows: repeat(var(--ph), var(--mini));
}

.slot.dim { opacity: 0.35; }
.slot.dragging .piece { visibility: hidden; }
.cell.mini { margin: 1px; border-radius: 20%; }

@keyframes deal-in { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.slot.deal .piece { animation: deal-in 200ms ease-out both; animation-delay: var(--delay, 0ms); }

.fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.rotate-overlay {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  text-align: center;
  font-size: 18px;
  color: var(--text-dim);
}

@media (orientation: landscape) and (max-height: 500px) {
  .rotate-overlay { display: flex; }
}

/* Floating piece while dragging: compositor-only transform, never intercepts pointers. */
.piece.float {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 50;
  pointer-events: none;
  will-change: transform;
}

.app { touch-action: none; }

/* Effects (T08): shake, floating score, combo banner. Positions come from CSSOM custom properties. */
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(var(--shake, 2px), 0); }
  40% { transform: translate(calc(var(--shake, 2px) * -1), calc(var(--shake, 2px) * 0.5)); }
  60% { transform: translate(calc(var(--shake, 2px) * 0.6), calc(var(--shake, 2px) * -0.5)); }
  80% { transform: translate(calc(var(--shake, 2px) * -0.4), 0); }
}
.board.shake { animation: shake 220ms linear; }

@keyframes float-up {
  from { transform: translate(-50%, 0); opacity: 1; }
  to { transform: translate(-50%, -40px); opacity: 0; }
}
.float-score {
  position: absolute;
  left: var(--x, 50%);
  top: var(--y, 50%);
  z-index: 40;
  pointer-events: none;
  font-weight: 800;
  font-size: 22px;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
  animation: float-up 700ms ease-out both;
}

@keyframes combo-pop {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  20% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
  75% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -70%) scale(1); opacity: 0; }
}
.combo-text {
  position: absolute;
  left: 50%;
  top: 38%;
  z-index: 45;
  pointer-events: none;
  font-weight: 900;
  font-size: 34px;
  color: #FFD76A;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.7);
  animation: combo-pop 800ms ease-out both;
}

@media (prefers-reduced-motion: reduce) {
  .board.shake { animation: none; }
}

/* Screens (T09): HUD settings button, banners, Game Over, settings sheet, confirm. */
[hidden] { display: none !important; }

.icon-btn {
  align-self: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 22px;
  background: var(--board-well);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

.banners {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--safe-top);
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 12px;
  pointer-events: none;
}
.banner {
  pointer-events: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #3a2f1a;
  border: 1px solid var(--c2);
  font-size: 14px;
}
.banner-text { flex: 1 1 200px; }
.banner-btn {
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: var(--board-well);
  color: var(--text);
  font-size: 14px;
}

.overlays { position: absolute; inset: 0; z-index: 100; pointer-events: none; }
.overlay {
  pointer-events: auto;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 9, 14, 0.78);
}
.confirm-wrap { z-index: 2; }
.card {
  width: min(100%, 340px);
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  border-radius: 16px;
  background: var(--board-well);
  box-shadow: 0 0 0 1px var(--grid-line), 0 12px 32px rgba(0, 0, 0, 0.5);
  text-align: center;
}
.card-title { margin: 0; font-size: 22px; }
.card-text { margin: 0; color: var(--text-dim); font-size: 15px; line-height: 1.4; }
.card-label { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-dim); }
.card-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.card-row { display: flex; justify-content: center; align-items: center; gap: 12px; }
.big-score { font-size: 56px; font-weight: 800; font-variant-numeric: tabular-nums; }
.record { font-size: 20px; font-weight: 700; color: var(--c2); }
.btn, .row {
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--grid-line);
  color: var(--text);
  font-size: 16px;
}
.btn.primary { background: var(--c5); color: #0b1020; font-weight: 700; }
.btn.small { min-height: 36px; font-size: 14px; }
.row { text-align: left; }
.row:disabled { color: var(--text-dim); opacity: 0.6; }
.row.highlight { box-shadow: 0 0 0 2px var(--c2); }
.diag { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.diag-text {
  margin: 0;
  max-height: 160px;
  overflow: auto;
  padding: 8px;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-dim);
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-all;
  -webkit-user-select: text;
  user-select: text;
}
