/* ═══════════════════════════════════════════════════════
   GRIDDLE — Styles v6.0 (Mobile Optimised)
   Fixes: cell size, touch-action, modal iOS scroll,
          landscape grid layout, will-change, hover guards,
          backdrop-filter fallback, breakpoint overlap
   ═══════════════════════════════════════════════════════ */

/* ── Design Tokens ────────────────────────────────────── */
:root {
  --bg: #0a0a10;
  --surface: #13131c;
  --surface2: #1c1c28;
  --surface3: #252535;
  --border: #2a2a3e;
  --border2: #363650;
  --text: #f0f0f8;
  --muted: #6868a0;
  --muted2: #4a4a78;

  --accent: #6C63FF;
  --accent2: #43D9A2;
  --danger: #FF6584;
  --gold: #FFD166;
  --orange: #f18741;
  --pink: #FF3CAC;
  --blue: #2979FF;

  --radius: 10px;
  --radius-lg: 18px;

  /* FIX #1: better clamp — more room for cells, reduce padding contribution */
  --cell-size: clamp(30px, calc((100vw - 64px) / 10), 46px);
  --gap: 3px;

  --font-display: 'Syne', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'DM Mono', monospace;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, .5);
}

/* ── Reset ────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  overflow-x: hidden;
  overscroll-behavior: none;
}

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* ── Screen flash ─────────────────────────────────────── */
#screen-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9000;
  opacity: 0;
  background: var(--flash-color, var(--gold));
  mix-blend-mode: screen;
}

#screen-flash.flash {
  animation: screenFlash .4s ease forwards;
}

@keyframes screenFlash {
  0% {
    opacity: .35;
  }

  100% {
    opacity: 0;
  }
}

/* ── App layout ───────────────────────────────────────── */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding:
    max(.75rem, env(safe-area-inset-top)) max(.75rem, env(safe-area-inset-right)) max(1.5rem, env(safe-area-inset-bottom)) max(.75rem, env(safe-area-inset-left));
}

/* ── Header ───────────────────────────────────────────── */
header {
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .4rem 0 .6rem;
  gap: .4rem;
  flex-wrap: nowrap;
}

.logo-wrap {
  display: flex;
  align-items: baseline;
  gap: .35rem;
  flex-shrink: 0;
}

.logo {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -.04em;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  user-select: none;
}

.puzzle-day {
  font-family: var(--font-mono);
  font-size: .75rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: .02em;
  padding-bottom: .1rem;
  min-width: 2ch;
}

.header-right {
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-shrink: 1;
  min-width: 0;
}

/* Streak badge */
.streak-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .72rem;
  font-weight: 600;
  color: var(--gold);
  background: rgba(255, 209, 102, .1);
  border: 1px solid rgba(255, 209, 102, .2);
  padding: 5px 8px;
  border-radius: 20px;
  min-height: 32px;
  flex-shrink: 0;
}

.streak-icon {
  font-size: .85rem;
}

.streak-label {
  color: rgba(255, 209, 102, .7);
  font-size: .65rem;
}

.freeze-badge {
  font-size: .65rem;
  color: #56CBF9;
  margin-left: 2px;
}

/* Attempt badge */
.attempt-badge {
  font-size: .65rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 4px 7px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}

.attempt-badge.ranked {
  color: var(--accent2);
  border-color: rgba(67, 217, 162, .3);
  background: rgba(67, 217, 162, .08);
}

.attempt-badge.practice {
  color: var(--orange);
  border-color: rgba(241, 135, 65, .3);
  background: rgba(241, 135, 65, .08);
}

/* Countdown */
.next-label {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  flex-shrink: 0;
  margin-left: auto;
}

.next-text {
  font-size: .6rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
}

.js-countdown {
  font-family: var(--font-mono);
  font-size: .82rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: .04em;
  font-variant-numeric: tabular-nums;
}

/* ── Score bar ────────────────────────────────────────── */
.score-bar {
  width: 100%;
  max-width: 520px;
  display: flex;
  gap: .5rem;
  margin-bottom: .5rem;
}

.score-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .45rem .6rem;
  text-align: center;
  transition: border-color .2s;
  min-width: 0;
}

.score-card.accent {
  border-color: rgba(108, 99, 255, .3);
}

.score-card .label {
  font-size: .58rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}

