/*
 * grid.css — feature grid-trend (spec 04 §2–§11): main history grid, VIP lock layers,
 * trace lines, hover tooltip, column font sizes, 72-column landscape overlay.
 * Values copied verbatim from the original stylesheet, in its source order.
 * The shared number-cell rules (.history-cell, .history-value, .num-N, .history-nine-bg,
 * .pending-countdown, pendingTextBlink, highlight mode) live in base.css; the room-switch
 * animation block lives in spells.css.
 */

.history-grid {
  --history-line: #d7dbe4;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--history-columns, 20), minmax(0, 1fr));
  grid-auto-rows: var(--history-cell-size, auto);
  gap: 0;
  height: min(calc(var(--history-cell-size, 24px) * 15), calc(100dvh - 248px));
  border-top: 1px solid var(--history-line);
  border-left: 1px solid var(--history-line);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  align-content: start;
}

.history-data-wrap,
.trend-data-wrap,
.wide-history-shell {
  position: relative;
}

.history-data-wrap.is-vip-locked .history-grid,
.trend-data-wrap.is-vip-locked .trend-board,
.wide-history-view.is-vip-locked .wide-history-grid {
  filter: blur(6px) saturate(.7) brightness(.72);
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

.vip-data-lock {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: radial-gradient(circle at 50% 36%, rgba(91, 196, 255, .2), transparent 190px), #080f1c5c;
  backdrop-filter: blur(9px) saturate(1.18);
  -webkit-backdrop-filter: blur(9px) saturate(1.18);
}

.vip-data-lock[hidden] {
  display: none;
}

.vip-data-lock > div {
  width: min(86%, 310px);
  border: 1px solid rgba(230, 200, 126, .45);
  border-radius: 14px;
  padding: 18px 16px;
  display: grid;
  justify-items: center;
  gap: 10px;
  text-align: center;
  background: linear-gradient(180deg, #19283edb, #080f1de6), radial-gradient(circle at 50% 0, rgba(255, 230, 142, .16), transparent 140px);
  box-shadow: 0 18px 48px #00000057;
}

.vip-data-lock strong {
  color: #fff6da;
  font-size: 20px;
  line-height: 1.25;
}

.vip-data-lock p {
  color: #d8e2f2db;
  font-size: 13px;
  line-height: 1.45;
}

.vip-data-lock button {
  min-width: 128px;
  height: 38px;
  border: 1px solid rgba(255, 230, 144, .72);
  border-radius: 999px;
  background: linear-gradient(180deg, #d7b45e, #694316);
  color: #fff9dd;
  font-size: 16px;
  font-weight: 900;
  text-shadow: 0 1px 1px rgba(0, 0, 0, .35);
  box-shadow: inset 0 1px #ffffff57, 0 8px 22px #00000038;
}

/* Trace line (spec 04 §10.4) */
.history-trace-line {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  pointer-events: none;
  overflow: visible;
}

.history-trace-path {
  fill: none;
  opacity: .96;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, .38));
}

.history-trace-shadow {
  fill: none;
  stroke: #060a127a;
  opacity: .5;
}

.history-trace-path.is-nine {
  opacity: 1;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, .55)) drop-shadow(0 0 5px rgba(255, 238, 96, .48)) drop-shadow(0 0 7px rgba(49, 221, 255, .42));
}

.history-trace-pending {
  stroke-dasharray: 6 5;
  animation: historyTraceDash .8s linear infinite;
}

/* Hover tooltip (spec 04 §7) */
.history-hover-tooltip {
  position: fixed;
  z-index: 9999;
  max-width: min(280px, calc(100vw - 16px));
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 4px;
  background: #2f2d2df7;
  box-shadow: 0 3px 12px #0000006b;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  pointer-events: none;
  white-space: nowrap;
}

.history-hover-tooltip[hidden] {
  display: none;
}

.history-day-gap {
  visibility: hidden;
  pointer-events: none;
}

/* Never applied by any script (quirk Q14), kept from the original stylesheet. */
.history-cell.is-carryover {
  filter: brightness(.78) saturate(.84);
}

.history-cell.is-carryover-start {
  border-top: 2px solid rgba(120, 143, 175, .72);
}

/* Panel + per-column font sizes (spec 04 §5.2; no 20-column rule) */
.history-panel {
  --history-columns: 24;
  margin-top: 10px;
  padding: 0;
}

.history-panel[data-columns="10"] .history-cell {
  font-size: 17px;
}

.history-panel[data-columns="22"] .history-cell {
  font-size: 15px;
}

