/* ==========================================================================
   Tạp Hóa AI 1986 — Trang chủ Không gian 3D + Header hợp nhất
   Flat Vintage Print (Zero Shadow) + Day / Night HUD
   ========================================================================== */

:root,
[data-theme="light"],
[data-theme="dark"] {
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'Lora', Georgia, serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;

  --hud-bg: rgba(244, 235, 212, 0.96);
  --hud-surface: #faf3e1;
  --hud-bg-soft: #e6d6b5;
  --hud-border: rgba(135, 108, 69, 0.36);
  --text: #271b10;
  --text-secondary: #4a3826;
  --text-muted: #705a42;
  --primary: #1c4a39;
  --primary-hover: #133629;
  --primary-fg: #f8f0dc;
  --accent-red: #9e261d;
  --accent-red-hover: #7f1c15;
  --accent-red-fg: #f8f0dc;
  --radius: 2px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  color: var(--text);
  background: #e7d8b5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button, input, select {
  font-family: var(--font-body);
}

#shop3d-canvas {
  position: fixed;
  inset: 0;
  z-index: 2;
  width: 100vw;
  height: 100dvh;
  display: block;
  background: transparent;
  touch-action: none;
  cursor: grab;
}

#shop3d-canvas:active {
  cursor: grabbing;
}

/* Hidden audio-only YouTube stream driving the 3D corner wall speaker (zero visible video) */
.s3d-speaker-audio {
  position: fixed;
  left: -9999px;
  top: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: -1;
}

.s3d-speaker-audio iframe {
  width: 1px;
  height: 1px;
  border: 0;
  pointer-events: none;
}

/* 3D Perspective-Projected Live Square (1:1) YouTube CRT Television Screen
   Always sits behind #shop3d-canvas (z-index: 1 < 2) with pointer-events: none so
   WebGL depth buffer occludes it pixel-perfectly behind all 3D geometry. */
.s3d-tv-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 480px;
  height: 480px;
  z-index: 1;
  transform-origin: 0 0;
  background: #182320;
  border-radius: 28px;
  overflow: hidden;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  will-change: transform;
}

.s3d-tv-screen.is-visible {
  visibility: visible;
  opacity: 1;
}

.s3d-tv-screen iframe {
  position: absolute;
  top: -192px;
  left: -192px;
  width: 864px;
  height: 864px;
  border: 0;
  display: block;
  pointer-events: none;
}

.s3d-tv-osd {
  position: absolute;
  top: 22px;
  right: 22px;
  z-index: 4;
  min-width: 146px;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(10, 22, 16, 0.80);
  border: 1.5px solid rgba(98, 255, 146, 0.48);
  color: #62ff92;
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.04em;
  text-shadow: 0 0 10px rgba(98, 255, 146, 0.65);
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.s3d-tv-osd.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.s3d-tv-osd__bars {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.s3d-tv-osd__bar {
  width: 10px;
  height: 14px;
  border-radius: 2px;
  background: rgba(98, 255, 146, 0.18);
  border: 1px solid rgba(98, 255, 146, 0.35);
}

.s3d-tv-osd__bar.is-on {
  background: #62ff92;
  box-shadow: 0 0 6px rgba(98, 255, 146, 0.7);
}

.s3d-tv-exit {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 22;
  height: 32px;
  padding: 0 12px;
  background: var(--hud-bg);
  border: 1px solid var(--accent-red);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-red);
  cursor: pointer;
}

.s3d-tv-exit:hover {
  background: var(--accent-red);
  color: var(--accent-red-fg);
}

.s3d-tv-exit[hidden] {
  display: none;
}

.s3d-top-left {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 23;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.s3d-fs-btn {
  height: 32px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--hud-bg);
  border: 1px solid var(--hud-border);
  border-radius: var(--radius);
  color: var(--primary);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.s3d-fs-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-fg);
}

.s3d-fs-btn.is-active {
  background: var(--accent-red);
  border-color: var(--accent-red);
  color: var(--accent-red-fg);
}

.s3d-fs-btn[hidden] {
  display: none;
}

.s3d-fs-ico {
  display: block;
  flex-shrink: 0;
}

.s3d-fs-ico--exit {
  display: none;
}

.s3d-fs-btn.is-active .s3d-fs-ico--enter {
  display: none;
}

.s3d-fs-btn.is-active .s3d-fs-ico--exit {
  display: block;
}

/* Visually hidden semantic navigation for SEO & screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Crisp native 2D Search Input aligned directly inside FilterDialog3D (no CSS transform blur) */
.s3d-search-3d-wrap {
  position: fixed;
  top: 0;
  left: 0;
  width: 420px;
  height: 44px;
  z-index: 24;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease;
}

.s3d-search-3d-wrap.is-visible {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

.s3d-search-3d-wrap form {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: transparent;
}

.s3d-search-3d-icon {
  display: inline-flex;
  align-items: center;
  color: var(--accent-red);
  margin-right: 12px;
  flex-shrink: 0;
}

.s3d-search-3d-icon svg {
  width: 20px;
  height: 20px;
}

.s3d-search-3d-wrap input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
  -webkit-font-smoothing: antialiased;
}