.score-card .value {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 500;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  transition: color .15s;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-card.accent .value {
  color: var(--accent2);
}

/* ── Next queue ───────────────────────────────────────── */
.next-queue-wrap {
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: .4rem;
  padding: 0 .1rem;
}

.next-queue-label {
  font-size: .58rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted2);
  flex-shrink: 0;
}

.next-queue {
  display: flex;
  gap: .4rem;
  align-items: center;
}

.next-queue canvas {
  opacity: .5;
  border-radius: 4px;
}

/* ── Grid ─────────────────────────────────────────────── */
.grid-wrap {
  position: relative;
  width: 100%;
  max-width: 520px;
  display: flex;
  justify-content: center;
}

#grid {
  display: grid;
  grid-template-columns: repeat(10, var(--cell-size));
  grid-template-rows: repeat(10, var(--cell-size));
  gap: var(--gap);
  background: #1e1e2e;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  margin-bottom: .5rem;
  user-select: none;
  touch-action: none;
  /* prevent scroll/zoom inside grid */
}

/* ── Cell ─────────────────────────────────────────────── */
.cell {
  border-radius: 4px;
  background: var(--surface2);
  outline: 1px solid rgba(255, 255, 255, .04);
  cursor: pointer;
  transition: transform .07s, background .07s, box-shadow .07s, opacity .07s;
  position: relative;
  overflow: hidden;
  /* FIX: manipulation blocks double-tap zoom without killing pointer events */
  touch-action: manipulation;
  /* FIX #7: will-change only during animation, not always */
  will-change: auto;
}

.cell::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, .13) 0%, transparent 55%);
  border-radius: 3px;
  opacity: 0;
  transition: opacity .1s;
  pointer-events: none;
}

.cell.filled::after {
  opacity: 1;
}

.cell.filled::before {
  content: attr(data-pattern);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell-size) * .35);
  line-height: 1;
  opacity: .25;
  pointer-events: none;
  color: rgba(255, 255, 255, .9);
}

.cell.hover-ok {
  background: var(--hover-color, var(--accent)) !important;
  opacity: .82;
  transform: scale(1.06);
  z-index: 2;
  box-shadow: 0 0 10px var(--hover-color, var(--accent));
}

.cell.hover-no {
  background: var(--danger) !important;
  opacity: .45;
  transform: scale(.94);
}

/* FIX #7: will-change only on animated cells */
.cell.just-placed {
  will-change: transform;
  animation: cellDrop .3s cubic-bezier(.175, .885, .32, 1.275) forwards;
}

@keyframes cellDrop {
  0% {
    transform: scale(.5) translateY(-4px);
    opacity: .5;
  }

  65% {
    transform: scale(1.14) translateY(1px);
    opacity: 1;
  }

  100% {
    transform: scale(1) translateY(0);
  }
}

.cell.clearing {
  will-change: transform;
  animation: clearFlash .45s ease forwards;
  z-index: 3;
}

@keyframes clearFlash {
  0% {
    transform: scale(1);
    filter: brightness(1);
  }

  30% {
    transform: scale(1.18);
    filter: brightness(2.5) saturate(1.5);
  }

  60% {
    transform: scale(1.06);
    filter: brightness(1.8);
  }

  100% {
    transform: scale(0);
    filter: brightness(3);
    opacity: 0;
  }
}

/* FIX #10: Enhanced keyboard focus */
.cell:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  z-index: 4;
  box-shadow: 0 0 0 2px rgba(108, 99, 255, .3);
}

/* Near-complete highlight */
.cell.near-complete:not(.filled) {
  background: rgba(255, 209, 102, 0.12) !important;
  outline-color: rgba(255, 209, 102, 0.35) !important;
  transition: background .2s, outline-color .2s;
}

/* ── Tray ─────────────────────────────────────────────── */
.tray {
  width: 100%;
  max-width: 520px;
  display: flex;
  gap: .5rem;
  justify-content: center;
  margin-bottom: .5rem;
}

.tray-slot {
  flex: 1;
  min-height: clamp(70px, 18vw, 108px);
  min-width: 0;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  transition: border-color .15s, background .15s, transform .1s, box-shadow .15s;
  /* touch-action:none lets pointer events work without e.preventDefault() in
     pointerdown — prevents pointerup from being swallowed on iOS/Android */
  touch-action: none;
  position: relative;
  overflow: hidden;
}

.tray-slot:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tray-slot:active:not(.empty) {
  transform: scale(.95);
}

