:root{
  --bg:#060504;
  --bg2:#15100b;
  --surface:rgba(255,255,255,.055);
  --surface2:rgba(255,255,255,.03);
  --line:rgba(218,170,82,.22);
  --line-strong:rgba(240,198,106,.62);
  --gold:#d9aa52;
  --gold2:#f0c66a;
  --cream:#f4ead9;
  --muted:#a99b84;
  --danger:#ff7474;
  --ok:#8fe6a6;
  --busy:#88bfff;
}

*{box-sizing:border-box}

html,
body{
  margin:0;
  min-height:100%;
  background:
    radial-gradient(circle at 16% 4%, rgba(92,43,20,.45), transparent 30%),
    radial-gradient(circle at 86% 12%, rgba(217,170,82,.14), transparent 26%),
    linear-gradient(135deg,var(--bg2),var(--bg) 68%);
  color:var(--cream);
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
}

body{
  min-height:100dvh;
  overflow:auto;
  -webkit-tap-highlight-color:transparent;
}

button{
  appearance:none;
  font:inherit;
}

.control-shell{
  width:100%;
  min-height:100dvh;
  padding:14px max(16px, env(safe-area-inset-right)) 14px max(16px, env(safe-area-inset-left));
  display:grid;
  grid-template-rows:40px auto auto auto auto;
  gap:14px;
}

.status-strip{
  display:grid;
  grid-template-columns:1fr auto auto auto auto;
  align-items:center;
  gap:14px;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:.1em;
  font-size:12px;
}

.brand-mark{
  color:var(--gold2);
  font-weight:900;
  letter-spacing:.24em;
}

#current-time{
  color:var(--cream);
  font-size:22px;
  font-weight:800;
  letter-spacing:.03em;
}

#ha-status.ok{color:var(--ok)}
#ha-status.error{color:var(--danger)}

.fresh-pull{
  min-height:28px;
  border:1px solid rgba(240,198,106,.34);
  border-radius:999px;
  background:rgba(0,0,0,.24);
  color:var(--gold2);
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:0 11px;
  text-decoration:none;
  text-transform:uppercase;
  letter-spacing:.1em;
  font-size:10px;
  font-weight:900;
  box-shadow:0 8px 18px rgba(0,0,0,.18);
  transition:border-color .14s ease, background .14s ease;
}

.fresh-pull:hover{
  border-color:rgba(240,198,106,.62);
  background:rgba(217,170,82,.1);
}

h1,
h2,
h3,
p{
  margin:0;
}

.panel{
  min-height:0;
  border:1px solid var(--line);
  border-radius:8px;
  background:rgba(0,0,0,.18);
  padding:12px;
  overflow:hidden;
}

.section-heading{
  height:24px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  margin-bottom:10px;
}

.section-heading h2{
  color:var(--gold2);
  text-transform:uppercase;
  letter-spacing:.14em;
  font-size:12px;
  font-weight:900;
}

.panel-action{
  min-height:28px;
  border:1px solid rgba(255,116,116,.38);
  border-radius:6px;
  background:rgba(255,116,116,.09);
  color:#ffc9c9;
  text-transform:uppercase;
  letter-spacing:.08em;
  font-size:10px;
  font-weight:900;
  cursor:pointer;
}

.device-grid{
  display:grid;
  grid-template-columns:repeat(6, minmax(0, 1fr));
  grid-auto-rows:minmax(166px, 1fr);
  gap:12px;
}

.device-card,
.scene-card{
  position:relative;
  min-width:0;
  border:1px solid rgba(218,170,82,.18);
  border-radius:8px;
  background:
    linear-gradient(145deg,rgba(255,255,255,.078),rgba(255,255,255,.026)),
    rgba(0,0,0,.18);
  color:var(--cream);
  box-shadow:0 14px 30px rgba(0,0,0,.28);
  cursor:pointer;
  touch-action:manipulation;
  user-select:none;
  transition:transform .14s ease, border-color .14s ease, background .14s ease, opacity .14s ease, box-shadow .14s ease;
}

.device-card{
  min-height:0;
  padding:12px;
  display:grid;
  grid-template-rows:24px minmax(86px, 1fr) minmax(36px, auto) 36px;
  gap:8px;
  text-align:center;
}

.device-card img{
  align-self:center;
  justify-self:center;
  width:100%;
  height:min(122px, 12vh);
  object-fit:contain;
  filter:drop-shadow(0 12px 16px rgba(0,0,0,.36));
}

