:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --border: #d2d2d7;
  --fill: rgba(118, 118, 128, .12);
  --fill-2: rgba(118, 118, 128, .2);
  --blue: #0071e3;
  --blue-hover: #0077ed;
  --orange: #bf4800;
  --yellow: #fdc700;
  --focus: 0 0 0 4px rgba(0, 125, 250, .35);
  --radius: 18px;
  --shadow: 2px 4px 12px rgba(0, 0, 0, .08);
  --ease: cubic-bezier(0, 0, .5, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;

  --board-size: min(94vw, 470px, calc((100vh - 230px) / 1.4));
  --mini: calc(var(--board-size) / 17);
  --mini-gap: 2px;
}

@supports (height: 100dvh) {
  :root {
    --board-size: min(94vw, 470px, calc((100dvh - 230px) / 1.4));
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; overscroll-behavior: none; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.47;
  letter-spacing: -.022em;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

p { margin: 0; }
img { display: block; max-width: 100%; }
.hidden, [hidden] { display: none !important; }
button { touch-action: manipulation; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 18px;
  border: 0;
  border-radius: 980px;
  font: 400 15px/1 var(--font);
  letter-spacing: -.01em;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .2s var(--ease), color .2s var(--ease), opacity .2s;
}
.btn-sm { min-height: 32px; padding: 0 14px; font-size: 14px; }
.btn-lg { min-height: 44px; padding: 0 22px; font-size: 17px; }
.lbl-short { display: none; }
.btn-block { width: 100%; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-hover); }
.btn-primary:active { background: #006edb; }
.btn:focus-visible, .icon-btn:focus-visible { outline: 0; box-shadow: var(--focus); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--fill);
  color: var(--blue);
  cursor: pointer;
  transition: background-color .2s var(--ease), color .2s;
}
.icon-btn:hover { background: var(--fill-2); }
.icon-btn:active { transform: scale(.94); }
.icon-btn .off, .icon-btn.muted .on { display: none; }
.icon-btn.muted .off { display: inline; }
.icon-btn.muted { color: var(--text-2); }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
}
.pill-accent { background: rgba(191, 72, 0, .1); color: var(--orange); }

/* ---------- Navigation bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  flex: none;
  background: rgba(251, 251, 253, .8);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid rgba(0, 0, 0, .16);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 52px;
  padding: 0 28px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
}
.logo-full { width: auto; height: 32px; flex: none; }
.brand-text {
  display: flex;
  align-items: center;
  padding-left: 12px;
  border-left: 1px solid rgba(0, 0, 0, .14);
  white-space: nowrap;
}
.brand-text small { font-size: 14px; color: var(--text-2); letter-spacing: -.01em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- Layout ---------- */

.app {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 12px 12px max(12px, env(safe-area-inset-bottom));
}

/* ---------- Scores ---------- */

.scores {
  width: var(--board-size);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
}
.best {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  justify-self: start;
  padding: 4px 10px;
  border-radius: 980px;
  background: rgba(253, 199, 0, .18);
  color: #8a6400;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
.score-wrap { text-align: center; }
.eyebrow {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .011em;
  color: var(--orange);
}
.score {
  font-size: clamp(36px, 10vw, 48px);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}
.score.bump { animation: bump .3s var(--ease); }
@keyframes bump { 40% { transform: scale(1.12); } }

/* ---------- Board ---------- */

.board-wrap { position: relative; }

.board {
  width: var(--board-size);
  height: var(--board-size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 4px;
  padding: 10px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: filter .6s;
  touch-action: none;
}
.board.over { filter: grayscale(.9) opacity(.75); }
.board.shake { animation: shake .4s; }
@keyframes shake {
  20% { transform: translate(-5px, 2px); }
  40% { transform: translate(5px, -2px); }
  60% { transform: translate(-3px, 1px); }
  80% { transform: translate(3px, -1px); }
}

.cell {
  border-radius: 7px;
  background: #ececf0;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .06);
}

.block {
  --bev: 3px;
  border-radius: 7px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .3) 0%, rgba(255, 255, 255, 0) 60%), var(--c);
  box-shadow:
    inset 0 calc(var(--bev) * -1) 0 rgba(0, 0, 0, .14),
    inset 0 1px 0 rgba(255, 255, 255, .45),
    0 1px 2px rgba(0, 0, 0, .12);
}

.cell.ghost {
  background: var(--c);
  opacity: .35;
  box-shadow: none;
}

.cell.highlight {
  opacity: 1;
  background: linear-gradient(180deg, rgba(255, 255, 255, .4) 0%, rgba(255, 255, 255, 0) 60%), var(--c);
  box-shadow:
    inset 0 -3px 0 rgba(0, 0, 0, .14),
    inset 0 1px 0 rgba(255, 255, 255, .5),
    0 0 12px var(--c);
}

.cell.placed { animation: place .22s var(--ease); }
@keyframes place {
  from { transform: scale(.75); }
  to { transform: scale(1); }
}

.cell.clearing { animation: clear .45s ease-in both; }
@keyframes clear {
  0% { transform: scale(1); filter: brightness(1); }
  35% { transform: scale(1.12); filter: brightness(1.35); }
  100% { transform: scale(0); opacity: 0; }
}

/* ---------- Tray ---------- */

