@import url('https://unpkg.com/normalize.css') layer(normalize);

@layer normalize, base, demo;

@layer demo {
  [data-exclude='true'] {
    .img-container {
      opacity: calc(var(--icon-opacity, 0.25) * 0.25);
      transition: opacity 0.26s ease-out;
    }
    article:is(:hover, :focus-within) {
      .img-container { opacity: var(--icon-opacity, 0.25); }
    }
  }

  /* ✅ thu nhỏ card để đủ chỗ cho player */
  article {
    -webkit-tap-highlight-color: #0000;
    /* ✅ để grid quyết định cột; card tự co theo ô */
    width: 100%;
    max-width: var(--card-max, var(--card-w, 260px));
    aspect-ratio: 4 / 3;
    outline: 2px solid light-dark(hsl(0 0% 90%), hsl(0 0% 20%));
    background: light-dark(hsl(0 0% 98%), hsl(0 0% 10%));
    position: relative;
    border-radius: 12px;
    container-type: size;
    cursor: pointer;
    transition-property: translate, scale;
    transition-duration: 0.12s;
    transition-timing-function: cubic-bezier(.645, .045, .355, 1);

    & > div {
      -webkit-clip-path: inset(0 round 12px);
              clip-path: inset(0 round 12px);
      overflow: hidden;
      align-content: center;
      display: grid;
      place-items: center;
      gap: 0.45rem;
      position: absolute;
      inset: 0;
      border-radius: 12px;
    }

    &:active { translate: 0 1px; scale: 0.99; }

    &::after {
      content: '';
      position: absolute;
      pointer-events: none;
      inset: 0px;
      border-radius: inherit;
      border: calc(var(--border-width) * 1px) solid #0000;
      -webkit-backdrop-filter: blur(calc(var(--border-blur) * 1px)) saturate(var(--border-saturate)) brightness(var(--border-brightness)) contrast(var(--border-contrast));
              backdrop-filter: blur(calc(var(--border-blur) * 1px)) saturate(var(--border-saturate)) brightness(var(--border-brightness)) contrast(var(--border-contrast));
      -webkit-mask: linear-gradient(#fff 0 100%) border-box, linear-gradient(#fff 0 100%) padding-box;
              mask: linear-gradient(#fff 0 100%) border-box, linear-gradient(#fff 0 100%) padding-box;
      -webkit-mask-composite: xor;
              mask-composite: exclude;
      z-index: 2;
      -webkit-clip-path: inset(0 round 12px);
              clip-path: inset(0 round 12px);
      transform: translateZ(0);
    }

    img {
      width: var(--icon-size, 90px);
      user-select: none;
    }

    img:nth-of-type(1) { z-index: 2; position: relative; }

    .img-container {
      position: absolute;
      inset: 0;
      display: grid;
      place-items: center;
      transform: translateZ(0);
      filter: url(#blur) saturate(var(--icon-saturate)) brightness(var(--icon-brightness));
      /* ✅ default 0 để hiệu ứng không "mất" nếu JS pointer-tracking chưa chạy */
      translate: calc(var(--pointer-x, 0) * 50cqi) calc(var(--pointer-y, 0) * 50cqh);
      scale: var(--icon-scale);
      opacity: var(--icon-opacity);
      will-change: transform, filter;
    }

    h2 {
      z-index: 4;
      position: relative;
      font-size: 0.95rem;
      margin: 0;
      user-select: none;
      text-align: center;
    }
  }

  main {
    /* ✅ cho phép cuộn dọc trên mobile */
    touch-action: pan-y;
    width: min(var(--page-w, 800px), calc(100vw - 2rem));
    max-width: calc(100vw - 2rem);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, var(--card-w, 260px)));
    gap: clamp(0.85rem, 2.4vw, 1.25rem);
    justify-content: center;
    /* ✅ quan trọng: khi 1 cột (1fr) vẫn phải căn giữa card */
    justify-items: center;
    padding: 0.9rem 0 0.4rem;
  }

  /* ✅ Điện thoại dọc / cửa sổ hẹp: 1 cột, card full-width (không bị lệch trái) */
/* ✅ Điện thoại dọc / cửa sổ hẹp: vẫn 2 cột (2x2) nhưng card + icon nhỏ lại */
	@media (max-width: 720px) {
	  main{
		/* thu nhỏ icon/card chỉ trong khu vực apps */
		--icon-size: 74px;

		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 0.85rem;
		padding-top: 0.75rem;

		justify-content: center;
		justify-items: center;
	  }

	  article{ max-width: none; }

	  article h2{ font-size: 0.86rem; }
	}

	/* máy rất hẹp (iphone SE…): nhỏ thêm chút để vẫn giữ 2 cột */
	@media (max-width: 380px){
	  main{ --icon-size: 64px; gap: 0.7rem; }
	  article h2{ font-size: 0.80rem; }
	}


  article:is(:hover, :focus-within) {
    translate: 0 -1px;
    scale: 1.02;
  }

  /* ✅ mobile/touch: giảm hover scale để không “đè” nhau */
  @media (max-width: 720px){
    article:is(:hover, :focus-within){ translate: 0 0; scale: 1.01; }
  }
  @media (hover: none){
    article:is(:hover, :focus-within){ translate: 0 0; scale: 1; }
  }
}

@layer base {
  :root {
    --page-w: 800px;
    --card-w: 260px;
    --card-max: 260px;
    --icon-size: 90px;
    --bg-dim: 0.25;
  }

  html { color-scheme: light dark; }

  [data-theme='light'] { color-scheme: light only; }
  [data-theme='dark'] { color-scheme: dark only; }

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

  body {
    background: light-dark(#fff, #000);
    min-height: 100vh;
    margin: 0;
    font-family: var(--app-font, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif);
    display: flex;
    flex-direction: column;
    align-items: center;

    /* ✅ tránh trang bị kéo dài do padding lớn */
    padding-bottom: 0.5rem;
  }

  /* ✅ lớp dim overlay cho background image */
  body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: color-mix(in hsl, black, transparent calc(100% - (var(--bg-dim) * 100%)));
    opacity: var(--bg-dim);
    z-index: -1;
  }

  /* ✅ bỏ nền lưới */
  body::before { content: none !important; }

  .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;
  }
}