.device-card h3{
  color:var(--cream);
  font-size:15px;
  line-height:1.1;
  letter-spacing:.01em;
  align-self:center;
}

.status-pill{
  justify-self:center;
  max-width:100%;
  border:1px solid rgba(255,255,255,.1);
  border-radius:999px;
  padding:5px 9px;
  color:var(--muted);
  background:rgba(0,0,0,.28);
  text-transform:uppercase;
  letter-spacing:.08em;
  font-size:10px;
  font-weight:900;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.status-pill::before{
  content:"";
  display:inline-block;
  width:7px;
  height:7px;
  margin-right:6px;
  border-radius:50%;
  background:currentColor;
  vertical-align:1px;
}

.status-pill.on{color:var(--ok);border-color:rgba(143,230,166,.34)}
.status-pill.playing{color:var(--ok);border-color:rgba(143,230,166,.34)}
.status-pill.paused{color:var(--busy);border-color:rgba(136,191,255,.34)}
.status-pill.idle{color:var(--gold2);border-color:rgba(240,198,106,.38)}
.status-pill.off{color:var(--muted)}
.status-pill.ready{color:var(--gold2);border-color:rgba(240,198,106,.38)}

.device-action{
  align-self:end;
  display:flex;
  align-items:center;
  justify-content:center;
  min-height:36px;
  border:1px solid var(--line-strong);
  border-radius:6px;
  background:rgba(217,170,82,.11);
  color:var(--gold2);
  text-transform:uppercase;
  letter-spacing:.1em;
  font-size:11px;
  font-weight:900;
  pointer-events:none;
}

.now-enjoying{
  min-height:340px;
}

.now-card{
  min-height:340px;
  display:grid;
  grid-template-columns:clamp(250px, 24vw, 320px) minmax(320px, 1fr) minmax(300px, .76fr);
  gap:26px 30px;
  align-items:center;
  border:1px solid rgba(218,170,82,.18);
  border-radius:8px;
  background:
    radial-gradient(circle at 12% 16%, rgba(240,198,106,.12), transparent 32%),
    linear-gradient(145deg,rgba(255,255,255,.07),rgba(255,255,255,.025)),
    rgba(0,0,0,.2);
  box-shadow:0 14px 30px rgba(0,0,0,.24);
  padding:22px;
}

.now-card--video,
.now-card--empty{
  grid-template-columns:clamp(330px, 34vw, 440px) minmax(320px, 1fr) minmax(300px, .76fr);
}

.now-card--poster,
.now-card--album{
  grid-template-columns:clamp(250px, 24vw, 320px) minmax(320px, 1fr) minmax(300px, .76fr);
}

.now-art-shell{
  position:relative;
  width:100%;
  max-height:320px;
  padding:10px;
  border-radius:10px;
  background:
    linear-gradient(145deg, rgba(255,255,255,.07), rgba(255,255,255,.018)),
    rgba(0,0,0,.22);
  border:1px solid rgba(218,170,82,.22);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.08),
    0 22px 38px rgba(0,0,0,.34),
    0 0 32px rgba(218,170,82,.08);
}

.now-art{
  position:relative;
  width:100%;
  height:100%;
  display:grid;
  place-items:center;
  overflow:hidden;
  isolation:isolate;
  border:1px solid rgba(255,255,255,.1);
  border-radius:8px;
  background:
    linear-gradient(145deg, rgba(255,255,255,.07), rgba(255,255,255,.018)),
    rgba(0,0,0,.34);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.08),
    inset 0 -18px 42px rgba(0,0,0,.28);
}

.poster-art{
  aspect-ratio:2 / 3;
}

.video-art{
  aspect-ratio:16 / 9;
  max-height:none;
}

.album-art{
  aspect-ratio:1 / 1;
}

.empty-art,
.now-art[data-failed="true"]{
  background:
    radial-gradient(circle at 30% 18%, rgba(240,198,106,.12), transparent 34%),
    linear-gradient(145deg, rgba(255,255,255,.06), rgba(255,255,255,.014)),
    rgba(0,0,0,.34);
}

.now-art-bg,
.now-art-main{
  display:block;
  grid-area:1 / 1;
  min-width:0;
  min-height:0;
}

.now-art-bg{
  z-index:0;
  width:112%;
  height:112%;
  object-fit:cover;
  filter:blur(18px) saturate(1.14);
  opacity:.46;
  transform:scale(1.08);
}