.tray-slot.selected {
  border-color: var(--accent);
  background: var(--surface2);
  box-shadow: 0 0 0 3px rgba(108, 99, 255, .22), 0 0 20px rgba(108, 99, 255, .2);
  transform: translateY(-3px);
}

.tray-slot.selected canvas {
  filter: drop-shadow(0 0 7px var(--accent));
}

.tray-slot.empty {
  opacity: .25;
  cursor: default;
}

.tray-slot canvas {
  display: block;
}

.tray-slot.frozen {
  opacity: 0.3;
  filter: saturate(0.2);
  transition: opacity .25s ease, filter .25s ease;
  pointer-events: none;
}

/* FIX: hover only on real pointer devices */
@media (hover: hover) {
  .tray-slot:hover:not(.empty):not(.selected) {
    border-color: var(--border2);
    background: var(--surface2);
  }
}

/* ── Undo + Stats row ─────────────────────────────────── */
.undo-row {
  width: 100%;
  max-width: 520px;
  display: flex;
  gap: .5rem;
  margin-bottom: .5rem;
}

.btn-undo,
.btn-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  /* FIX #1: touch target minimum */
  padding: .4rem .9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, transform .08s, opacity .15s;
  touch-action: manipulation;
}

.btn-undo {
  flex: 2;
}

.btn-stats {
  flex: 1;
}

.btn-undo:active,
.btn-stats:active {
  transform: scale(.96);
}

.btn-undo:disabled {
  opacity: .3;
  cursor: not-allowed;
}

.btn-undo:focus-visible,
.btn-stats:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.undo-count {
  background: var(--accent);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
  transition: background .2s;
}

@media (hover: hover) {
  .btn-undo:hover {
    background: var(--surface2);
  }

  .btn-stats:hover {
    background: var(--surface2);
  }
}

/* ── Buttons ──────────────────────────────────────────── */
.btn-row {
  display: flex;
  gap: .5rem;
  width: 100%;
  max-width: 520px;
  flex-wrap: wrap;
}

.btn {
  flex: 1;
  min-height: 44px;
  /* FIX #1: 44px touch target */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: .6rem .75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, transform .08s, box-shadow .12s;
  touch-action: manipulation;
  white-space: nowrap;
  text-decoration: none;
  min-width: 0;
}

.btn:active {
  transform: scale(.96);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (hover: hover) {
  .btn:hover {
    background: var(--surface2);
  }

  .btn.primary:hover {
    background: #7b74ff;
  }

  .btn.challenge:hover {
    background: rgba(67, 217, 162, .22);
  }
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px rgba(108, 99, 255, .35);
}

.btn.primary:active {
  background: #7b74ff;
}

.btn.challenge {
  background: rgba(67, 217, 162, .1);
  border-color: rgba(67, 217, 162, .35);
  color: var(--accent2);
}

.btn.challenge:active {
  background: rgba(67, 217, 162, .2);
}

/* ── Practice banner ──────────────────────────────────── */
.practice-banner {
  width: 100%;
  max-width: 520px;
  display: none;
  flex-direction: column;
  gap: 2px;
  background: rgba(241, 135, 65, .08);
  border: 1px solid rgba(241, 135, 65, .25);
  border-radius: var(--radius);
  padding: .55rem .85rem;
  margin-bottom: .4rem;
  font-size: .75rem;
  line-height: 1.5;
}

.practice-banner.visible {
  display: flex;
}

.pb-badge {
  display: inline-block;
  font-size: .58rem;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--orange);
  background: rgba(241, 135, 65, .15);
  border: 1px solid rgba(241, 135, 65, .3);
  padding: 1px 6px;
  border-radius: 4px;
  margin-bottom: 2px;
  width: fit-content;
}

.pb-text {
  color: var(--text);
  font-size: .78rem;
}

.pb-text strong {
  color: var(--orange);
}

.pb-sub {
  color: var(--muted);
  font-size: .70rem;
}

/* ── Confetti + float layer ───────────────────────────── */
#confetti-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  overflow: visible;
}

.confetti-piece {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  will-change: transform, opacity;
  animation: confettiFly .85s cubic-bezier(.22, .61, .36, 1) forwards;
}

@keyframes confettiFly {
  0% {
    transform: translate(0, 0) rotate(0deg) scale(1);
    opacity: 1;
  }

  100% {
    transform: translate(var(--dx), var(--dy)) rotate(540deg) scale(.3);
    opacity: 0;
  }
}

