/* Mahar mini app — mobile-first, WebView-safe. No inline styles anywhere
   (CSP style-src 'self'). Theme matches mahar.app: black background,
   cyan #00b2ff brand accent, slate-gray secondary text. */

/* Header height compensation: main pads its bottom by this so centered
   content (channel cards, status card) sits at the TRUE viewport center,
   not the center of the area below the header. */
:root {
  --header-h: 56px; /* 6 + 36px logo + 14 */
  /* Mahar app palette (mahar.app card pages): page bg = Tailwind gray-900,
     cards = gray-800, borders = gray-700. Video letterbox stays pure black. */
  --bg: #111827;
  --card: #1f2937;
  --card-border: #374151;
  --text: #e8ecf1;
  --text-muted: #728197;
  --accent: #00b2ff;
  --accent-strong: #0098d8;
  --accent-contrast: #041018;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Noto Sans Myanmar", "Padauk", "Myanmar Text", sans-serif;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(10px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
  /* Fluid column: fills fold-inner/tablet screens, stays a sensible column
     on desktops. Text-heavy elements keep their own readable caps. */
  max-width: 1080px;
  margin: 0 auto;
  width: 100%;
}

@media (min-width: 800px) {
  :root { --header-h: 60px; } /* 6 + 40px logo + 14 */
  #app {
    padding-left: 24px;
    padding-right: 24px;
  }
  .app-logo { height: 40px; }
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center; /* centers status card / player in any orientation */
  padding-bottom: var(--header-h); /* optical center against the full viewport */
}

/* --- Header --- */

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 2px 14px;
}

.app-logo {
  /* 768x256 (3:1) wordmark — 36px tall renders ~108px wide */
  height: 36px;
  width: auto;
  display: block;
}

/* --- Status card --- */

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 34px 22px;
  /* Readable measure on wide screens; the column itself stretches. */
  width: 100%;
  max-width: 560px;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
}

.status-icon {
  margin-bottom: 12px;
}

.status-icon img {
  height: 42px;
  width: auto;
  display: block;
  margin: 0 auto;
  animation: status-breathe 1.8s ease-in-out infinite;
}

@keyframes status-breathe {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

#screen-status h1 {
  font-size: 19px;
  margin: 0 0 8px;
}

#screen-status p {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-muted);
  margin: 0 0 18px;
  overflow-wrap: break-word;
}

.btn {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  padding: 12px 30px;
  cursor: pointer;
  font-family: inherit;
}

.btn:active {
  background: var(--accent-strong);
}

.diag-link {
  display: inline-block;
  margin-top: 14px;
  font-size: 13px;
  color: var(--accent);
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

/* --- Player --- */

.video-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
  margin-top: 4px;
}

/* Landscape (short viewports): derive width from available height so the
   player never forces page scrolling. */
@media (orientation: landscape) {
  .video-wrapper {
    width: auto;
    height: calc(100vh - 72px);
    height: calc(100dvh - 72px);
    max-height: 520px; /* roomier cap for fold-inner/tablet landscape */
    max-width: 100%;
    margin: 2px auto 0;
  }
}

/* Fullscreen takes over the whole screen — undo the fit calculations. */
.video-wrapper:fullscreen {
  width: 100%;
  height: 100%;
  max-height: none;
  aspect-ratio: auto;
  border-radius: 0;
}

/* Slim chrome on short screens (phone landscape). */
@media (max-height: 560px) {
  .app-header { padding: 2px 2px 8px; }
  .app-logo { height: 28px; }
  .card { padding: 18px 16px; }
  #screen-status h1 { font-size: 17px; }
  #screen-status p { font-size: 13px; margin-bottom: 12px; }
}

#video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #000;
}

/* Forensic watermark: derived per-session code, drifting between corners. */
.watermark {
  position: absolute;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.28);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  transition: top 1.2s ease, left 1.2s ease, right 1.2s ease, bottom 1.2s ease;
  z-index: 3;
}

.watermark.wm-0 { top: 10px; right: 12px; }
.watermark.wm-1 { top: 12%; left: 8%; right: auto; }
.watermark.wm-2 { bottom: 16%; right: 10%; top: auto; }
.watermark.wm-3 { bottom: 10%; left: 10%; right: auto; top: auto; }

/* Controls bar */
.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 26px 8px 8px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  opacity: 1;
  transition: opacity 0.25s ease;
  z-index: 4;
}

.controls.controls-hidden {
  opacity: 0;
  pointer-events: none;
}

