/*
 * Cross Math — equation crossword styling.
 * Warm paper + ink, matching the SourceStrongAI brand; the board is a
 * 6×7 CSS grid: digit cells, operator chips, equals, and margin targets.
 */

:root {
  --paper: #f4f0ec;
  --card: #fdfaf4;
  --ink: #1a1a1a;
  --ink2: #6b6156;
  --orange: #ff5e00;
  --orange-text: #c2410c;
  --orange-ring: #d94f00;
  --teal: #0e9f8c;
  --red: #d7263d;
  --gold: #ffc432;
}

* {
  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;
  color: var(--ink);
  background:
    radial-gradient(700px 420px at 110% -5%, rgba(255, 196, 50, 0.22), transparent 60%),
    radial-gradient(600px 400px at -10% 20%, rgba(255, 94, 0, 0.1), transparent 55%), var(--paper);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100svh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

#fx-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 40;
}

.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: #fff;
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 rgba(26, 26, 26, 0.9);
  line-height: 1.55;
}
.noscript-card a {
  color: var(--orange-text);
}
.noscript-title {
  margin-top: 0;
}

.mini-header {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 4px 10px;
  padding: 14px 16px 6px;
}
.brand-link {
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
}
.brand-link .accent {
  color: var(--orange-text);
}
.mini-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.more-games {
  color: var(--ink2);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}
.more-games:hover {
  color: var(--orange-text);
}

.chip-btn {
  min-height: 44px;
  padding: 0 13px;
  border: 2px solid var(--ink);
  border-radius: 99px;
  background: #fff;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.game-title {
  margin: 8px 0 0;
  font-size: clamp(1.7rem, 7vw, 2.4rem);
  font-weight: 900;
  letter-spacing: 0.02em;
}
.game-title .accent {
  color: var(--orange-text);
}

.topbar {
  width: 100%;
  max-width: 720px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 0 16px;
}
.seg {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 12px;
  box-shadow: 3px 3px 0 rgba(26, 26, 26, 0.9);
}
.seg button {
  min-height: 44px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  opacity: 0.6;
  font-size: 0.85rem;
  font-weight: 800;
  padding: 0 14px;
  cursor: pointer;
  touch-action: manipulation;
}
.seg button[aria-checked='true'] {
  background: var(--orange);
  color: #1a1a1a;
  opacity: 1;
}