.now-art::after{
  content:"";
  position:absolute;
  inset:0;
  z-index:1;
  pointer-events:none;
  background:
    radial-gradient(circle at 50% 42%, transparent 28%, rgba(0,0,0,.26) 72%),
    linear-gradient(180deg, rgba(255,255,255,.08), transparent 24%, rgba(0,0,0,.26));
}

.now-art-main{
  z-index:2;
  max-width:88%;
  max-height:88%;
  object-fit:contain;
  border-radius:6px;
  box-shadow:0 18px 30px rgba(0,0,0,.44);
}

.poster-art .now-art-main{
  max-width:82%;
  max-height:90%;
}

.video-art .now-art-main{
  max-width:92%;
  max-height:84%;
}

.album-art .now-art-main{
  max-width:86%;
  max-height:86%;
}

.now-art[data-failed="true"] .now-art-bg,
.now-art[data-failed="true"] .now-art-main{
  display:none;
}

.now-copy{
  min-width:0;
  align-self:center;
}

.now-topline{
  display:flex;
  align-items:center;
  gap:8px;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:.08em;
  font-size:10px;
  font-weight:900;
}

.now-copy h3{
  margin-top:14px;
  color:var(--cream);
  font-size:clamp(40px, 5vw, 68px);
  line-height:1;
  overflow-wrap:anywhere;
}

.now-subtitle{
  margin-top:10px;
  color:var(--muted);
  font-size:17px;
  line-height:1.3;
}

.now-synopsis{
  margin-top:14px;
  max-width:68ch;
  display:-webkit-box;
  -webkit-line-clamp:2;
  -webkit-box-orient:vertical;
  overflow:hidden;
  color:rgba(244,234,217,.78);
  font-size:14px;
  line-height:1.42;
}

.now-meta{
  margin-top:14px;
  display:flex;
  flex-wrap:wrap;
  gap:6px;
}

.now-source-meta{
  margin-top:8px;
}

.now-transport{
  margin-top:16px;
  display:flex;
  flex-wrap:wrap;
  gap:9px;
}

.now-control{
  width:auto;
  min-width:78px;
  height:42px;
  border:1px solid rgba(240,198,106,.32);
  border-radius:999px;
  background:
    linear-gradient(145deg, rgba(255,255,255,.065), rgba(255,255,255,.018)),
    rgba(0,0,0,.3);
  color:var(--gold2);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.08), 0 10px 18px rgba(0,0,0,.24);
  cursor:pointer;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:7px;
  padding:0 13px;
  line-height:1;
  font-size:15px;
  font-weight:900;
  transition:transform .14s ease, border-color .14s ease, background .14s ease;
}

.now-control span{
  font-size:13px;
  line-height:1;
}

.now-control:hover:not(:disabled){
  border-color:rgba(240,198,106,.58);
  background:rgba(217,170,82,.12);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.1), 0 0 16px rgba(240,198,106,.12);
}

.now-control:active,
.now-control.is-pressed{
  transform:scale(.95);
}

.now-control:focus-visible{
  outline:2px solid var(--gold2);
  outline-offset:2px;
}

.now-volume{
  min-width:0;
  display:grid;
  gap:8px;
}

.now-volume span{
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap:10px;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:.08em;
  font-size:10px;
  font-weight:900;
}

.now-volume b{
  color:var(--gold2);
  font-size:12px;
}

.now-volume input{
  width:100%;
  accent-color:var(--gold2);
}

.now-meta span,
.now-detail-pill,
.now-empty{
  border:1px solid rgba(255,255,255,.1);
  border-radius:999px;
  padding:5px 9px;
  background:rgba(0,0,0,.22);
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:.07em;
  font-size:9px;
  font-weight:900;
}

.now-detail-pill{
  border-color:rgba(240,198,106,.2);
  background:rgba(217,170,82,.075);
  color:rgba(244,234,217,.8);
}

.now-details{
  min-width:0;
  align-self:stretch;
  border-left:1px solid rgba(218,170,82,.18);
  padding-left:24px;
  display:flex;
  flex-direction:column;
  justify-content:space-between;
  gap:18px;
}

.now-detail-stack{
  min-width:0;
  display:flex;
  flex-direction:column;
  justify-content:center;
  gap:14px;
}

.now-badges{
  display:flex;
  flex-wrap:wrap;
  gap:6px;
}