.score-float {
  position: absolute;
  font-family: var(--font-mono);
  font-size: .85rem;
  font-weight: 500;
  color: var(--accent2);
  pointer-events: none;
  will-change: transform, opacity;
  animation: floatUp .85s ease forwards;
  white-space: nowrap;
  transform: translateX(-50%);
}

@keyframes floatUp {
  0% {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
  }

  100% {
    transform: translateX(-50%) translateY(-48px);
    opacity: 0;
  }
}

/* ── First move burst ─────────────────────────────────── */
.first-move-burst {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-display);
  font-weight: 800;
  color: #FFD166;
  pointer-events: none;
  font-size: clamp(1.1rem, 4vw, 2.2rem);
  max-width: 90vw;
  text-align: center;
  white-space: normal;
  animation: burstUp 1.2s cubic-bezier(.22, .61, .36, 1) forwards;
  z-index: 9999;
  text-shadow: 0 0 20px rgba(255, 209, 102, 0.5);
}

@media (max-width: 480px) {
  .first-move-burst {
    font-size: clamp(1rem, 5vw, 1.6rem);
    padding: 0 12px;
  }
}

@keyframes burstUp {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(.6) translateY(10px);
  }

  30% {
    opacity: 1;
    transform: translateX(-50%) scale(1.15) translateY(-8px);
  }

  70% {
    opacity: 1;
    transform: translateX(-50%) scale(1) translateY(-14px);
  }

  100% {
    opacity: 0;
    transform: translateX(-50%) scale(.9) translateY(-28px);
  }
}

/* ── Toasts ───────────────────────────────────────────── */
#toast,
#combo-toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: .75rem 1.5rem;
  border-radius: 30px;
  font-family: var(--font-body);
  font-size: .95rem;
  font-weight: 600;
  white-space: normal;
  text-align: center;
  max-width: min(420px, calc(100vw - 2.5rem));
  line-height: 1.4;
  opacity: 0;
  transition: opacity .3s ease, transform .3s ease;
  pointer-events: none;
  z-index: 1000;
}

#toast {
  bottom: max(2.5rem, calc(env(safe-area-inset-bottom) + 1rem));
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  box-shadow: 0 4px 20px rgba(0, 0, 0, .3);
}

#combo-toast {
  top: 5rem;
  background: rgba(255, 209, 102, .12);
  border: 1px solid rgba(255, 209, 102, .28);
  color: var(--gold);
  font-size: 1.05rem;
  font-family: var(--font-display);
}

#toast.show,
#combo-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#toast.hiding,
#combo-toast.hiding {
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
  transition: opacity .5s ease, transform .5s ease;
}

/* ── Modals ───────────────────────────────────────────── */
#gameover-screen,
#already-played-screen,
#tutorial-screen,
#stats-screen {
  position: fixed;
  inset: 0;
  /* FIX #10: backdrop-filter with @supports fallback */
  background: rgba(10, 10, 16, .97);
  display: flex;
  align-items: center;
  /* FIX #8: was flex-start which caused iOS scroll issues */
  justify-content: center;
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
  padding:
    max(1.5rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1.5rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  overflow-y: auto;
  overscroll-behavior: contain;
  /* FIX #8 */
}

/* FIX: backdrop-filter only when supported */
@supports (backdrop-filter: blur(1px)) {

  #gameover-screen,
  #already-played-screen,
  #tutorial-screen,
  #stats-screen {
    background: rgba(10, 10, 16, .88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }
}

#gameover-screen.visible,
#already-played-screen.visible,
#tutorial-screen.visible,
#stats-screen.visible {
  opacity: 1;
  pointer-events: all;
}

/* ── Card ─────────────────────────────────────────────── */
.go-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 1.75rem 1.5rem 1.5rem;
  width: min(92vw, 390px);
  text-align: center;
  flex-shrink: 0;
  /* FIX #8: prevent card squishing */
  position: relative;
  box-shadow: var(--shadow-md);
  /* FIX #8: remove margin:auto which conflicted with flex-start */
}

.go-card.slide-in {
  animation: slideUp .32s cubic-bezier(.22, .61, .36, 1);
}