.hud {
  width: 100%;
  max-width: 560px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px 16px 4px;
}
@media (max-width: 430px) {
  .hud {
    grid-template-columns: repeat(2, 1fr);
  }
}
.hud-item {
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 12px;
  box-shadow: 3px 3px 0 rgba(26, 26, 26, 0.9);
  padding: 7px 10px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.hud-item span {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink2);
}
.hud-item b {
  font-size: 0.98rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

/* ---------- puzzle board: 6 rows × 7 cols ---------- */

.puzzle {
  display: grid;
  grid-template-columns: repeat(7, auto);
  gap: 6px;
  margin: 14px auto 0;
  padding: 14px;
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 5px 5px 0 rgba(26, 26, 26, 0.9);
  width: fit-content;
}

.tile {
  appearance: none;
  font-family: inherit;
  padding: 0;
  width: clamp(48px, 12vw, 64px);
  height: clamp(48px, 12vw, 64px);
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  display: grid;
  place-items: center;
  font-size: clamp(1.3rem, 5.5vw, 1.7rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition:
    transform 0.08s ease-out,
    background 0.12s ease-out;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.tile:active {
  transform: scale(0.95);
}
.tile.sel {
  background: #fff3e6;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(255, 94, 0, 0.35);
}
.tile.filled {
  background: #fff;
}
.tile.bad {
  background: #ffe1e1;
  border-color: var(--red);
  animation: shake 0.4s ease-out;
}
@keyframes shake {
  20%,
  60% {
    translate: -5px 0;
  }
  40%,
  80% {
    translate: 5px 0;
  }
}

.op {
  align-self: center;
  justify-self: center;
  min-width: 30px;
  height: 30px;
  border-radius: 99px;
  background: var(--ink);
  color: var(--paper);
  display: grid;
  place-items: center;
  font-size: 1rem;
  font-weight: 900;
}
.op.eq {
  background: var(--orange-text);
  color: #fff;
  min-width: 34px;
}
.op.vop {
  background: #3d3d3d;
}

.target {
  align-self: center;
  justify-self: center;
  min-width: clamp(44px, 11vw, 58px);
  height: clamp(44px, 11vw, 58px);
  border: 2.5px dashed var(--ink);
  border-radius: 12px;
  background: #fff8ec;
  display: grid;
  place-items: center;
  font-size: clamp(1.1rem, 4.5vw, 1.4rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--orange-text);
}
.gap {
  width: 6px;
  height: 6px;
}

.puzzle-msg {
  min-height: 1.3em;
  margin: 10px 16px 0;
  text-align: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--red);
}

/* ---------- digit pad ---------- */

.pad-wrap {
  display: flex;
  justify-content: center;
  width: 100%;
  padding: 10px 12px 0;
}
.pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: min(100%, 336px);
}
.key {
  min-height: 52px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  box-shadow: 3px 3px 0 rgba(26, 26, 26, 0.9);
  font-size: 1.3rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    transform 0.08s ease-out,
    box-shadow 0.08s ease-out;
}
.key:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 rgba(26, 26, 26, 0.9);
}
.key:disabled {
  opacity: 0.3;
  box-shadow: none;
  cursor: not-allowed;
}
.key-clear {
  color: var(--red);
  font-size: 1.1rem;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 16px;
  padding: 0 16px;
}
.btn-primary {
  border: none;
  background: var(--orange);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: 0.03em;
  padding: 14px 30px;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 4px 4px 0 rgba(26, 26, 26, 0.9);
  transition:
    transform 0.08s ease-out,
    box-shadow 0.08s ease-out;
  touch-action: manipulation;
}
.btn-primary:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 rgba(26, 26, 26, 0.9);
}
.btn-secondary {
  border: 2px solid var(--ink);
  background: #fff;
  box-shadow: 3px 3px 0 rgba(26, 26, 26, 0.9);
  padding: 12px 18px;
  min-height: 44px;
  font-weight: 800;
  font-size: 0.88rem;
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn-secondary:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 rgba(26, 26, 26, 0.9);
}
.btn-secondary:disabled {
  opacity: 0.4;
}

.hint-line {
  color: var(--ink2);
  font-size: 0.82rem;
  text-align: center;
  padding: 0 16px;
}

.mini-footer {
  margin-top: auto;
  padding: 18px 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);
}

/* ---------- win banner ---------- */

.hidden {
  display: none !important;
}
.win-banner {
  position: fixed;
  inset: auto 0 calc(env(safe-area-inset-bottom, 0px) + 14px);
  display: flex;
  justify-content: center;
  z-index: 30;
  pointer-events: none;
}
.win-inner {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: 6px 6px 0 rgba(26, 26, 26, 0.9);
  padding: 16px 26px 18px;
  animation: winIn 0.45s cubic-bezier(0.22, 1.4, 0.36, 1);
}
@keyframes winIn {
  from {
    transform: translateY(30px) scale(0.92);
    opacity: 0;
  }
}
.win-emoji {
  font-size: 2rem;
}
.win-title {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 900;
}
.win-line {
  margin: 0;
  color: var(--ink2);
  font-weight: 600;
  font-size: 0.95rem;
}
.win-best {
  margin: 0;
  font-weight: 900;
  letter-spacing: 0.12em;
  font-size: 0.85rem;
  background: linear-gradient(90deg, var(--gold), #ffe9a8, var(--gold));
  padding: 4px 14px;
  border-radius: 99px;
}

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

@media (max-width: 360px) {
  .puzzle {
    gap: 4px;
    padding: 10px;
  }
  .tile {
    width: 44px;
    height: 44px;
    font-size: 1.15rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile.bad,
  .win-inner {
    animation: none;
  }
  * {
    transition-duration: 0.01ms !important;
  }
}