/* Header */
.hero{
  width: min(var(--page-w, 800px), calc(100vw - 2rem));
  max-width: calc(100vw - 2rem);
  text-align: center;
  margin-top: 1.4rem;
}
#page-title{
  margin: 0;
  font-size: clamp(22px, 2.6vw, 38px);
  font-weight: 800;
  letter-spacing: -0.02em;
}
#page-subtitle{
  margin: 8px 0 0;
  font-size: clamp(12px, 1.35vw, 15px);
  opacity: .75;
}

/* ✅ content luôn nằm trên overlay/event layer */
header.hero, main, .music-wrap { position: relative; z-index: 10; }

/* tweakpane */
div.tp-dfwv { width: 320px; position: fixed; z-index: 9999999; }

/* Responsive: màn thấp -> co thêm để không scroll */
@media (max-height: 820px) {
  :root { --card-w: 240px; --icon-size: 82px; }
  .hero { margin-top: 1.1rem; }
  main { gap: 1rem; padding: 0.7rem 0 0.25rem; }
}
@media (max-height: 740px) {
  :root { --card-w: 220px; --icon-size: 76px; }
  #page-title { font-size: clamp(20px, 2.2vw, 32px); }
  main { gap: 0.9rem; }
}
/* WEATHER mini widget (side) */
.weather-wrap{
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 30;
  width: 170px;
  pointer-events: auto;
}

.w-mini{
  border-radius: 14px;
  padding: 10px 10px 8px;
  background: rgba(255, 180, 190, 0.85);
  backdrop-filter: blur(10px);
  box-shadow: 0 14px 40px rgba(0,0,0,0.35);
  color: rgba(0,0,0,0.75);
  font-size: 12px;
}