@keyframes slideUp {
  from {
    transform: translateY(36px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: .8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s;
  touch-action: manipulation;
}

/* FIX: hover guard */
@media (hover: hover) {
  .modal-close:hover {
    background: var(--surface3);
    color: var(--text);
  }
}

.modal-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.go-card h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: .25rem;
  letter-spacing: -.02em;
}

.go-card .subtitle {
  color: var(--muted);
  font-size: .8rem;
  margin-bottom: .75rem;
}

.go-tier {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  margin: .2rem 0 .4rem;
  letter-spacing: -.01em;
}

.ap-attempts {
  font-size: .75rem;
  color: var(--muted);
  font-family: var(--font-mono);
  margin-bottom: .6rem;
}

.ap-countdown {
  font-family: var(--font-mono);
  font-size: 2.2rem;
  font-weight: 500;
  letter-spacing: .06em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  margin: .2rem 0 .7rem;
}

.ap-emoji-grid {
  font-size: 1.25rem;
  line-height: 1.7;
  letter-spacing: .05em;
  margin: .6rem 0 .9rem;
  word-break: break-all;
  font-family: 'Segoe UI Emoji', 'Apple Color Emoji', sans-serif;
}

.go-best,
.go-rank,
.go-par {
  font-size: .8rem;
  font-weight: 600;
  padding: .5rem .9rem;
  border-radius: var(--radius);
  margin-bottom: .6rem;
  line-height: 1.45;
}

.go-best {
  background: rgba(255, 209, 102, .1);
  color: var(--gold);
}

.go-rank {
  background: rgba(67, 217, 162, .1);
  color: var(--accent2);
}

.go-par {
  background: rgba(108, 99, 255, .1);
  color: var(--accent);
}

/* ── Go stats ─────────────────────────────────────────── */
.go-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  margin-bottom: .85rem;
}

.go-stat {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: .65rem .4rem;
}

.go-stat .s-label {
  font-size: .58rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.go-stat .s-value {
  font-family: var(--font-mono);
  font-size: 1.22rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

#go-challenge {
  font-size: .82rem;
  font-weight: 600;
  padding: .6rem 1rem;
  background: rgba(108, 99, 255, .1);
  border-radius: var(--radius);
  margin-bottom: .75rem;
  display: none;
  line-height: 1.45;
}

.go-buttons {
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.go-buttons .btn {
  flex: none;
  width: 100%;
  justify-content: center;
}

/* ── Ranked / Practice info ───────────────────────────── */
.go-ranked-info {
  font-size: .78rem;
  font-weight: 500;
  padding: .55rem .9rem;
  border-radius: var(--radius);
  margin-bottom: .6rem;
  line-height: 1.55;
  text-align: left;
}

.go-ranked-info.ranked {
  background: rgba(67, 217, 162, .08);
  border: 1px solid rgba(67, 217, 162, .2);
  color: var(--accent2);
}

.go-ranked-info.practice {
  background: rgba(241, 135, 65, .08);
  border: 1px solid rgba(241, 135, 65, .25);
  color: var(--text);
}

.go-ranked-info.practice .go-practice-badge {
  display: inline-block;
  font-size: .58rem;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--orange);
  background: rgba(241, 135, 65, .15);
  border: 1px solid rgba(241, 135, 65, .3);
  padding: 1px 6px;
  border-radius: 4px;
  margin-right: 4px;
  vertical-align: middle;
}

.go-ranked-info.practice strong {
  color: var(--orange);
}

/* ── Tutorial ─────────────────────────────────────────── */
.tutorial-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 2rem 1.5rem 1.5rem;
  width: min(92vw, 360px);
  text-align: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-md);
}

.tutorial-step {
  transition: opacity .2s;
}

.tutorial-step.hidden {
  display: none;
}

.tutorial-emoji {
  font-size: 2.8rem;
  margin-bottom: .75rem;
}

.tutorial-card h2 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 800;
  margin-bottom: .5rem;
  letter-spacing: -.02em;
}

.tutorial-card p {
  color: var(--muted);
  font-size: .85rem;
  line-height: 1.55;
  margin-bottom: 1rem;
}

.tutorial-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 1rem 0 .75rem;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border2);
  cursor: pointer;
  transition: background .2s, transform .2s;
}

.dot.active {
  background: var(--accent);
  transform: scale(1.3);
}

.tutorial-buttons {
  display: flex;
  gap: .5rem;
}

.tutorial-buttons .btn {
  flex: 1;
}

