/* Matrix Analysis — "Glass Lab" interactive board.
   Apple-glass aesthetic: frosted depth, spring motion, lotto-ball heroes. */

#view-analysis { position: relative; }

.an-bar { display: flex; align-items: flex-end; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.an-bar label {
  color: #475569;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--display, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}
.an-bar select {
  background: #ffffff;
  border: 1px solid #cfd8e6;
  border-radius: 6px;
  color: var(--ink, #172033);
  font-family: var(--display, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
  font-size: 14px;
  font-weight: 700;
  min-height: 40px;
  min-width: 150px;
  padding: 8px 12px;
  -webkit-text-fill-color: var(--ink, #172033);
}
.an-bar select option {
  background: #ffffff;
  color: var(--ink, #172033);
}
.an-bar select:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}
.an-bar select:focus-visible {
  outline: 2px solid rgba(37, 99, 235, 0.55);
  outline-offset: 2px;
}
.an-hint { color: #475569; font-size: 12px; margin-left: auto; }

/* The board: a calm dark field the balls float on */
.an-stage {
  position: relative; min-height: 520px;
  border-radius: 22px; overflow: visible;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(80,110,170,.18), transparent 60%),
    linear-gradient(180deg, #0d1220 0%, #0a0e18 100%);
  border: 1px solid rgba(255,255,255,.06);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05);
  padding: 26px 22px 90px;
}

/* scrollable grid — both axes, styled scrollbars always visible */
.an-grid {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 60vh;
  padding-bottom: 8px;
  border-radius: 12px;
}
/* always-visible styled scrollbars (webkit) */
.an-grid::-webkit-scrollbar { width: 10px; height: 10px; }
.an-grid::-webkit-scrollbar-track { background: rgba(255,255,255,.04); border-radius: 8px; }
.an-grid::-webkit-scrollbar-thumb { background: rgba(255,255,255,.28); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
.an-grid::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.45); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
.an-grid::-webkit-scrollbar-corner { background: transparent; }
/* Firefox */
.an-grid { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.28) rgba(255,255,255,.04); }

/* rows size to their content so the scroller engages instead of clipping */
.an-colhead, .an-row { width: max-content; min-width: 100%; }

.an-colhead { display: flex; gap: 8px; padding: 0 4px 6px; }
.an-colhead .an-col-label {
  width: var(--an-cell, 54px); flex: 0 0 var(--an-cell, 54px); text-align: center;
  color: #7f8aa0; font-size: 13px; font-weight: 700; letter-spacing: .04em;
  transition: color .3s, transform .3s;
}
.an-colhead .an-col-label.is-active { color: #ffd34d; transform: translateY(-2px); }

/* Date column at the left of every row */
.an-datecol {
  width: 96px; flex: 0 0 96px; text-align: left;
  color: #8893a6; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
  display: flex; align-items: center; padding-left: 2px; white-space: nowrap;
}
.an-datehead { color: #7f8aa0; font-weight: 700; letter-spacing: .04em; }

/* rows — compact data-grid spacing, best practice: 36-40px rows, 4-6px gap */
.an-rows { display: flex; flex-direction: column; gap: 4px; }
.an-row { display: flex; gap: 8px; align-items: center; min-height: var(--an-cell, 44px); }
.an-cell { width: var(--an-cell, 54px); flex: 0 0 var(--an-cell, 54px); height: var(--an-cell, 44px); display: flex; align-items: center; justify-content: center; }

/* The lotto ball — frosted glass sphere */
.ball {
  --d: var(--an-ball, 54px);
  width: var(--d); height: var(--d); border-radius: 50%; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: #11151f; user-select: none; cursor: default;
  background:
    radial-gradient(circle at 32% 28%, #ffffff 0%, #f4f6fb 38%, #d9dee9 78%, #c2c8d6 100%);
  box-shadow:
    inset 0 2px 4px rgba(255,255,255,.9),
    inset 0 -6px 12px rgba(90,100,120,.35),
    0 6px 14px rgba(0,0,0,.45);
  position: relative;
  transition: transform .35s cubic-bezier(.34,1.56,.64,1), box-shadow .3s, opacity .3s;
}
.ball::after {  /* glass highlight */
  content: ""; position: absolute; top: 8%; left: 20%; width: 46%; height: 30%;
  border-radius: 50%; background: linear-gradient(180deg, rgba(255,255,255,.95), transparent);
  filter: blur(1px); opacity: .8;
}
.ball .bn { position: relative; z-index: 1; line-height: 1; max-width: 96%; overflow: hidden; text-align: center; }
/* text auto-fits via font-size set inline by JS */

.ball.is-dim { opacity: .14; filter: grayscale(.5); }
.ball.is-pickable { cursor: pointer; }
.ball.is-pickable:hover { transform: scale(1.08); box-shadow: inset 0 2px 4px rgba(255,255,255,.9), inset 0 -6px 12px rgba(90,100,120,.35), 0 10px 22px rgba(0,0,0,.5), 0 0 0 3px rgba(255,211,77,.5); }

/* selected value ball — gold ring + glow */
.ball.is-match {
  box-shadow:
    inset 0 2px 4px rgba(255,255,255,.9),
    inset 0 -6px 12px rgba(150,120,40,.3),
    0 6px 16px rgba(0,0,0,.45),
    0 0 0 3px rgba(255,211,77,.85),
    0 0 22px rgba(255,200,60,.55);
  background: radial-gradient(circle at 32% 28%, #fffefb 0%, #fff4d6 42%, #ffe49c 80%, #f4cf72 100%);
}
@keyframes pop-in {
  0% { transform: scale(.2); opacity: 0; }
  70% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.ball.animate-in { animation: pop-in .5s cubic-bezier(.34,1.56,.64,1) both; }
@keyframes ripple {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); }
  100% { transform: scale(1); }
}
.ball.animate-ripple { animation: ripple .55s ease-out; }

/* empty placeholder dot for blank cells */
.an-dot { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,.07); }

/* ---------------- floating glass toolbox ---------------- */
.an-toolbox {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center;
  max-width: calc(100% - 32px);
  padding: 9px 12px; border-radius: 999px;
  background: rgba(28,33,46,.55);
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 10px 40px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.12);
  backdrop-filter: blur(24px) saturate(1.4); -webkit-backdrop-filter: blur(24px) saturate(1.4);
  z-index: 40;
}
.an-tool {
  width: 44px; height: 44px; border-radius: 50%; border: none;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.06); color: #e6ebf4; cursor: pointer;
  transition: background .2s, transform .15s, box-shadow .2s;
}
.an-tool svg { width: 20px; height: 20px; }
.an-tool:hover { background: rgba(255,255,255,.14); transform: translateY(-2px); }
.an-tool.is-on { background: rgba(255,211,77,.9); color: #1a1206; box-shadow: 0 0 18px rgba(255,200,60,.5); }
.an-tool-sep { width: 1px; height: 26px; background: rgba(255,255,255,.14); margin: 0 4px; }

/* compact matrix / value selects inside the toolbox */
.an-tbox-select {
  background: rgba(255,255,255,.08); color: #eef2f8;
  border: 1px solid rgba(255,255,255,.16); border-radius: 999px;
  padding: 7px 10px; font-size: 12px; font-weight: 700; cursor: pointer;
  max-width: 130px; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23aab4c8' stroke-width='3'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; padding-right: 24px;
}
.an-tbox-select option {
  background: #202636;
  color: #eef2f8;
}
#an-tbox-mode { max-width: 84px; }
.an-tbox-select:hover { background-color: rgba(255,255,255,.14); }

.an-toolhint {
  position: absolute; bottom: 74px; left: 50%; transform: translateX(-50%);
  background: rgba(20,24,34,.9); color: #ffd34d; font-size: 12px; font-weight: 600;
  padding: 6px 14px; border-radius: 999px; white-space: nowrap;
  border: 1px solid rgba(255,211,77,.3); opacity: 0; transition: opacity .3s;
  pointer-events: none; z-index: 41;
}
.an-toolhint.show { opacity: 1; }

/* ---------------- ticket builder ($ panel) ---------------- */
.an-ticket {
  position: absolute; right: 18px; top: 18px; width: 280px;
  border-radius: 18px; padding: 16px;
  background: rgba(24,28,40,.7);
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 16px 50px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.1);
  backdrop-filter: blur(26px) saturate(1.4); -webkit-backdrop-filter: blur(26px) saturate(1.4);
  z-index: 45; transform: translateX(20px); opacity: 0; pointer-events: none;
  transition: transform .35s cubic-bezier(.34,1.4,.64,1), opacity .3s;
}
.an-ticket.show { transform: translateX(0); opacity: 1; pointer-events: auto; }
.an-ticket-head { display: flex; align-items: center; gap: 6px; cursor: grab; margin: -2px 0 4px; }
.an-ticket-head:active { cursor: grabbing; }
.an-tgrip { display: flex; align-items: center; color: #6b7689; }
.an-tgrip svg { width: 16px; height: 16px; }
.an-ticket h4 { margin: 0; color: #f2f5fb; font-size: 15px; font-weight: 800; letter-spacing: .02em; }
.an-ticket .sub { color: #7f8aa0; font-size: 11px; margin-bottom: 12px; }
.an-line { display: flex; align-items: center; gap: 7px; margin-bottom: 9px; min-height: 38px; }
.an-line .ln { color: #cdd5e2; font-size: 11px; font-weight: 700; width: 16px; flex: 0 0 16px; }
.an-line .slots { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.an-line.is-current { }
.an-line.is-current .slots { box-shadow: inset 0 0 0 1px rgba(255,211,77,.25); border-radius: 10px; padding: 3px; }
.an-mini {
  --d: 30px; width: var(--d); height: var(--d); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #11151f;
  background: radial-gradient(circle at 32% 28%, #fff 0%, #e7ebf2 70%, #cfd5e0 100%);
  box-shadow: inset 0 1px 2px rgba(255,255,255,.9), 0 2px 5px rgba(0,0,0,.4);
  animation: pop-in .4s cubic-bezier(.34,1.56,.64,1) both;
}
.an-mini.is-bonus { background: radial-gradient(circle at 32% 28%, #fff 0%, #ffe1a8 70%, #f3c66a 100%); box-shadow: inset 0 1px 2px rgba(255,255,255,.9), 0 2px 5px rgba(0,0,0,.4), 0 0 0 2px rgba(243,180,80,.6); }
.an-ticket-actions { display: flex; gap: 6px; margin-top: 8px; }
.an-ticket-actions button {
  flex: 1; padding: 8px 6px; border-radius: 10px; border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.06); color: #cdd5e2; font-weight: 700; font-size: 12px; cursor: pointer;
}
.an-ticket-actions button:first-child {
  background: rgba(255,211,77,.9); color: #1a1206; border-color: transparent;
}
.an-ticket-actions button:hover { background: rgba(255,255,255,.13); }
.an-ticket-actions button:first-child:hover { background: rgba(255,221,99,1); }

@media (prefers-reduced-motion: reduce) {
  .ball, .an-mini, .an-ticket, .an-toolbox { transition: none; animation: none; }
}

/* tighter layout + smaller date column on small screens */
@media (max-width: 600px) {
  .an-datecol { width: 70px; flex: 0 0 70px; font-size: 11px; }
}

/* ================================================================
   MOBILE / IPHONE LAYOUT  (≤ 768px touch screen)
   The floating toolbox becomes a fixed bottom nav bar so it never
   overlaps the grid, never fights with scroll, and is always reachable
   with a thumb. The ticket becomes a bottom sheet. Everything is
   sized for 44px tap targets throughout.
   ================================================================ */
@media (max-width: 768px) {

  /* --- control bar: hide the hint, compress selects --- */
  .an-hint { display: none; }
  .an-bar { gap: 6px; margin-bottom: 6px; }
  .an-bar select { padding: 6px 8px; font-size: 12px; max-width: 120px; }
  .an-bar label { font-size: 11px; }

  /* --- stage: no giant bottom padding (toolbar is outside now) --- */
  .an-stage {
    min-height: unset;
    padding: 12px 10px 12px;
    border-radius: 14px;
  }

  /* --- grid: use more of the screen height --- */
  .an-grid { max-height: 55vh; }
  .an-grid::-webkit-scrollbar { width: 4px; height: 4px; }

  /* --- toolbox: FIXED bottom nav bar, full width, never floats --- */
  .an-toolbox {
    position: fixed !important;
    left: 0 !important; right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    transform: none !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 18px 18px 0 0;
    padding: 10px 8px env(safe-area-inset-bottom, 8px);
    gap: 4px;
    z-index: 200;
    /* hide the drag grip on mobile — no dragging */
  }
  .an-grip { display: none; }

  /* compact toolbox selects on mobile */
  .an-tbox-select { font-size: 11px; padding: 6px 6px; max-width: 90px; padding-right: 18px; }
  #an-tbox-mode { max-width: 62px; }

  /* smaller tool buttons but still 44px tap target */
  .an-tool { width: 40px; height: 40px; }
  .an-tool svg { width: 18px; height: 18px; }
  .an-tool-sep { height: 20px; margin: 0 2px; }
  .an-zoomlabel { min-width: 30px; font-size: 11px; }

  /* hint floats above the toolbar */
  .an-toolhint { bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }

  /* --- ticket: bottom sheet instead of floating panel --- */
  .an-ticket {
    position: fixed !important;
    left: 0 !important; right: 0 !important;
    bottom: 0 !important; top: auto !important;
    width: 100% !important;
    max-height: 70vh;
    border-radius: 20px 20px 0 0;
    transform: translateY(100%) !important;
    opacity: 1 !important;
    transition: transform .35s cubic-bezier(.34,1.2,.64,1) !important;
    z-index: 300;
    overflow-y: auto;
    padding-bottom: env(safe-area-inset-bottom, 16px);
  }
  .an-ticket.show {
    transform: translateY(0) !important;
    pointer-events: auto !important;
  }
  /* hide the drag grip on the ticket on mobile */
  .an-ticket-head { cursor: default; }
  .an-tgrip { display: none; }

  /* make ticket action buttons larger for touch */
  .an-ticket-actions button { padding: 12px 8px; font-size: 13px; }
}

/* very small phones (iPhone SE etc) */
@media (max-width: 375px) {
  .an-tbox-select { max-width: 72px; font-size: 10px; }
  .an-tool { width: 36px; height: 36px; }
  .an-tool svg { width: 16px; height: 16px; }
}

/* ---- pick row + column context ---- */
.an-col-label.is-pickcol { color: #ffd34d; text-shadow: 0 0 12px rgba(255,200,60,.5); }
.an-cell.is-pickcol-cell { background: rgba(255,211,77,.06); border-radius: 10px; }
.an-row.is-rowhit { background: rgba(255,211,77,.05); border-radius: 12px; }
.an-row.is-rowhit .ball:not(.is-match) { opacity: .55; }

/* ---- toolbox grip + zoom ---- */
.an-grip { display: flex; align-items: center; justify-content: center; width: 22px; height: 44px; color: #6b7689; cursor: grab; }
.an-grip:active { cursor: grabbing; }
.an-grip svg { width: 18px; height: 18px; }
.an-zoomlabel { color: #cdd5e2; font-size: 12px; font-weight: 700; min-width: 40px; text-align: center; font-variant-numeric: tabular-nums; }

/* the ball you actually picked on the current row — steady bright gold ring */
.ball.is-picked {
  box-shadow:
    inset 0 2px 4px rgba(255,255,255,.9),
    inset 0 -6px 12px rgba(150,120,40,.3),
    0 6px 16px rgba(0,0,0,.45),
    0 0 0 4px rgba(255,221,99,1),
    0 0 30px rgba(255,210,80,.85);
  transform: scale(1.06);
}

/* ---- movie focus: matrix only, no header / footer / chrome ---- */
body.an-movie-focus .masthead,
body.an-movie-focus .tabs,
body.an-movie-focus .foot,
body.an-movie-focus #view-analysis .an-bar { display: none !important; }

body.an-movie-focus main { padding: 0 !important; }
body.an-movie-focus #view-analysis { margin: 0; }
body.an-movie-focus .an-stage {
  position: fixed; inset: 0; z-index: 2000;
  min-height: 100vh; border-radius: 0; border: none;
  padding: 24px 20px 96px;
  display: flex; flex-direction: column; justify-content: flex-start;
}
/* fit-to-screen: no scroll in movie mode — entire matrix sized to viewport */
body.an-movie-focus .an-grid {
  max-height: none; overflow: hidden;
  display: flex; flex-direction: column; align-items: flex-start;
}
/* compact spacing in movie mode — rows/columns use the fitted gap */
body.an-movie-focus .an-rows { gap: var(--an-gap, 6px); }
body.an-movie-focus .an-row,
body.an-movie-focus .an-colhead { gap: var(--an-gap, 6px); }
body.an-movie-focus .an-cell {
  width: var(--an-ball, 40px); flex: 0 0 var(--an-ball, 40px); height: var(--an-ball, 40px);
}
body.an-movie-focus .an-col-label {
  width: var(--an-ball, 40px); flex: 0 0 var(--an-ball, 40px);
}
/* hide the Date column in movie mode — matrix is the sole focus */
body.an-movie-focus .an-datecol { display: none !important; }

/* movie mode: flat dots instead of glass spheres (number still shown) */
body.an-movie-focus .ball {
  background: rgba(255,255,255,.16);
  color: #e9edf4;
  box-shadow: none;
  border: 1px solid rgba(255,255,255,.22);
}
body.an-movie-focus .ball::after { display: none; }   /* drop glass highlight */
body.an-movie-focus .ball.is-match {
  background: #ffd34d;
  color: #1a1206;
  border-color: #ffdf73;
  box-shadow: 0 0 14px rgba(255,200,60,.55);
}
body.an-movie-focus .ball.is-picked {
  background: #ffdf73;
  color: #1a1206;
  border: 2px solid #fff0b8;
  box-shadow: 0 0 18px rgba(255,210,80,.8);
  transform: none;
}

/* exit button only visible in focus mode */
#an-exit { display: none; }
body.an-movie-focus #an-exit { display: flex; }