.tray {
  width: var(--board-size);
  height: calc(var(--board-size) * .36);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  touch-action: none;
}
.slot {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
}
.slot.dragging .piece { opacity: 0; }

.piece {
  display: grid;
  transition: transform .2s var(--ease), opacity .2s, filter .2s;
}
.tray .block { --bev: 2px; border-radius: 4px; }
.slot:hover .piece:not(.unfit) { transform: scale(1.06); }
.piece.unfit { opacity: .3; filter: grayscale(1); }
.piece.appear { animation: appear .35s cubic-bezier(.2, 1.4, .4, 1) backwards; }
@keyframes appear { from { transform: scale(0); opacity: 0; } }

.drag {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100;
  pointer-events: none;
  will-change: transform;
}
.drag .piece {
  animation: lift .12s var(--ease);
  filter: drop-shadow(0 10px 16px rgba(0, 0, 0, .18));
}
@keyframes lift { from { transform: scale(.55); } }

.hint {
  max-width: var(--board-size);
  font-size: 13px;
  line-height: 1.38;
  text-align: center;
  color: var(--text-2);
  letter-spacing: -.01em;
}

/* ---------- Effects ---------- */

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

.float-score {
  position: absolute;
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
  color: var(--text);
  text-shadow: 0 0 6px #fff, 0 0 2px #fff;
  font-variant-numeric: tabular-nums;
  animation: floatUp .9s var(--ease) forwards;
}
@keyframes floatUp {
  0% { transform: translate(-50%, -50%) scale(.6); opacity: 0; }
  20% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
  100% { transform: translate(-50%, -160%) scale(1); opacity: 0; }
}

.praise {
  position: absolute;
  left: 50%;
  top: 45%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 28px;
  border-radius: 22px;
  white-space: nowrap;
  background: rgba(255, 255, 255, .86);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .04), 0 20px 50px rgba(0, 0, 0, .16);
  animation: praise 1.3s var(--ease) forwards;
}
.praise-main {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: clamp(26px, 8vw, 34px);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -.01em;
}
.praise-main::before {
  content: "";
  flex: none;
  width: .8em;
  height: .8em;
  background: url("assets/favicon.png") center / contain no-repeat;
}
.praise-combo {
  font-size: 15px;
  font-weight: 600;
  color: var(--blue);
}
@keyframes praise {
  0% { transform: translate(-50%, -50%) scale(.6); opacity: 0; }
  18% { transform: translate(-50%, -50%) scale(1.04); opacity: 1; }
  30% { transform: translate(-50%, -50%) scale(1); }
  80% { transform: translate(-50%, -55%); opacity: 1; }
  100% { transform: translate(-50%, -70%); opacity: 0; }
}

/* ---------- Game over sheet ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, .4);
  animation: sheet-fade .3s var(--ease);
}
.sheet {
  width: 100%;
  max-width: 380px;
  padding: 40px 36px 32px;
  border-radius: 18px;
  background: #fff;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .22);
  animation: sheet-in .3s var(--ease);
}
@keyframes sheet-in { from { opacity: 0; transform: scale(.94); } }
@keyframes sheet-fade { from { opacity: 0; } }

.sheet .logo-mark { display: block; margin: 0 auto 18px; }
.sheet h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.17;
  font-weight: 600;
  letter-spacing: .009em;
}
.final-label {
  margin-top: 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .02em;
}
.final-score {
  font-size: 56px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}
#newBest { margin-top: 6px; }
.final-best {
  margin: 10px 0 26px;
  font-size: 15px;
  color: var(--text-2);
  letter-spacing: -.016em;
}

/* ---------- Install sheet ---------- */

.sheet-install { position: relative; }
.sheet-close {
  position: absolute;
  top: 14px;
  right: 14px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--fill);
  color: var(--text-2);
  cursor: pointer;
  transition: background-color .2s, color .2s;
}
.sheet-close:hover { background: var(--fill-2); color: var(--text); }
.app-icon {
  margin: 0 auto 16px;
  border-radius: 15px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .06), 0 4px 12px rgba(0, 0, 0, .1);
}
.sheet-sub {
  margin: 8px auto 22px;
  max-width: 300px;
  font-size: 15px;
  line-height: 1.43;
  color: var(--text-2);
  letter-spacing: -.016em;
}
.steps {
  margin: 0 0 26px;
  padding: 0;
  list-style: none;
  text-align: left;
  border-radius: 12px;
  background: var(--bg);
}
.steps li {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  font-size: 15px;
  line-height: 1.4;
  letter-spacing: -.016em;
}
.steps li + li::before {
  content: "";
  position: absolute;
  top: 0;
  left: 52px;
  right: 0;
  height: 1px;
  transform: scaleY(.5);
  background: rgba(60, 60, 67, .36);
}
.steps strong { font-weight: 600; }
.step-num {
  display: grid;
  place-items: center;
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}
.step-icon {
  display: inline-block;
  vertical-align: -3px;
  color: var(--blue);
}

/* ---------- Responsive ---------- */

@media (max-width: 734px) {
  .topbar-inner { padding: 0 16px; }
  .logo-full { height: 28px; }
}

@media (max-width: 560px) {
  .brand-text { display: none; }
}

@media (max-width: 360px) {
  .lbl-long { display: none; }
  .lbl-short { display: inline; }
}

@media (max-width: 480px) {
  .sheet { padding: 36px 22px 24px; }
}