/* ── Stats screen ─────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  margin: .75rem 0;
}

.stat-item {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: .75rem .4rem;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--accent2);
}

.stat-label {
  font-size: .58rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 4px;
}

.score-dist {
  margin-top: .75rem;
}

.dist-label {
  font-size: .62rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .5rem;
  text-align: left;
}

.dist-bars {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.dist-row {
  display: grid;
  grid-template-columns: 3rem 1fr 2.5rem;
  align-items: center;
  gap: .5rem;
  font-size: .7rem;
}

.dist-tier {
  color: var(--muted);
  text-align: right;
  font-family: var(--font-mono);
  font-size: .65rem;
}

.dist-bar-wrap {
  background: var(--surface2);
  border-radius: 4px;
  height: 12px;
  overflow: hidden;
}

.dist-bar {
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  transition: width .6s cubic-bezier(.22, .61, .36, 1);
  min-width: 2px;
}

.dist-count {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: .65rem;
}

/* ── Weekly summary ───────────────────────────────────── */
.weekly-summary {
  background: linear-gradient(135deg, rgba(255, 209, 102, .12), rgba(255, 99, 132, .08));
  border: 1px solid rgba(255, 209, 102, 0.3);
  border-radius: var(--radius);
  padding: .8rem 1rem;
  margin: .6rem 0;
  text-align: center;
  display: none;
}

.weekly-summary.visible {
  display: block;
}

.weekly-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 800;
  color: #FFD166;
  margin-bottom: .25rem;
}

.weekly-best {
  font-size: .85rem;
  color: var(--text);
}

.weekly-best strong {
  color: #FFD166;
}

.weekly-sub {
  font-size: .72rem;
  color: var(--muted);
  margin-top: .2rem;
}

/* ── Grid freeze ──────────────────────────────────────── */
#grid.frozen {
  opacity: 0.45;
  filter: blur(1.5px) saturate(0.3) brightness(0.8);
  transition: opacity .25s ease, filter .25s ease;
  pointer-events: none;
}

/* ── Drag ghost ───────────────────────────────────────── */
/* Applied via JS inline style — this class is for when drag is active */
body.dragging {
  cursor: grabbing;
  user-select: none;
}

/* Tray slot: show grab cursor when block present */
.tray-slot:not(.empty) {
  cursor: grab;
}

.tray-slot.selected:not(.empty) {
  cursor: grabbing;
}

/* ══════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ══════════════════════════════════════════════════════ */

/* ── Çok küçük: 320px–374.9px ────────────────────────── */
/* FIX #9: was 374px — 374.9px closes the 1px gap */
@media (max-width: 374.9px) {
  :root {
    /* FIX #1: reduce padding to give cells more room */
    --cell-size: clamp(28px, calc((100vw - 48px) / 10), 32px);
    --gap: 2px;
  }

  .app {
    padding-left: .5rem;
    padding-right: .5rem;
  }

  #grid {
    padding: 4px;
  }

  .logo {
    font-size: 1.3rem;
  }

  .puzzle-day {
    display: none;
  }

  .streak-label {
    display: none;
  }

 

  .attempt-badge {
    display: none;
  }

  .streak-badge {
    padding: 4px 7px;
    font-size: .68rem;
  }

  .js-countdown {
    font-size: .75rem;
  }

  .score-card .value {
    font-size: 1.1rem;
  }

  .tray-slot {
    min-height: clamp(64px, 16vw, 80px);
  }

  #combo-toast {
    font-size: .9rem;
  }

  .go-card {
    padding: 1.4rem 1.1rem 1.2rem;
  }

  .go-card h2 {
    font-size: 1.25rem;
  }

  .go-stat .s-value {
    font-size: 1rem;
  }

  .ap-countdown {
    font-size: 1.7rem;
  }

  /* FIX #8: smaller screen — compact game over buttons */
  .go-buttons .btn {
    min-height: 40px;
    padding: .45rem .75rem;
  }

  .go-buttons {
    gap: .3rem;
  }
}

/* ── Küçük: 375px–429px ──────────────────────────────── */
@media (max-width: 429px) and (min-width: 375px) {
  :root {
    --cell-size: clamp(28px, calc((100vw - 56px) / 10), 38px);
  }

  .streak-label {
    display: none;
  }

   .streak-badge {
    padding: 4px 8px;
  }
}

/* ── Orta: 430px–519px ───────────────────────────────── */
@media (max-width: 519px) and (min-width: 430px) {
  :root {
    --cell-size: clamp(30px, calc((100vw - 60px) / 10), 42px);
  }

  .streak-label {
    display: none;
  }
}

