* {
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
}

/* Prevent double-tap zoom and remove the 300ms tap delay on all
   interactive elements. iOS ignores user-scalable=no since iOS 10,
   so this CSS approach is the only reliable cross-browser fix. */
button, .grid-box {
  touch-action: manipulation;
}

body {
  /* 100dvh fills the *actual* visible area, adjusting as the browser
     URL bar appears/disappears — much better than 100vh on mobile. */
  height: 100vh;        /* fallback for older browsers */
  height: 100dvh;
  /* In standalone (home screen) mode iOS doesn't provide the URL bar buffer,
     so content starts under the status bar. env(safe-area-inset-top) is ~0
     in Safari browser mode and ~44–50px in standalone mode. */
  padding-top: env(safe-area-inset-top);
  /* Prevent horizontal rubber-band bounce only.
     Allowing vertical overscroll lets iOS Safari dismiss its URL bar. */
  overflow-x: hidden;
  overscroll-behavior-x: none;
  font-family: 'Inter', sans-serif;
}

/* ---- Animations ---- */
.pop {
  animation: pop 0.1s ease-in-out;
}
@keyframes pop {
  50% { transform: scale(1.1); }
}

.shake {
  animation: shake 0.4s ease-in-out;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

.row-checking > .grid-box {
  animation: checking 0.7s ease-in-out infinite;
}
@keyframes checking {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.flip-anim {
  animation: flip-anim 0.6s ease-in-out forwards;
}
@keyframes flip-anim {
  0%   { transform: rotateX(0); }
  50%  { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

/* ---- Grid boxes ---- */
/* clamp() makes boxes shrink on narrow phones so the 7-letter row
   never overflows, while growing nicely on wider screens/tablets.   */
.grid-box {
  width:     clamp(2.2rem, 10.5vw, 3.25rem);
  height:    clamp(2.2rem, 10.5vw, 3.25rem);
  font-size: clamp(0.85rem, 4vw, 1.5rem);
  transition: all 0.2s;
  flex-shrink: 0;
  text-align: center;
}

.box-active {
  border-color: #1e40af !important;
  border-width: 3px !important;
}

/* ---- Row states ---- */
.row-inactive {
  opacity: 0.4;
  pointer-events: none;
}

.row-inactive .grid-box {
  background-color: #f1f5f9;
}

/* Middle rows before both anchors are confirmed — squished outline placeholders */
.row-pending {
  pointer-events: none;
  opacity: 1 !important; /* override row-inactive so border stays visible */
}

.row-pending .grid-box {
  height: 0.5rem !important;      /* desktop default — noticeable but subtle */
  min-height: 0 !important;
  font-size: 0 !important;
  background-color: transparent !important;
  border-color: #cbd5e1 !important;
  border-width: 1.5px !important;
  border-radius: 3px !important;
  transition: none !important;
}

/* Extra squish on small screens */
@media (max-width: 639px) {
  .row-pending .grid-box {
    height: 0.3rem !important;
  }
}

/* Expand animation when anchors are confirmed — starts from whatever squished
   height the element currently has, so it works at any screen size. */
@keyframes grid-box-expand {
  to {
    height: clamp(2.2rem, 10.5vw, 3.25rem);
    font-size: clamp(0.85rem, 4vw, 1.5rem);
    opacity: 1;
  }
}

.row-expanding .grid-box {
  animation: grid-box-expand 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@media (hover: hover) {
  .row-clickable .grid-box:hover {
    background-color: #f8fafc;
    cursor: pointer;
  }
}

.row-clickable .grid-box:active {
  opacity: 0.7;
}

/* ---- Loader spinner ---- */
.loader {
  border: 4px solid #f3f3f3;
  border-top: 4px solid #3b82f6;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Hint button idle nudge */
.hint-jiggle {
  animation: hint-jiggle 0.5s ease-in-out;
  transition: none !important;
}
@keyframes hint-jiggle {
  0%   { transform: rotate(0deg); }
  20%  { transform: rotate(-12deg); }
  40%  { transform: rotate(12deg); }
  60%  { transform: rotate(-8deg); }
  80%  { transform: rotate(8deg); }
  100% { transform: rotate(0deg); }
}