.w-top{
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.w-left{
  display:flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.w-city{
  font-weight: 800;
  font-size: 12px;
  letter-spacing: .2px;
}

.w-date{
  font-weight: 700;
  opacity: .7;
  font-size: 11px;
}

.w-big{
  display: grid;
  grid-template-columns: 52px 1fr;
  column-gap: 10px;
  align-items: center;
}

.w-big-ico svg{
  width: 52px;
  height: 52px;
  fill: rgba(0,0,0,0.65);
  stroke: rgba(0,0,0,0.65);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.w-now{
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}

.w-range{
  font-weight: 700;
  opacity: .7;
  margin-top: 2px;
  font-size: 11px;
}

.w-3{
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.w-d{
  background: rgba(255,255,255,0.35);
  border-radius: 10px;
  padding: 6px 4px;
  text-align: center;
}

.w-dow{
  font-weight: 900;
  font-size: 10px;
  opacity: .75;
}

.w-ico svg{
  width: 22px;
  height: 22px;
  margin: 4px 0 2px;
  fill: rgba(0,0,0,0.6);
  stroke: rgba(0,0,0,0.6);
  stroke-width: 2.5;
}

.w-mm{
  font-weight: 900;
  font-size: 10px;
  opacity: .8;
}

/* nếu bạn sợ che header, có thể tự đẩy xuống khi màn nhỏ */
@media (max-width: 720px), (max-height: 720px){
  /* ✅ trên mobile/portrait: đưa weather vào luồng để không che header & icon */
  .weather-wrap{
    position: static;
    width: min(380px, calc(100vw - 2rem));
    margin: 0.75rem auto 0;
    transform: none;
  }
  .w-mini{ font-size: 11px; }
  .w-big{ grid-template-columns: 44px 1fr; }
  .w-big-ico svg{ width: 44px; height: 44px; }
}
.fx-layer{
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.fx-back{ z-index: 5; }
.fx-front{ z-index: 20; }

.petal{
  transform: translateZ(0);
  filter: drop-shadow(0 10px 18px color-mix(in hsl, black, transparent 70%));
}
/* ===== APP MODAL ===== */
.app-overlay{
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: grid;
  place-items: center;
}

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

.app-backdrop{
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.38);
  backdrop-filter: blur(10px);
  opacity: 0;
  transition: opacity 240ms ease;
}

.app-overlay.is-open .app-backdrop{ opacity: 1; }

.app-window{
  position: relative;
  width: min(80vw, 1100px);
  height: min(80vh, 720px);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 30px 120px rgba(0,0,0,0.55);
  background: light-dark(rgba(255,255,255,0.92), rgba(15,15,15,0.82));
  transform: translateY(10px) scale(0.98);
  opacity: 0;
  transition: transform 280ms cubic-bezier(.2,.8,.2,1), opacity 220ms ease;
  will-change: transform, border-radius;
}

.app-overlay.is-open .app-window{
  transform: translateY(0) scale(1);
  opacity: 1;
}

.app-loader{
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 12px;
  background: light-dark(rgba(255,255,255,0.92), rgba(0,0,0,0.25));
  z-index: 1;
}

.app-loader[hidden]{ display:none; }

.app-loader .spinner{
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 4px solid rgba(255,255,255,0.55);
  border-top-color: rgba(255,77,125,0.95);
  animation: spin 900ms linear infinite;
}

.app-loader .loader-text{
  font: 700 13px/1.2 system-ui, -apple-system, Segoe UI, Roboto, Arial;
  opacity: .75;
}

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

.app-close{
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 0;
  cursor: pointer;
  background: rgba(255,255,255,0.8);
  color: rgba(0,0,0,0.7);
  font-size: 18px;
  font-weight: 900;
}
[data-theme="dark"] .app-close{
  background: rgba(0,0,0,0.35);
  color: rgba(255,255,255,0.85);
}

.app-frame{
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: transparent;
}

/* ghost để animate đóng app về đúng icon (giống iPhone) */
.app-ghost{
  position: fixed;
  z-index: 1000000;
  pointer-events: none;
  overflow: hidden;
  transform: translateZ(0);
  will-change: left, top, width, height, opacity, background-color, border-radius;
}

/* icon “bay ra” */
.fly-icon{
  position: fixed;
  z-index: 1000000;
  pointer-events: none;
  will-change: transform, opacity;
  border-radius: 18px;
  transform-origin: center;
  filter: drop-shadow(0 20px 30px rgba(0,0,0,0.35));
}

/* khi modal mở thì khóa scroll */
body.app-lock{
  overflow: hidden;
}
