/* ============================================================
   AmbientOs Base Styles
   ============================================================ */

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/ibm-plex-sans-400.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/ibm-plex-sans-500.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/ibm-plex-sans-600.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/ibm-plex-sans-700.woff2") format("woff2");
}

/* Be Vietnam Pro — self-hosted (OFL), applied only for html[lang="vi"].
   Two subsets per weight: latin (Basic Latin) + vietnamese (VN diacritics). */
@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/be-vietnam-pro/be-vietnam-pro-latin-400.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/be-vietnam-pro/be-vietnam-pro-vietnamese-400.woff2") format("woff2");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/be-vietnam-pro/be-vietnam-pro-latin-500.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/be-vietnam-pro/be-vietnam-pro-vietnamese-500.woff2") format("woff2");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/be-vietnam-pro/be-vietnam-pro-latin-600.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/be-vietnam-pro/be-vietnam-pro-vietnamese-600.woff2") format("woff2");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/be-vietnam-pro/be-vietnam-pro-latin-700.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/be-vietnam-pro/be-vietnam-pro-vietnamese-700.woff2") format("woff2");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

/* --- Reset -------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

/* --- Base --------------------------------------------------- */
body {
  height: 100%;
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Themed text selection. */
::selection {
  background-color: hsl(var(--primary) / 0.28);
  color: hsl(var(--foreground));
}

/* Themed custom scrollbars (WebKit + Firefox). */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background-color: var(--border-strong);
  border: 2px solid transparent;
  background-clip: padding-box;
  border-radius: 999px;
}
*::-webkit-scrollbar-thumb:hover { background-color: hsl(var(--muted-foreground)); }

/* Sane default focus ring for interactive elements without a component-specific one. */
:where(a, button, input, select, textarea, summary, [role="button"], [tabindex]:not([tabindex="-1"])):focus-visible {
  outline: 2px solid hsl(var(--ui-ring));
  outline-offset: 2px;
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

#app {
  height: 100%;
}

/* --- Loading splash ----------------------------------------- */
.loading-splash {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 1rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
}

.loading-splash svg {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

/* --- Blazor error UI --------------------------------------- */
#blazor-error-ui {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: 0.75rem 1rem;
  background-color: hsl(var(--destructive));
  color: hsl(var(--destructive-foreground));
  font-size: 0.875rem;
  text-align: center;
}

#blazor-error-ui .reload {
  color: inherit;
  font-weight: 600;
  margin-left: 0.5rem;
  text-decoration: underline;
}

/* --- Utilities --------------------------------------------- */

/* Screen-reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Layout */
.container {
  width: 100%;
  max-width: 1280px;
  margin-inline: auto;
  padding-inline: 1rem;
}

.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.gap-2 {
  gap: 0.5rem;
}

.gap-4 {
  gap: 1rem;
}

.grid {
  display: grid;
}

/* Visual */
.rounded {
  border-radius: var(--radius);
}

.shadow {
  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
}

.shadow-md {
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

.border {
  border: 1px solid hsl(var(--border));
}

/* Typography */
.text-sm {
  font-size: 0.875rem;
  line-height: 1.25rem;
}

.text-xs {
  font-size: 0.75rem;
  line-height: 1rem;
}

.text-lg {
  font-size: 1.125rem;
  line-height: 1.75rem;
}

.text-xl {
  font-size: 1.25rem;
  line-height: 1.75rem;
}

.text-2xl {
  font-size: 1.5rem;
  line-height: 2rem;
}

.text-muted {
  color: hsl(var(--muted-foreground));
}

.font-medium {
  font-weight: 500;
}

.font-semibold {
  font-weight: 600;
}

.font-bold {
  font-weight: 700;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Spacing helpers */
.p-4 {
  padding: 1rem;
}

.p-6 {
  padding: 1.5rem;
}

.px-4 {
  padding-inline: 1rem;
}

.py-2 {
  padding-block: 0.5rem;
}

.mt-1 {
  margin-top: 0.25rem;
}

.mt-4 {
  margin-top: 1rem;
}

.w-full {
  width: 100%;
}

.h-full {
  height: 100%;
}

/* --- Admin shared ------------------------------------------ */
.admin-page-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: hsl(var(--foreground));
  margin-bottom: .5rem;
}

.admin-page-hint {
  font-size: .875rem;
  color: hsl(var(--muted-foreground));
  margin-bottom: 1.5rem;
}

/* ============================================================
   TV D-pad focus ring (V3) — ONE focus language for the whole app.
   Double ring: white inner (separates from any card color) + blue
   outer (reads on white cards AND the navy rail) + lift shadow.
   Slight scale on focus, except inside media stages (#526).
   ============================================================ */
.tv-focusable {
  outline: none;
  transition: transform 160ms var(--tv-motion, ease), box-shadow 160ms var(--tv-motion, ease),
              background 140ms var(--tv-motion, ease);
}

.tv-focusable:focus-visible,
.tv-focusable.tv-focus {
  outline: none;
  box-shadow: var(--tv-focus-ring, 0 0 0 3px #fff, 0 0 0 7px #2f7fd1, 0 16px 44px rgba(16, 42, 74, .22));
  transform: scale(1.03);
  z-index: 5;
  position: relative;
  border-radius: 12px;
}

/* #526 — the media stage/player must NEVER get a transform (any transformed ancestor of an
   <iframe>/<video> breaks Android WebView's SurfaceView hole-punch: audio, no picture).
   Same ring, box-shadow only. .tv-stage-zone marks any wrapper that can contain an embed. */
.tm-view .tv-focusable:focus-visible,
.tm-view:focus-visible,
.tv-viewer:focus-visible,
.tv-stage-zone .tv-focusable:focus-visible,
.tv-stage-zone:focus-visible {
  transform: none;
}

/* Edge-bump feedback (§2.2 luật 1): khi bấm phím mà không đi đâu được, tv-nav.js gắn class
   này 150ms — ring "nhún" nhẹ để báo "đến mép rồi" thay vì màn hình đứng im. */
.tv-focusable.tv-edge-bump:focus-visible,
.tv-focusable.tv-edge-bump {
  animation: tv-edge-bump 150ms var(--tv-motion, ease);
}

@keyframes tv-edge-bump {
  0%   { transform: scale(1.03); }
  50%  { transform: scale(1.008); }
  100% { transform: scale(1.03); }
}

/* Stage zones bump shadow-only (no transform, #526). */
.tv-stage-zone .tv-focusable.tv-edge-bump,
.tv-stage-zone.tv-edge-bump {
  animation: none;
}

/* Give focus room to breathe inside panels that would otherwise clip the ring/scale. */
.tv-focus-safe {
  overflow: visible;
}

/* Page transition — fade-in only (opacity is compositor-only; no transform: #526-safe). */
.tv-page-fade {
  animation: tv-page-fade 180ms ease-out;
}

@keyframes tv-page-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .tv-focusable { transition: none; }
  .tv-focusable:focus-visible,
  .tv-focusable.tv-focus { transform: none; }
  .tv-focusable.tv-edge-bump { animation: none; }
  .tv-page-fade { animation: none; }
}