/* ── Tablet / Desktop: 700px+ ────────────────────────── */
@media (min-width: 700px) {
  :root {
    --cell-size: 46px;
  }

  .app {
    padding-top: 1.25rem;
  }

  .logo {
    font-size: 1.85rem;
  }

  .puzzle-day {
    font-size: .82rem;
  }

  .streak-badge {
    padding: 5px 10px;
  }

  .streak-label {
    display: inline;
  }

  .next-text {
    display: block;
  }

  .attempt-badge {
    display: block;
  }
}

/* ── Landscape — FIX #5: CSS Grid layout (replaces broken flex-wrap) ─────── */
@media (max-height: 500px) and (orientation: landscape) {
  :root {
    /* cell size based on available height */
    --cell-size: clamp(24px, calc((100vh - 80px) / 10), 36px);
    --gap: 2px;
  }

  .app {
    display: grid;
    grid-template-areas:
      "header  header  header"
      "score   grid    tray"
      "undo    grid    btn";
    grid-template-columns: 100px 1fr 86px;
    grid-template-rows: auto 1fr auto;
    align-items: start;
    gap: .35rem;
    padding:
      max(.4rem, env(safe-area-inset-top)) max(.5rem, env(safe-area-inset-right)) max(.4rem, env(safe-area-inset-bottom)) max(.5rem, env(safe-area-inset-left));
    overflow-y: auto;
    min-height: 100dvh;
  }

  header {
    grid-area: header;
    padding: .15rem 0;
  }

  #practice-banner {
    grid-column: 1 / -1;
  }

  .score-bar {
    grid-area: score;
    flex-direction: column;
    max-width: none;
    gap: .25rem;
    margin-bottom: 0;
  }

  .next-queue-wrap {
    display: none;
  }

  .grid-wrap {
    grid-area: grid;
    margin: 0;
  }

  #grid {
    margin-bottom: 0;
  }

  .tray {
    grid-area: tray;
    flex-direction: column;
    max-width: none;
    gap: .25rem;
    margin-bottom: 0;
  }

  .undo-row {
    grid-area: undo;
    flex-direction: column;
    max-width: none;
    gap: .25rem;
    margin-bottom: 0;
  }

  .btn-row {
    grid-area: btn;
    flex-direction: column;
    max-width: none;
    gap: .25rem;
    flex-wrap: nowrap;
  }

  .tray-slot {
    min-height: 52px;
  }

  .score-card .value {
    font-size: 1rem;
  }

  .streak-label {
    display: none;
  }

  .next-text {
    display: none;
  }

  .attempt-badge {
    display: none;
  }

  /* compact score bar labels in landscape */
  .score-card .label {
    display: none;
  }

  .score-card {
    padding: .3rem .4rem;
  }
}

/* ── Landscape ultra-short (320px height) ─────────────── */
@media (max-height: 420px) and (orientation: landscape) {
  :root {
    --cell-size: clamp(22px, calc((100vh - 65px) / 10), 30px);
  }

  .score-bar {
    max-width: 85px;
  }
}

/* ── Reduced motion ───────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {

  .cell,
  .tray-slot,
  .btn,
  .btn-undo,
  .btn-stats,
  #toast,
  #combo-toast,
  #gameover-screen,
  #already-played-screen,
  #tutorial-screen,
  #stats-screen {
    transition: none !important;
    animation: none !important;
  }

  .cell.clearing {
    animation: none !important;
    opacity: 0;
  }

  .cell.just-placed {
    animation: none !important;
  }

  .confetti-piece {
    animation: none !important;
    display: none;
  }

  .score-float {
    animation: none !important;
    display: none;
  }

  #screen-flash.flash {
    animation: none !important;
  }

  .go-card.slide-in {
    animation: none !important;
  }
}

/* ── High contrast ────────────────────────────────────── */
@media (forced-colors: active) {
  .cell {
    border: 2px solid ButtonText;
  }

  .cell.filled {
    background: Highlight;
  }

  .btn {
    border: 2px solid ButtonText;
  }
}
/* ═══════════════════════════════════════════════════════
   GRIDDLE OWL MASCOT
   ═══════════════════════════════════════════════════════ */

#owl-mascot {
  position: relative;
  flex-shrink: 0;
  /* FIX 1: sabit 52px yerine clamp — küçük ekranda küçülür */
  width: clamp(36px, 6vw, 52px);
  height: clamp(36px, 6vw, 52px);
  cursor: default;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#owl-mascot svg {
  display: block;
  width: 100%;
  height: 100%;
  animation: owlFloat 4s ease-in-out infinite;
  will-change: transform;
  overflow: visible;
}