.history-panel[data-columns="24"] .history-cell {
  font-size: 14px;
}

.history-panel[data-columns="30"] .history-cell {
  font-size: 13px;
}

.history-panel[data-columns="36"] .history-cell {
  font-size: 12px;
}

.history-panel[data-columns="72"] .history-cell {
  font-size: 9px;
}

.history-panel[data-columns="10"] .history-cell.num-9 {
  font-size: 17px;
}

.history-panel[data-columns="22"] .history-cell.num-9 {
  font-size: 15px;
}

.history-panel[data-columns="24"] .history-cell.num-9 {
  font-size: 14px;
}

.history-panel[data-columns="30"] .history-cell.num-9 {
  font-size: 13px;
}

.history-panel[data-columns="36"] .history-cell.num-9 {
  font-size: 12px;
}

.history-panel[data-columns="72"] .history-cell.num-9 {
  font-size: 9px;
}

/* 72-column landscape overlay (spec 04 §9.2) */
.wide-history-view {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 300;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: radial-gradient(circle at 15% 10%, rgba(68, 151, 206, .22), transparent 30%), linear-gradient(145deg, #07111f, #101b2f 48%, #07101d);
  overflow: hidden;
}

.wide-history-view[hidden] {
  display: none;
}

body.is-wide-history {
  overflow: hidden;
}

.wide-history-shell {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.wide-history-back {
  position: absolute;
  left: max(8px, env(safe-area-inset-left));
  top: max(8px, env(safe-area-inset-top));
  z-index: 4;
  min-width: 54px;
  min-height: 28px;
  border: 1px solid rgba(126, 191, 239, .72);
  border-radius: 999px;
  background: #081424c7;
  color: #eaf6ff;
  font-size: 13px;
  font-weight: 850;
  box-shadow: inset 0 1px #ffffff1f, 0 4px 14px #00000059;
}

.wide-history-grid {
  --history-line: #d7dbe4;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(72, minmax(0, 1fr));
  grid-auto-rows: var(--wide-history-cell-size, 12px);
  align-content: start;
  gap: 0;
  border-top: 1px solid var(--history-line);
  border-left: 1px solid var(--history-line);
  overflow: auto;
  overscroll-behavior: contain;
  background: #111b2a;
}

.wide-history-grid .history-cell {
  font-size: clamp(8px, calc(var(--wide-history-cell-size, 12px) * .78), 11px);
  font-weight: 380;
}

.wide-history-grid .history-cell.num-9 {
  font-size: clamp(8px, calc(var(--wide-history-cell-size, 12px) * .78), 11px);
  font-weight: 500;
}

.wide-history-grid .pending-countdown {
  font-size: clamp(8px, calc(var(--wide-history-cell-size, 12px) * .72), 11px);
}

@media (orientation: portrait) {
  .wide-history-view {
    padding: 0;
  }

  .wide-history-shell {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 100vh;
    height: 100vw;
    padding: max(8px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-top));
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center;
  }
}

@keyframes historyTraceDash {
  0% {
    stroke-dashoffset: 0;
  }
  to {
    stroke-dashoffset: -22;
  }
}

/*
 * ≤ 360px (grid part of the original 2568 media block). The global `.history-cell`
 * rule comes after `.pending-countdown` (base.css), so the countdown cell drops to
 * weight 380 and, at 20 columns, to 13px (quirk Q16).
 */
@media (max-width: 360px) {
  .history-grid {
    gap: 0;
  }

  .history-cell {
    border-radius: 0;
    font-size: 13px;
    font-weight: 380;
  }

  .history-cell.num-9 {
    font-size: 13px;
    font-weight: 500;
  }

  .history-panel[data-columns="10"] .history-cell,
  .history-panel[data-columns="10"] .history-cell.num-9 {
    font-size: 16px;
  }

  .history-panel[data-columns="22"] .history-cell,
  .history-panel[data-columns="22"] .history-cell.num-9 {
    font-size: 14px;
  }

  .history-panel[data-columns="24"] .history-cell,
  .history-panel[data-columns="24"] .history-cell.num-9 {
    font-size: 13px;
  }

  .history-panel[data-columns="30"] .history-cell,
  .history-panel[data-columns="30"] .history-cell.num-9 {
    font-size: 12px;
  }

  .history-panel[data-columns="36"] .history-cell,
  .history-panel[data-columns="36"] .history-cell.num-9 {
    font-size: 10px;
  }

  .history-panel[data-columns="72"] .history-cell,
  .history-panel[data-columns="72"] .history-cell.num-9 {
    font-size: 8px;
  }
}