.ctrl-btn {
  background: none;
  border: none;
  color: #fff;
  min-width: 44px;
  min-height: 40px;
  cursor: pointer;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ctrl-btn .ic {
  width: 22px;
  height: 22px;
  display: block;
}

/* Pseudo-fullscreen: the WebView's Fullscreen API is host-dependent (many
   super apps don't implement it), so the player falls back to filling the
   viewport via CSS when requestFullscreen() is not honored. */
.video-wrapper.pseudo-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 200;
  width: 100%;
  height: 100%;
  max-height: none;
  max-width: none;
  aspect-ratio: auto;
  margin: 0;
  border-radius: 0;
}

/* Portrait-locked WebViews: rotate the player 90° so a landscape stream fills
   the screen when the viewer turns the phone sideways. Controls and watermark
   rotate with the wrapper, so the layout stays self-consistent. */
.video-wrapper.pseudo-fullscreen.rotate {
  inset: auto;
  top: 50%;
  left: 50%;
  width: 100vh;
  height: 100vw;
  transform: translate(-50%, -50%) rotate(90deg);
}

body.pseudo-fullscreen-open {
  overflow: hidden;
}

.ctrl-spacer {
  flex: 1;
}

/* Spinner */
.spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 38px;
  height: 38px;
  margin: -19px 0 0 -19px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  z-index: 2;
}

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

/* Big play overlay (tap-to-start with sound) */
.big-play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 74px;
  height: 74px;
  border-radius: 50%;
  border: none;
  background: rgba(20, 24, 30, 0.82);
  color: #fff;
  cursor: pointer;
  z-index: 5;
}

.big-play .ic {
  width: 34px;
  height: 34px;
}

/* --- Wave SDK consent sheet (rendered in-page by the SDK) ------------------
   The SDK styles it with inline attributes (allowed via style-src-attr) and
   hardcodes a cyan #16B4FB button; these overrides re-brand it Mahar and win
   over inline styles with !important. */
#wm-dialog-content {
  color: #e8ecf1 !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Noto Sans Myanmar", "Padauk", "Myanmar Text", sans-serif !important;
}

#wm-dialog-content img {
  border-radius: 12px;
}

#wm-agree-btn {
  background-color: #00b2ff !important;
  color: #041018 !important;
  font-weight: 700 !important;
  border: none !important;
  border-radius: 10px !important;
  padding: 13px !important;
  font-family: inherit !important;
}

/* --- Exit confirmation modal ---------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 24px 22px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.modal-card h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.modal-card p {
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions .btn {
  flex: 1;
  padding: 12px 10px;
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--card-border);
}

.btn-danger {
  background: #d32f2f;
  color: #fff;
}

.btn-danger:active {
  background: #b71c1c;
}

/* App-level exit chip: pinned top-right of the whole app (fixed), layered
   above the fullscreen player (z-index 250 > player 200, below the modal's
   300) so it stays visible when the video is maximized. */
.corner-exit {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
  z-index: 250;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.corner-exit .ic {
  width: 17px;
  height: 17px;
}

/* Twin chip inside the player frame, shown only in fullscreen modes — it
   rotates WITH the frame, so it lands at the viewer's top-right in the
   rotated (portrait-locked) pseudo-fullscreen, where a fixed chip would
   sit at the wrong physical corner. Clicks proxy to the app-level chip. */
.fs-exit {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
  display: none;
}

.video-wrapper.fs-mode .fs-exit {
  display: flex;
}

/* --- Channel home ------------------------------------------------------------ */
.channel-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

/* Wide/landscape: two roomier cards side by side. */
@media (min-width: 700px) {
  .channel-list {
    grid-template-columns: 1fr 1fr;
    max-width: 680px;
    gap: 16px;
  }
  .channel-card {
    padding: 32px 22px 26px;
    gap: 18px;
  }
  .channel-card img { height: 120px; }
  .channel-card .channel-name { font-size: 16px; }
}

/* Landscape phones (wider than tall but under the 700px breakpoint):
   side-by-side still fits and vertical space is scarce — bigger cards
   horizontally, capped height. */
@media (orientation: landscape) and (max-height: 500px) {
  .channel-list {
    grid-template-columns: 1fr 1fr;
    max-width: 640px;
  }
  .channel-card img { height: 84px; }
}

.channel-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 24px 18px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s ease;
}

.channel-card:active {
  border-color: var(--accent);
}

/* Fixed logo height (width follows aspect): identical visual weight and
   guaranteed centering across cards regardless of source-file proportions. */
.channel-card img {
  height: 96px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  object-position: center;
}

.channel-card .channel-name {
  font-size: 15px;
  font-weight: 700;
}

/* One-time "rotate your phone" hint (inside the frame so it reads upright
   when the phone is held sideways). Self-fading, never blocks touches. */
.rotate-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(15, 18, 23, 0.88);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  z-index: 7;
  pointer-events: none;
  animation: rotate-hint-fade 3.5s ease forwards;
}

.rotate-hint .ic {
  width: 22px;
  height: 22px;
}

@keyframes rotate-hint-fade {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; }
}