#owl-speech {
  display: none;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 56px;
  width: max-content;
  max-width: min(200px, calc(100vw - 90px));
  background: var(--surface3);
  border: 1px solid rgba(108, 99, 255, 0.35);
  color: #fbd478;
  text-shadow: 0 0 8px rgba(255, 209, 102, 0.3);
  font-family: var(--font-body);
  font-size: 14.5px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 12px;
  white-space: normal;
  line-height: 1.4;
  word-break: break-word;
  z-index: 500;
  pointer-events: none;
}

#owl-speech::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-right-color: var(--surface3);
}

#owl-speech.owl-show {
  display: block;
  animation: owlBubblePop 0.3s cubic-bezier(.175, .885, .32, 1.275) forwards;
}

/* 375px altı — iPhone SE, küçük Androidler */
@media (max-width: 375px) {
  #owl-speech {
    font-size: 13.5px;
    max-width: calc(100vw - 80px);
    padding: 5px 10px;
  }
}
/* ── Keyframes ─────────────────────────────────────────── */

@keyframes owlFloat {

  0%,
  100% {
    transform: translateY(0px);
  }

  50% {
    transform: translateY(-4px);
  }
}

@keyframes owlBounce {
  0% {
    transform: scale(1) translateY(0);
  }

  35% {
    transform: scale(1.13) translateY(-7px);
  }

  65% {
    transform: scale(0.95) translateY(2px);
  }

  100% {
    transform: scale(1) translateY(0);
  }
}

@keyframes owlCombo {
  0% {
    transform: scale(1) rotate(0deg);
  }

  20% {
    transform: scale(1.2) rotate(-9deg) translateY(-9px);
  }

  45% {
    transform: scale(1.2) rotate(9deg) translateY(-9px);
  }

  70% {
    transform: scale(1.08) rotate(-3deg);
  }

  100% {
    transform: scale(1) rotate(0deg);
  }
}

@keyframes owlSad {
  0% {
    transform: translateY(0) rotate(0deg);
  }

  30% {
    transform: translateY(4px) rotate(-5deg);
  }

  100% {
    transform: translateY(3px) rotate(-3deg);
  }
}

/* YENİ — placeReact() ve nodHead() için */
@keyframes owlNod {
  0% {
    transform: translateY(0) rotate(0deg);
  }

  25% {
    transform: translateY(-4px) rotate(3deg);
  }

  55% {
    transform: translateY(2px) rotate(-2deg);
  }

  80% {
    transform: translateY(-2px) rotate(1deg);
  }

  100% {
    transform: translateY(0) rotate(0deg);
  }
}

/* YENİ — idle çeşitliliği için (baş tilt) */




#owl-head {
transform-box: fill-box;
  transform-origin: center 18px;

  will-change: transform;
}



@keyframes wingFlapLeft {

  0%,
  100% {
    transform: rotate(0deg);
    transform-origin: 17px 30px;
  }

  30% {
    transform: rotate(22deg);
    transform-origin: 17px 30px;
  }

  70% {
    transform: rotate(-6deg);
    transform-origin: 17px 30px;
  }
}

@keyframes wingFlapRight {

  0%,
  100% {
    transform: rotate(0deg);
    transform-origin: 35px 30px;
  }

  30% {
    transform: rotate(-22deg);
    transform-origin: 35px 30px;
  }

  70% {
    transform: rotate(6deg);
    transform-origin: 35px 30px;
  }
}

@keyframes owlBubblePop {
  from {
    transform: translateY(-50%) scale(0.65);
    opacity: 0;
  }

  to {
    transform: translateY(-50%) scale(1);
    opacity: 1;
  }
}

/* ── Responsive ────────────────────────────────────────── */


@media (max-width: 480px) {
  #owl-speech {
    top: calc(100% + 8px);
    left: 0;
    max-width: min(180px, calc(100vw - 24px));
    font-size: 13px;
    padding: 5px 10px;
  }

  #owl-speech::before {
    left: 10px;
    top: -8px;
    transform: none;
    border-right-color: transparent;
    border-bottom-color: var(--surface3);
  }
}


@media (max-width: 374.9px) {
  #owl-speech {
    display: none !important;
  }
}


@media (max-height: 500px) and (orientation: landscape) {
  #owl-mascot {
    display: none;
  }
}


@media (prefers-reduced-motion: reduce) {
  #owl-mascot svg {
    animation: none !important;
  }

  #owl-speech.owl-show {
    animation: none !important;
  }
}