.s3d-search-3d-wrap input::placeholder {
  color: var(--text-muted);
  font-style: italic;
  font-weight: 400;
}

/* Floating Action Button (FAB) & Expandable Zone / Pagination Menu */
.s3d-fab {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 25;
}

.s3d-fab-btn {
  position: relative;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 1.5px solid #e4c17a;
  background: var(--primary);
  color: var(--primary-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.s3d-fab-btn:hover {
  background: var(--primary-hover);
}

.s3d-fab.is-open .s3d-fab-btn {
  background: var(--accent-red);
  border-color: #f4d58d;
}

.s3d-fab.is-open .s3d-fab-btn:hover {
  background: var(--accent-red-hover);
}

.s3d-fab-ico {
  position: absolute;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.s3d-fab-ico--close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.75);
}

.s3d-fab.is-open .s3d-fab-ico--menu {
  opacity: 0;
  transform: rotate(90deg) scale(0.75);
}

.s3d-fab.is-open .s3d-fab-ico--close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.s3d-fab-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent-red);
  border: 1.5px solid var(--hud-surface);
  color: var(--accent-red-fg);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.s3d-fab-badge[hidden] {
  display: none;
}

.s3d-fab-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  width: min(296px, calc(100vw - 28px));
  padding: 10px;
  background: var(--hud-bg);
  border: 1px solid var(--hud-border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(8px) scale(0.97);
  transform-origin: bottom right;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s ease;
}

.s3d-fab.is-open .s3d-fab-menu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.s3d-fab-head {
  padding-bottom: 6px;
  border-bottom: 1px solid var(--hud-border);
  text-align: center;
}

.s3d-zones {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.s3d-zone-btn {
  border: 1px solid var(--hud-border);
  background: var(--hud-surface);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 700;
  padding: 7px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  text-align: center;
  justify-content: center;
}

.s3d-zone-btn--wide {
  grid-column: 1 / -1;
}

.s3d-zone-btn:hover {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.s3d-zone-btn.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-fg);
}

.s3d-zone-btn--filter {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.s3d-zone-btn--filter.is-filtered {
  background: var(--accent-red);
  border-color: var(--accent-red);
  color: var(--accent-red-fg);
}

.s3d-zone-btn--classic {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  border-color: var(--primary);
}

.s3d-zone-btn--classic:hover {
  background: var(--primary);
  color: var(--primary-fg);
}

.s3d-fab-foot {
  padding-top: 6px;
  border-top: 1px solid var(--hud-border);
}

.s3d-status {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  display: block;
}

.s3d-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.s3d-pager button {
  border: 1px solid var(--hud-border);
  background: var(--hud-surface);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: var(--radius);
  cursor: pointer;
}

.s3d-pager button:hover:not(:disabled) {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-fg);
}

.s3d-pager button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.s3d-page-info {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

/* Hover Tooltip */
.s3d-tooltip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 30;
  width: 248px;
  padding: 8px 10px;
  background: var(--hud-bg);
  border: 1px solid var(--accent-red);
  border-radius: var(--radius);
  pointer-events: none;
}

.s3d-tip__shop {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-red);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.s3d-tip__name {
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
  margin-bottom: 4px;
}

.s3d-tip__price {
  font-family: var(--font-mono);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--accent-red);
}

.s3d-tip__price span {
  font-size: 11px;
  padding: 1px 5px;
  border: 1px solid var(--accent-red);
  margin-left: 4px;
}

.s3d-tip__hint {
  font-size: 11.5px;
  font-style: italic;
  color: var(--text-muted);
}

/* Shared Fallback Button */
.s3d-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 12px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  cursor: pointer;
}

.s3d-btn--primary {
  background: var(--primary);
  color: var(--primary-fg);
  border: 0;
}

.s3d-btn--primary:hover {
  background: var(--primary-hover);
}

/* Loading & WebGL Fallback */
.s3d-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(24, 62, 47, 0.92);
  color: #f4ebd4;
}

.s3d-overlay[hidden] {
  display: none;
}

.s3d-overlay-box {
  max-width: 420px;
  width: 100%;
  padding: 24px 22px;
  text-align: center;
  background: #1c4a39;
  border: 1px solid rgba(228, 193, 122, 0.55);
  border-radius: var(--radius);
}

.s3d-overlay-box h1,
.s3d-overlay-box h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 22px;
  color: #fbf2da;
}

.s3d-overlay-box p {
  margin: 0 0 14px;
  font-size: 13.5px;
  color: #d2bf9c;
  line-height: 1.55;
}

.s3d-spinner {
  width: 30px;
  height: 30px;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 3px solid rgba(228, 193, 122, 0.3);
  border-top-color: #e4c17a;
  animation: s3d-spin 0.7s linear infinite;
}

@keyframes s3d-spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 960px) {
  .s3d-fs-btn {
    width: 34px;
    height: 34px;
    padding: 0;
  }
  .s3d-fs-label {
    display: none;
  }
  .s3d-fab {
    right: 14px;
    bottom: 14px;
  }
}
