/* =====================================================================
   SagaxIQ Zip Path Challenge: complete game-page stylesheet
   Replace the ENTIRE contents of iqgames/css/zip-game.css with this file.
   Mobile-first. Header (Home | Level + Difficulty | Timer) stays on ONE row
   at every width. Header, board, hint and buttons share one column width.
   ===================================================================== */

:root {
  --sagax-navy: #073477;
  --sagax-navy-deep: #05285e;
  --sagax-blue: #0d4b98;
  --sagax-orange: #ff9a3c;
  --sagax-coral: #ff654f;
  --sagax-ink: #17243b;
  --sagax-muted: #687790;
  --sagax-line: #e1e8f3;
}

/* Page background (only on pages that contain the game) */
body:has(#zipGame) {
  background:
    radial-gradient(ellipse at 0% 20%, rgba(0, 190, 220, .28) 0%, transparent 42%),
    radial-gradient(ellipse at 100% 100%, rgba(0, 220, 190, .30) 0%, transparent 40%),
    linear-gradient(135deg, #031b40 0%, #05265a 50%, #003b60 100%);
  background-attachment: fixed;
}

/* ---------- Layout column ---------- */
.zg, .zg *, .zg *::before, .zg *::after { box-sizing: border-box; }

.zg {
  --vh: 1vh;
  /* Width of the board frame: as large as fits the screen HEIGHT as well as the width.
     300px is the space used by the site navbar + header + hint + buttons. */
  --bw: min(100%, 560px, max(260px, calc(100 * var(--vh) - 300px)));
  /* Header / hint / buttons never get narrower than 360px (or the screen) */
  --cw: max(var(--bw), min(100%, 360px));

  position: relative;
  width: min(100%, 620px);
  margin: 0 auto;
  padding: 12px 10px calc(22px + env(safe-area-inset-bottom, 0px));
  color: var(--sagax-ink);
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  overflow-x: clip;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
@supports (height: 1dvh) { .zg { --vh: 1dvh; } }

/* ---------- Top bar: Home | Level + Difficulty | Timer (always one row) ---------- */
.zg-top {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: none;                 /* cancels any older "two-row" layout */
  align-items: center;
  gap: 6px;
  width: var(--cw);
  margin: 0 auto 10px;
  padding: 8px;
  border: 1px solid rgba(225, 232, 243, .95);
  border-radius: 16px;
  background: rgba(255, 255, 255, .9);
  box-shadow: 0 8px 26px rgba(5, 40, 94, .08);
}
.zg-top > .zg-btn { grid-area: auto; justify-self: start; min-height: 36px; padding: 0 12px; font-size: 12px; }

.zg-info {
  grid-area: auto;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
}
.zg-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 1 auto;
  min-width: 0;
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid var(--sagax-line);
  border-radius: 999px;
  background: #f4f7fc;
  color: var(--sagax-navy);
  font-weight: 900;
  font-size: clamp(10.5px, 3.1vw, 13px);
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.zg-diff { color: #d9503c; background: #fff2ed; border-color: #ffd8cd; }

.zg-timer {
  grid-area: auto;
  justify-self: end;
  min-width: 54px;
  padding: 7px 8px;
  border-radius: 10px;
  background: var(--sagax-navy);
  color: #fff;
  font-weight: 900;
  font-size: 14px;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 5px 12px rgba(7, 52, 119, .18);
}

/* ---------- Buttons ---------- */
.zg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  font: 800 13px/1.1 "Nunito", "Segoe UI", system-ui, sans-serif;
  text-decoration: none;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease, border-color .18s ease;
}
.zg-btn:hover { transform: translateY(-2px); }
.zg-btn:active { transform: translateY(0); }
.zg-btn:focus-visible { outline: 3px solid #75aaff; outline-offset: 3px; }
.zg-btn:disabled { opacity: .42; cursor: not-allowed; transform: none; }

.zg-btn-soft { color: var(--sagax-navy); background: #fff; border-color: #dce5f2; box-shadow: 0 3px 9px rgba(5, 40, 94, .05); }
.zg-btn-soft:hover { background: #f2f6fd; border-color: #b9cce7; box-shadow: 0 6px 14px rgba(5, 40, 94, .1); }

.zg-btn-primary { color: #fff; background: linear-gradient(110deg, var(--sagax-orange), var(--sagax-coral)); font-size: 1rem; box-shadow: 0 9px 20px rgba(255, 101, 79, .25); }
.zg-btn-primary:hover { box-shadow: 0 12px 24px rgba(255, 101, 79, .34); }

.zg-btn-hint { color: #fff; background: linear-gradient(110deg, #ffb21f, var(--sagax-orange)); box-shadow: 0 6px 14px rgba(255, 154, 60, .28); }
.zg-btn-hint:hover { box-shadow: 0 9px 18px rgba(255, 154, 60, .4); }

/* ---------- Board ---------- */
.zg-boardwrap {
  width: var(--bw);
  margin: 0 auto;
  padding: 8px;
  border: 1px solid rgba(220, 229, 242, .9);
  border-radius: 20px;
  background: linear-gradient(145deg, rgba(255, 255, 255, .97), rgba(247, 249, 254, .97));
  box-shadow: 0 18px 45px rgba(5, 40, 94, .14), inset 0 1px 0 #fff;
}
.zg-board {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  background: #fff;
  border: 2px solid #f5d7ce;
  border-radius: 14px;
  overflow: hidden;
  touch-action: none;           /* lets the finger draw without scrolling the page */
  cursor: pointer;
  box-shadow: 0 5px 18px rgba(23, 36, 59, .07);
}
.zg-board .fx { animation: zgflash .4s ease-out forwards; pointer-events: none; }
.zg-board .next-ring { animation: zgpulse 1.2s ease-in-out infinite; }
.zg-board .visited-number { fill: #073477 !important; }
@keyframes zgflash { from { opacity: .55; } to { opacity: 0; } }
@keyframes zgpulse { 50% { stroke-opacity: .25; } }

/* ---------- Hint text ---------- */
.zg-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--cw);
  min-height: 40px;
  margin: 10px auto;
  padding: 8px 12px;
  border: 1px solid #e0e8f5;
  border-radius: 12px;
  background: rgba(255, 255, 255, .88);
  color: var(--sagax-muted);
  font-size: 12.5px;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
  overflow-wrap: anywhere;
}
.zg-hint.err { color: #b9382a; background: #fff0ed; border-color: #ffd2c9; }

/* ---------- Controls: Undo | Hint | Clear | Restart on ONE row ---------- */
.zg-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  width: var(--cw);
  margin: 0 auto;
}
.zg-controls .zg-btn { width: 100%; min-width: 0; padding: 0 2px; font-size: clamp(11px, 3.2vw, 13px); }

/* ---------- Popup toast ---------- */
.zg-toast {
  position: fixed;
  top: 84px;
  left: 50%;
  z-index: 1100;
  width: max-content;
  max-width: calc(100vw - 28px);
  padding: 11px 18px;
  border: 2px solid #ffd2c9;
  border-radius: 16px;
  background: #fff0ed;
  color: #b9382a;
  font: 900 14px/1.3 "Nunito", "Segoe UI", system-ui, sans-serif;
  text-align: center;
  transform: translateX(-50%);
  box-shadow: 0 14px 34px rgba(2, 21, 52, .3);
  animation: zgtoastin .28s cubic-bezier(.2, 1.25, .4, 1);
  pointer-events: none;
}
.zg-toast[hidden] { display: none; }
.zg-toast.out { opacity: 0; transition: opacity .3s ease; }
@keyframes zgtoastin {
  from { transform: translate(-50%, -12px) scale(.9); opacity: 0; }
  to   { transform: translate(-50%, 0) scale(1); opacity: 1; }
}

/* ---------- Victory dialog ---------- */
.zg-result {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(5, 24, 55, .6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: zgfade .22s ease-out;
}
.zg-result[hidden] { display: none; }
@keyframes zgfade { from { opacity: 0; } to { opacity: 1; } }

.zg-card {
  position: relative;
  width: min(100%, 440px);
  max-height: calc(100 * var(--vh) - 28px);
  overflow: auto;
  padding: 24px 16px 18px;
  border-radius: 22px;
  background: #fff;
  text-align: center;
  box-shadow: 0 28px 80px rgba(2, 21, 52, .3);
  animation: zgpop .36s cubic-bezier(.2, 1.25, .4, 1);
}
.zg-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 7px;
  background: linear-gradient(90deg, var(--sagax-navy), #2871c9, var(--sagax-orange), var(--sagax-coral));
}
@keyframes zgpop { from { transform: translateY(12px) scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }

.zg-card h2 { margin: 6px 0 4px; color: var(--sagax-coral); font-size: clamp(20px, 6vw, 28px); line-height: 1.15; font-weight: 900; letter-spacing: -.02em; }
.zg-reslevel { margin: 0 0 6px; color: var(--sagax-muted); font-weight: 900; }
.zg-resfinal { margin: 8px 0 10px; color: var(--sagax-muted); font-weight: 700; line-height: 1.5; font-size: .92rem; }

.zg-stars { min-height: 44px; color: #ffb21f; font-size: 2.1rem; letter-spacing: 5px; }
.zg-stars .off { color: #e3e9f2; }
.zg-stars span { display: inline-block; animation: zgstar .5s both; }
.zg-stars span:nth-child(2) { animation-delay: .13s; }
.zg-stars span:nth-child(3) { animation-delay: .26s; }
@keyframes zgstar { from { transform: scale(0) rotate(-70deg); opacity: .2; } to { transform: none; opacity: 1; } }

.zg-stats { display: flex; gap: 10px; margin: 14px 0 18px; }
.zg-stats div { flex: 1; min-width: 0; padding: 11px 8px; border: 1px solid #e8edf6; border-radius: 15px; background: linear-gradient(145deg, #f7f9fd, #f0f4fb); }
.zg-stats dt { margin-bottom: 2px; color: var(--sagax-muted); font-size: .78rem; font-weight: 800; }
.zg-stats dd { margin: 0; color: var(--sagax-navy-deep); font-size: 1.45rem; font-weight: 900; font-variant-numeric: tabular-nums; }

.zg-resbtns { display: flex; gap: 10px; }
.zg-resbtns .zg-btn { flex: 1; min-width: 0; min-height: 46px; padding: 0 10px; font-size: .95rem; }

/* =====================================================================
   Larger screens
   ===================================================================== */
@media (min-width: 481px) {
  .zg { padding-top: 16px; }
  .zg-top { gap: 10px; padding: 10px 14px; margin-bottom: 12px; border-radius: 18px; }
  .zg-top > .zg-btn { min-height: 40px; padding: 0 20px; font-size: 14px; }
  .zg-info { gap: 8px; }
  .zg-pill { min-height: 36px; padding: 0 14px; font-size: 14.5px; }
  .zg-timer { min-width: 72px; padding: 8px 12px; font-size: 18px; border-radius: 12px; }

  .zg-boardwrap { padding: 12px; border-radius: 26px; }
  .zg-board { border-radius: 18px; }

  .zg-hint { min-height: 46px; margin: 12px auto; font-size: 14.5px; }
  .zg-controls { gap: 10px; }
  .zg-controls .zg-btn { min-height: 46px; font-size: 14.5px; }
  .zg-toast { top: 96px; padding: 14px 26px; font-size: 1.1rem; }

  .zg-card { padding: 28px 26px 24px; border-radius: 28px; }
  .zg-stats { gap: 12px; }
}

/* Short laptop screens: tighten vertical spacing so no scrolling is needed */
@media (min-width: 481px) and (max-height: 820px) {
  .zg { padding-top: 8px; padding-bottom: 12px; }
  .zg-top { padding: 6px 12px; margin-bottom: 8px; }
  .zg-boardwrap { padding: 8px; }
  .zg-hint { min-height: 38px; margin: 8px auto; padding: 6px 12px; }
  .zg-controls .zg-btn { min-height: 40px; }
}

/* Very narrow phones (320px) */
@media (max-width: 350px) {
  .zg { padding-left: 6px; padding-right: 6px; }
  .zg-top { gap: 4px; padding: 6px; }
  .zg-top > .zg-btn { padding: 0 9px; font-size: 11px; min-height: 34px; }
  .zg-pill { padding: 0 6px; font-size: 10px; min-height: 28px; }
  .zg-timer { min-width: 46px; padding: 6px 5px; font-size: 12.5px; }
  .zg-controls { gap: 4px; }
  .zg-controls .zg-btn { font-size: 10.5px; letter-spacing: -.2px; }
}

@media (prefers-reduced-motion: reduce) {
  .zg *, .zg *::before, .zg *::after { animation: none !important; transition: none !important; }
}
