/*
 * Block Drop — neo-brutalist skin matching the SourceStrongAI marketing
 * site: paper ground, ink borders, hard offset shadows, brand orange.
 * Mobile-first; the playfield scales to fit any viewport without scrolling.
 */

:root {
  --paper: #f4f0ec;
  --card: #fdfaf4;
  --ink: #1a1a1a;
  --ink2: #555;
  --orange: #ff5e00;
  --orange-text: #c2410c; /* AA-safe orange for text on paper */
  --gold: #ffc432;
  --shadow: 4px 4px 0 var(--ink);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--paper);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100svh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

main#main {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 760px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  z-index: 50;
}
.skip-link:focus {
  left: 0;
}

.noscript-card {
  max-width: 420px;
  margin: 18vh auto 0;
  padding: 22px;
  background: var(--card);
  border: 2px solid var(--ink);
  box-shadow: var(--shadow);
  line-height: 1.55;
}
.noscript-card a {
  color: var(--orange-text);
}
.noscript-title {
  margin-top: 0;
  font-size: 1.15rem;
}

.mini-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px calc(16px + env(safe-area-inset-right, 0px)) 8px
    calc(16px + env(safe-area-inset-left, 0px));
}
.brand-link {
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
}
.brand-link .accent {
  color: var(--orange-text);
}
.more-games {
  color: var(--ink2);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 700;
}
.more-games:hover {
  color: var(--orange-text);
}

/* ---------- layout ---------- */

#screen-game {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 4px 12px;
  width: 100%;
  max-width: 760px;
  justify-content: center;
}

#board-wrap {
  position: relative;
  flex: 0 0 auto;
  border: 3px solid var(--ink);
  box-shadow: 5px 5px 0 var(--ink);
  background: #fdfaf4;
  line-height: 0;
}

#board {
  display: block;
  touch-action: none;
}

#side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 148px;
}

.panel {
  background: var(--card);
  border: 2.5px solid var(--ink);
  box-shadow: var(--shadow);
  padding: 10px 12px;
}
.panel-title {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
#next {
  display: block;
  margin: 0 auto;
  width: 96px;
  height: 96px;
}

.stat-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
}
.stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.stat span {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink2);
}
.stat b {
  font-size: 1.05rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.side-btns {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-secondary {
  border: 2px solid var(--ink);
  background: var(--card);
  box-shadow: 3px 3px 0 var(--ink);
  padding: 10px 12px;
  font-weight: 800;
  font-size: 0.88rem;
  cursor: pointer;
  transition:
    transform 0.08s ease-out,
    box-shadow 0.08s ease-out;
  touch-action: manipulation;
}
.btn-secondary:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.btn-primary {
  border: none;
  background: var(--orange);
  color: #fff;
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  padding: 15px 44px;
  cursor: pointer;
  box-shadow: 5px 5px 0 var(--ink);
  transition:
    transform 0.08s ease-out,
    box-shadow 0.08s ease-out;
  touch-action: manipulation;
}
.btn-primary:active {
  transform: translate(3px, 3px);
  box-shadow: 2px 2px 0 var(--ink);
}

/* ---------- overlay (start / pause / game over) ---------- */

#overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(244, 240, 236, 0.92);
  line-height: 1.4;
}
#overlay.hidden,
.ov-stats.hidden {
  display: none;
}
.overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
  text-align: center;
}
.ov-title {
  margin: 0;
  font-size: clamp(2.2rem, 11vw, 3.4rem);
  line-height: 0.95;
  font-weight: 900;
  letter-spacing: 0.02em;
}
.ov-title .accent {
  color: var(--orange-text);
}
.ov-sub {
  margin: 0;
  color: var(--ink2);
  font-weight: 600;
  font-size: 0.95rem;
}
.ov-sub.newbest {
  color: var(--ink);
  background: linear-gradient(90deg, var(--gold), #ffe9a8, var(--gold));
  padding: 6px 14px;
  border-radius: 99px;
  font-weight: 900;
  letter-spacing: 0.08em;
}
.ov-stats {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 6px 22px;
  background: var(--card);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  padding: 12px 18px;
}
.ov-stats div {
  display: contents;
}
.ov-stats dt {
  grid-row: 1;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink2);
}
.ov-stats dd {
  grid-row: 2;
  margin: 0;
  font-size: 1.3rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.hint-line {
  margin: 2px 0 0;
  font-size: 0.74rem;
  color: var(--ink2);
  opacity: 0.85;
  max-width: 260px;
}

/* ---------- touch controls ---------- */

#touch-controls {
  display: none;
  gap: 10px;
  padding: 12px calc(10px + env(safe-area-inset-right, 0px))
    calc(6px + env(safe-area-inset-bottom, 0px)) calc(10px + env(safe-area-inset-left, 0px));
}
.tc-btn {
  flex: 1 1 58px;
  min-width: 0;
  max-width: 84px;
  min-height: 58px;
  border: 2.5px solid var(--ink);
  background: var(--card);
  box-shadow: 4px 4px 0 var(--ink);
  border-radius: 12px;
  font-size: 1.35rem;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.tc-btn:active,
.tc-btn.pressed {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 var(--ink);
  background: #fff3e6;
}
.tc-accent {
  background: var(--orange);
  color: #fff;
}
@media (pointer: coarse) {
  #touch-controls {
    display: flex;
  }
}

.mini-footer {
  margin-top: auto;
  padding: 14px 0 16px;
  display: flex;
  gap: 10px;
  color: var(--ink2);
  font-size: 0.85rem;
}
.mini-footer a {
  color: var(--ink2);
  text-decoration: none;
}
.mini-footer a:hover {
  color: var(--orange-text);
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 2px;
}

/* landscape phones: compact the side panel + overlay so the touch bar and
   the whole play area fit the short viewport without scrolling */
@media (min-width: 521px) and (max-height: 500px) {
  .mini-footer {
    display: none;
  }
  .panel:first-child {
    display: none;
  }
  .stat-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px 12px;
    padding: 8px 10px;
  }
  .stat b {
    font-size: 0.9rem;
  }
  .side-btns {
    flex-direction: row;
  }
  .btn-secondary {
    padding: 8px 8px;
    font-size: 0.78rem;
  }
  .ov-title {
    font-size: clamp(1.5rem, 9vh, 2.2rem);
  }
  .overlay-inner {
    gap: 8px;
    padding: 8px;
  }
  .btn-primary {
    padding: 12px 22px;
    font-size: 1.05rem;
  }
  .hint-line {
    display: none;
  }
  .ov-stats dd {
    font-size: 1.05rem;
  }
}

/* narrow phones: stack the side panel under the board as a compact row */
@media (max-width: 520px) {
  .mini-footer {
    display: none; /* header already carries More free games */
  }
  #screen-game {
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }
  .stat b {
    font-size: 0.95rem;
  }
  #side {
    width: 100%;
    max-width: 340px;
    flex-direction: row;
    align-items: stretch;
  }
  .panel:first-child {
    display: none; /* next preview hides on phones; board space wins */
  }
  .stat-panel {
    flex: 1;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px 14px;
  }
  .stat {
    min-width: 0;
  }
  .side-btns {
    flex-direction: column;
    justify-content: center;
    gap: 8px;
  }
  .btn-secondary {
    padding: 8px 10px;
    font-size: 0.8rem;
  }
  .mini-header {
    padding-top: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
  }
}
