/* Page chrome. The card itself sits on .stage, which carries the HA theme. */
:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #1d2026; --muted: #646b78; --line: #dfe2e8;
  --accent: #2f6fde; --accent-soft: rgba(47,111,222,.1); --chip: #eef0f4;
  color-scheme: light dark;
}
/* Dark from the system, unless the theme picker chose; the picker sets data-theme. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #0e1013; --panel: #171a1f; --text: #e6e8ec; --muted: #949aa6; --line: #2a2f37;
    --accent: #6a9cff; --accent-soft: rgba(106,156,255,.14); --chip: #22262d; color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #0e1013; --panel: #171a1f; --text: #e6e8ec; --muted: #949aa6; --line: #2a2f37;
  --accent: #6a9cff; --accent-soft: rgba(106,156,255,.14); --chip: #22262d; color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light }
* { box-sizing: border-box }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 Roboto, system-ui, -apple-system, sans-serif }
a { color: var(--accent) }
h1 { font-size: 20px; font-weight: 500; margin: 0 }
h2 { font-size: 13px; font-weight: 500; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em }
h3 { font-size: 13px; font-weight: 500; margin: 0 }
p { margin: 2px 0 0; color: var(--muted) }
.muted { color: var(--muted) }
.ver { font-size: 12px; font-weight: 400; color: var(--muted); font-variant-numeric: tabular-nums }
code, pre, table { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px }

.top { display: flex; align-items: center; gap: 14px; padding: 16px 20px; border-bottom: 1px solid var(--line); background: var(--panel) }
.top > div:not(.seg) { flex: 1; min-width: 0 }
.top .seg button { padding: 4px 9px; font-size: 13px }
.seg.icons button { font-size: 15px; line-height: 1.2 }
.back { text-decoration: none; font-size: 20px; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: var(--chip); color: var(--text) }

.btn { all: unset; cursor: pointer; padding: 7px 12px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 500; font-size: 13px; white-space: nowrap }
.btn.ghost { background: var(--chip); color: var(--text) }
.btn.gh { display: inline-flex; align-items: center; gap: 6px }
.btn.gh svg { width: 16px; height: 16px }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px }

.layout { padding: 20px; max-width: 1400px; margin: 0 auto }
/* States: toggle buttons in two rows, so any state is one tap away. */
.states { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 3px; background: var(--chip); border-radius: 10px; padding: 3px }
.states button { all: unset; cursor: pointer; padding: 8px 10px; border-radius: 7px; text-align: center; font-weight: 500; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.states button:hover { color: var(--text) }
.states button[aria-pressed="true"] { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12) }
.desc b { font-weight: 500; color: var(--text) }

.work { min-width: 0; display: flex; flex-direction: column; gap: 12px }
.bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center }
.seg { display: inline-flex; background: var(--chip); border-radius: 8px; padding: 3px }
.seg button { all: unset; cursor: pointer; padding: 5px 11px; border-radius: 6px; color: var(--muted); font-weight: 500; font-size: 13px }
.seg button small { font-weight: 400; opacity: .7 }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12) }
/* Card options: label above a small segment, so two or three groups fit a phone row. */
/* Card options: one row per section, its name in a narrow column on the left. */
.opts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 12px; align-items: end; margin-top: 4px }
.sec { display: contents }
.sec h4 { margin: 0 0 7px; font-size: 12px; font-weight: 500; color: var(--text) }
.opts .bar { gap: 6px 10px; align-items: flex-end }
.opts .seg button.ic { padding: 3px 6px; display: inline-grid; place-items: center }
.opts .seg button.ic svg { display: block }
.opts #optreset { grid-column: 2; justify-self: start }
.studio { display: flex; flex-direction: column; gap: 14px; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px 16px }
.studio .stage { border: 0; border-radius: 0; padding: 16px 0 }
/* Narrow screens: the card first, then both option halves under it, in the box. */
@media (max-width: 899px) {
  .studio .stage { order: -1 }
}
/* Wider: the box holds the options left and right of the card, in the space beside it. */
@media (min-width: 900px) {
  /* Each half is pinned to its edge of the box and to the top, so picking
     another card width or layout never moves the chips. */
  .studio { display: grid; grid-template-columns: max-content minmax(0, 1fr) max-content; align-items: start; gap: 24px; padding: 20px 24px }
  .studio .opts { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; margin-top: 0 }
  .studio .side-b { justify-self: end }
  .studio .stage { align-self: center }
  .studio .sec { display: flex; flex-direction: column; align-items: flex-start; gap: 6px }
  .studio .sec h4 { margin: 0 }
  .studio .opts .bar { flex-direction: column; align-items: flex-start; gap: 6px }
  .studio .opts #optreset { align-self: flex-start }
}
.grp { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 3px }
.grp > span { font-size: 11px; color: var(--muted); padding-left: 2px }
.opts .seg { padding: 2px; border-radius: 7px }
.opts .seg button { padding: 3px 7px; font-size: 12px; border-radius: 5px }
.opts #optreset { padding: 5px 9px; font-size: 12px }
.sel { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px }
select { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px }
.desc { min-height: 1.4em }