.now-badges span{
  border:1px solid rgba(240,198,106,.25);
  border-radius:999px;
  padding:5px 8px;
  background:rgba(217,170,82,.08);
  color:var(--gold2);
  text-transform:uppercase;
  letter-spacing:.07em;
  font-size:9px;
  font-weight:900;
}

.now-progress{
  display:grid;
  gap:8px;
}

.now-progress span{
  height:10px;
  overflow:hidden;
  border-radius:999px;
  background:rgba(255,255,255,.08);
}

.now-progress i{
  display:block;
  height:100%;
  min-width:3px;
  border-radius:inherit;
  background:linear-gradient(90deg,var(--gold),var(--gold2));
}

.now-progress em{
  color:var(--muted);
  font-style:normal;
  text-transform:uppercase;
  letter-spacing:.07em;
  font-size:10px;
  font-weight:900;
}

.now-details dl{
  margin:0;
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:8px 12px;
}

.now-details div{
  min-width:0;
}

.now-details dt{
  color:rgba(169,155,132,.82);
  text-transform:uppercase;
  letter-spacing:.08em;
  font-size:8px;
  font-weight:900;
}

.now-details dd{
  margin:2px 0 0;
  color:var(--cream);
  font-size:11px;
  font-weight:800;
  line-height:1.18;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.now-summary{
  display:-webkit-box;
  -webkit-line-clamp:3;
  -webkit-box-orient:vertical;
  overflow:hidden;
  color:var(--muted);
  font-size:11px;
  line-height:1.35;
}

.now-empty{
  min-height:92px;
  display:flex;
  align-items:center;
  justify-content:center;
  border-radius:8px;
}

.scene-grid{
  display:grid;
  grid-template-columns:repeat(7, minmax(0, 1fr));
  grid-auto-rows:minmax(178px, 1fr);
  gap:12px;
}

.scene-card{
  min-height:0;
  padding:12px 10px 10px;
  display:grid;
  grid-template-rows:minmax(104px, 1fr) minmax(34px, auto) 18px;
  align-items:center;
  text-align:center;
}

.scene-card img{
  width:100%;
  height:min(132px, 13vh);
  object-fit:contain;
  margin:auto;
  filter:drop-shadow(0 12px 16px rgba(0,0,0,.34));
}

.scene-card strong{
  display:block;
  color:var(--cream);
  font-size:14px;
  line-height:1.12;
}

.scene-card span{
  display:block;
  min-height:16px;
  margin-top:4px;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:.08em;
  font-size:9px;
  font-weight:900;
}

.area-light-grid{
  display:grid;
  grid-template-columns:repeat(4, minmax(0, 1fr));
  gap:12px;
}

.area-light-card{
  min-width:0;
  min-height:248px;
  border:1px solid rgba(218,170,82,.18);
  border-radius:8px;
  background:
    radial-gradient(circle at 50% 12%, rgba(240,198,106,.14), transparent 32%),
    linear-gradient(145deg,rgba(255,255,255,.07),rgba(255,255,255,.025)),
    rgba(0,0,0,.2);
  box-shadow:0 14px 30px rgba(0,0,0,.28);
  padding:12px;
  display:grid;
  grid-template-rows:auto auto auto 1fr;
  gap:10px;
}

.area-light-card.is-lit{
  border-color:rgba(240,198,106,.42);
  box-shadow:0 18px 34px rgba(0,0,0,.3), inset 0 0 34px rgba(217,170,82,.08);
}

.area-light-card.is-missing{
  opacity:.48;
}

.light-card-top{
  min-width:0;
  display:grid;
  grid-template-columns:auto 1fr;
  align-items:center;
  gap:6px 8px;
}

.light-card-top .status-pill{
  justify-self:start;
}

.light-card-top h3{
  min-width:0;
  color:var(--cream);
  font-size:17px;
  line-height:1.05;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.light-card-top span:last-child{
  grid-column:1 / -1;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:.08em;
  font-size:9px;
  font-weight:900;
}

.light-master{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:8px;
}

.light-master button,
.preset-row button{
  min-width:0;
  min-height:36px;
  border:1px solid var(--line-strong);
  border-radius:6px;
  background:rgba(217,170,82,.11);
  color:var(--gold2);
  text-transform:uppercase;
  letter-spacing:.08em;
  font-size:10px;
  font-weight:900;
  cursor:pointer;
}

.light-master button[data-power="off"]{
  border-color:rgba(255,255,255,.12);
  background:rgba(0,0,0,.24);
  color:var(--muted);
}

.dimmer-control{
  min-width:0;
  display:grid;
  gap:7px;
}

.dimmer-control span{
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap:8px;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:.08em;
  font-size:9px;
  font-weight:900;
}

.dimmer-control b{
  color:var(--gold2);
  font-size:18px;
  letter-spacing:0;
}

.dimmer-control input{
  width:100%;
  accent-color:var(--gold2);
}

.light-capability{
  align-self:center;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:.08em;
  font-size:9px;
  font-weight:900;
}

.preset-row{
  align-self:end;
  display:grid;
  grid-template-columns:repeat(auto-fit, minmax(66px, 1fr));
  gap:8px;
}

.preset-row:empty{
  display:block;
}

.preset-row button{
  display:grid;
  place-items:center;
  gap:2px;
  padding:6px 5px;
}

.preset-row button span{
  color:var(--muted);
  font-size:8px;
  letter-spacing:.06em;
}

.device-card:active,
.scene-card:active,
.panel-action:active,
.light-master button:active,
.preset-row button:active,
.is-pressed{
  transform:scale(.975);
}

.device-card:focus-visible,
.scene-card:focus-visible,
.panel-action:focus-visible,
.light-master button:focus-visible,
.preset-row button:focus-visible,
.dimmer-control input:focus-visible{
  outline:2px solid var(--gold2);
  outline-offset:2px;
}

.device-card:hover,
.scene-card:hover,
.panel-action:hover,
.light-master button:hover,
.preset-row button:hover{
  border-color:rgba(240,198,106,.48);
}

.is-busy{
  border-color:var(--busy);
  color:var(--busy);
  opacity:.78;
}

.is-success{
  border-color:var(--ok);
}

.is-error{
  border-color:var(--danger);
}

button:disabled,
.scene-card[disabled],
.dimmer-control input:disabled,
.now-volume input:disabled,
.now-control:disabled{
  cursor:not-allowed;
  opacity:.42;
}

@media (max-width:1180px){
  body{overflow:auto}

  .control-shell{
    height:auto;
    min-height:100dvh;
    grid-template-rows:auto auto auto auto auto;
  }

  .device-grid{
    height:auto;
    grid-template-columns:repeat(3, minmax(0, 1fr));
    grid-auto-rows:minmax(160px, auto);
  }

  .scene-grid{
    height:auto;
    grid-template-columns:repeat(4, minmax(0, 1fr));
    grid-auto-rows:minmax(160px, auto);
  }

  .area-light-grid{
    grid-template-columns:repeat(2, minmax(0, 1fr));
  }

  .now-card{
    grid-template-columns:220px minmax(0, 1fr);
    min-height:300px;
  }

  .now-card--video{
    grid-template-columns:minmax(260px, 320px) minmax(0, 1fr);
  }

  .now-card--poster,
  .now-card--album{
    grid-template-columns:220px minmax(0, 1fr);
  }

  .now-details{
    grid-column:1 / -1;
    border-left:0;
    border-top:1px solid rgba(218,170,82,.16);
    padding:12px 0 0;
    gap:12px;
  }

  .now-enjoying{
    min-height:300px;
  }
}

@media (max-width:720px){
  .status-strip{
    grid-template-columns:1fr;
    gap:4px;
  }

  .device-grid,
  .scene-grid,
  .area-light-grid{
    grid-template-columns:1fr;
  }

  .section-heading{
    height:auto;
    min-height:24px;
    gap:10px;
    align-items:flex-start;
    flex-direction:column;
  }

  .now-card{
    grid-template-columns:160px minmax(0, 1fr);
    min-height:240px;
    gap:16px;
    padding:16px;
  }

  .now-card--video{
    grid-template-columns:minmax(170px, 210px) minmax(0, 1fr);
  }

  .now-card--poster,
  .now-card--album{
    grid-template-columns:160px minmax(0, 1fr);
  }

  .now-enjoying{
    min-height:240px;
  }

  .poster-art,
  .album-art{
    max-height:180px;
  }

  .now-details dl{
    grid-template-columns:1fr;
  }

  .now-copy h3{
    font-size:clamp(28px, 8vw, 42px);
  }

  .now-subtitle,
  .now-synopsis{
    font-size:14px;
  }

  .now-control{
    min-width:70px;
    height:38px;
    padding:0 11px;
  }
}