.stage { border-radius: 14px; padding: 32px 16px; display: flex; justify-content: center; border: 1px solid var(--line); overflow: auto }
.frame { max-width: 100%; transition: width .2s }
.err { color: #e2554a; font: 13px ui-monospace, monospace; padding: 12px; border: 1px dashed currentColor; border-radius: 8px }

/* One block for the state: pick it, read it, jump to its events, then play the clock. */
.player { display: flex; flex-direction: column; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px }
.player .desc { margin: 0 4px; font-size: 13px }
.player .events { margin: 0 2px }
.clock { display: flex; align-items: center; gap: 12px; border-top: 1px solid var(--line); padding: 10px 2px 0 }
.reset { all: unset; cursor: pointer; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--chip); color: var(--text); font-size: 17px; flex: none }
.play { all: unset; cursor: pointer; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff; font-size: 13px }
.time { display: flex; flex-direction: column; min-width: 76px; line-height: 1.2; flex: none }
.time b { font-size: 20px; font-weight: 500; font-variant-numeric: tabular-nums }
.time span { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums }
.clock input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent) }

.events { display: flex; flex-wrap: wrap; gap: 6px }
.events button { all: unset; cursor: pointer; padding: 5px 10px; border-radius: 999px; background: var(--chip); font-size: 12px; display: inline-flex; gap: 6px }
.events button b { font-variant-numeric: tabular-nums; font-weight: 500 }
.events button.past { background: var(--accent-soft); color: var(--accent) }

.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; min-width: 0 }
.ph { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px }
pre { margin: 0; white-space: pre-wrap; word-break: break-word }
table { border-collapse: collapse; width: 100% }
td { padding: 4px 6px 4px 0; border-top: 1px solid var(--line); vertical-align: top; word-break: break-all }
td b { font-weight: 500 }

.log { position: fixed; bottom: 16px; left: 50%; transform: translate(-50%, 20px); opacity: 0; transition: .2s; background: var(--text); color: var(--bg);
  padding: 8px 14px; border-radius: 8px; font: 12px ui-monospace, monospace; pointer-events: none; max-width: calc(100% - 32px) }
.log.show { opacity: 1; transform: translate(-50%, 0) }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(460px, 100%), 1fr)); gap: 16px; padding: 20px; max-width: 1280px; margin: 0 auto }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; display: flex; flex-direction: column }
.tile iframe { border: 0; width: 100%; height: 220px; display: block }
.tile .meta { padding: 12px 14px 14px; border-top: 1px solid var(--line) }
.tile h2 { text-transform: none; letter-spacing: 0; font-size: 16px; color: var(--text); margin: 0 }
.tile h2 a { color: inherit; text-decoration: none }
/* The whole tile opens the widget: the title link stretches over it, the
   download link stays on top. */
.tile { position: relative; transition: border-color .15s }
.tile h2 a::after { content: ""; position: absolute; inset: 0; z-index: 1 }
.tile:hover { border-color: color-mix(in srgb, var(--text) 35%, var(--line)) }
.tile .meta a[download] { position: relative; z-index: 2 }

body.embed { background: transparent }
body.embed .stage { border: 0; border-radius: 0; padding: 20px 16px }

@media (max-width: 760px) {
  .layout { padding: 16px }
  .states button { padding: 8px 4px; font-size: 12px }
  .top { padding: 12px 16px }
  .top p { display: none }
  .top { gap: 8px }
  .top h1 { font-size: 16px }
  .top .ver { display: none }
  .top .btn { padding: 6px 10px }
  .top .seg button { padding: 4px 7px }
  .wide-only { display: none }
  .gallery { padding: 16px }
}
