:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #eceef2;
  --line: rgba(20, 24, 31, 0.1);
  --text: #171a20;
  --dim: #5d6573;
  --accent: #2f6fd6;
  --accent-ink: #ffffff;
  --ok: #1f8a4c;
  --bad: #c2372f;
  --warn: #b7791f;
  --shadow: 0 1px 2px rgba(16, 20, 28, 0.06), 0 4px 14px rgba(16, 20, 28, 0.06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111419;
    --panel: #1a1e25;
    --panel-2: #232831;
    --line: rgba(255, 255, 255, 0.09);
    --text: #e7eaef;
    --dim: #98a1b0;
    --accent: #7fb2f5;
    --accent-ink: #0c1420;
    --ok: #5fcf8e;
    --bad: #f0776f;
    --warn: #e8b04d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111419; --panel: #1a1e25; --panel-2: #232831; --line: rgba(255, 255, 255, 0.09);
  --text: #e7eaef; --dim: #98a1b0; --accent: #7fb2f5; --accent-ink: #0c1420;
  --ok: #5fcf8e; --bad: #f0776f; --warn: #e8b04d;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button { font: inherit; }
.spacer { flex: 1; }
.dim { color: var(--dim); }

/* ---------- header */
.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px max(16px, calc((100vw - 1080px) / 2));
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none; font-weight: 650; font-size: 17px;
}
.brand svg { width: 22px; height: 22px; fill: var(--text); }
.brand svg .alt { fill: var(--accent); }
.mode {
  font-size: 12px; color: var(--dim); border: 1px solid var(--line);
  border-radius: 999px; padding: 2px 9px; white-space: nowrap;
}
.mode:empty { display: none; }
.mode.admin { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }

main {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 16px 40px;
}
.foot {
  padding: 18px 16px 26px; text-align: center; font-size: 13px; color: var(--dim);
}
.foot a, .linkish {
  color: var(--dim); background: none; border: 0; padding: 0; cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px; font-size: 13px;
}

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 7px 14px; border-radius: 9px; cursor: pointer; text-decoration: none;
  font-size: 14px; font-weight: 550; white-space: nowrap;
}
.btn:hover { border-color: color-mix(in srgb, var(--text) 30%, transparent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn[hidden] { display: none; }
.btn:focus-visible, .tile-link:focus-visible, .action:focus-visible, .switch input:focus-visible + span {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---------- headings */
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.page-head p { margin: 6px 0 0; color: var(--dim); max-width: 62ch; }
.crumb { display: inline-flex; align-items: center; gap: 6px; color: var(--dim); text-decoration: none; font-size: 14px; margin-bottom: 10px; }
.crumb:hover { color: var(--text); }
.crumb svg, .btn svg {
  width: 16px; height: 16px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--dim); font-weight: 600; }

/* ---------- app grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 18px;
}
.tile {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.tile:hover { transform: translateY(-2px); }
.tile-link { color: inherit; text-decoration: none; display: flex; flex-direction: column; flex: 1; }
.thumb {
  aspect-ratio: 1 / 1;
  background: var(--panel-2);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .letter { font-size: 64px; font-weight: 750; color: #fff; opacity: 0.95; }
.tile-body { padding: 12px 14px 14px; }
.tile-body h2 { font-size: 16px; font-weight: 650; }
.tile-body p {
  margin: 4px 0 0; font-size: 13px; color: var(--dim);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tile.off .thumb { filter: grayscale(1); opacity: 0.45; }
.tile.off .tile-body h2 { color: var(--dim); }
.tile-admin {
  display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; padding: 9px 14px;
  border-top: 1px solid var(--line); font-size: 13px; color: var(--dim);
}
.badge {
  position: absolute; top: 10px; left: 10px; font-size: 11px; font-weight: 650;
  padding: 2px 8px; border-radius: 999px; background: rgba(0, 0, 0, 0.62); color: #fff;
  letter-spacing: 0.02em;
}

/* ---------- switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch span.track {
  width: 34px; height: 20px; border-radius: 999px; background: var(--panel-2);
  border: 1px solid var(--line); position: relative; transition: background 0.15s;
}
.switch span.track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--dim); transition: transform 0.15s, background 0.15s;
}
.switch input:checked + span.track { background: var(--ok); border-color: var(--ok); }
.switch input:checked + span.track::after { transform: translateX(14px); background: #fff; }

/* ---------- action grid (inside an app) */
.actions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 16px;
}
.action {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  text-align: left; padding: 18px; min-height: 170px;
  background: var(--panel); color: var(--text); text-decoration: none;
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  cursor: pointer; transition: transform 0.12s ease;
}
.action:hover { transform: translateY(-2px); }
.action .icon {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--tone, var(--accent)) 16%, transparent);
  color: var(--tone, var(--accent));
}
.action .icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.action h3 { font-size: 16px; font-weight: 650; }
.action p { margin: 0; font-size: 13px; color: var(--dim); }
.action .last { margin-top: auto; font-size: 12px; color: var(--dim); display: flex; align-items: center; gap: 6px; }
.action.t-open { --tone: var(--accent); }
.action.t-run { --tone: var(--ok); }
.action.t-publish { --tone: #9b6bf2; }
.action.t-access { --tone: var(--warn); cursor: default; }
.action.t-access:hover { transform: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.failed { background: var(--bad); }
.dot.running { background: var(--warn); animation: pulse 1s infinite alternate; }
.dot.stopped { background: var(--dim); }
@keyframes pulse { to { opacity: 0.3; } }

.section-title { margin: 34px 0 12px; font-size: 14px; font-weight: 650; color: var(--dim); }
.runs, .devices { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.runs li + li, .devices li + li { border-top: 1px solid var(--line); }
.runs button {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: none; border: 0; color: var(--text); cursor: pointer; text-align: left;
}
.runs button:hover { background: var(--panel-2); }
.path { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; color: var(--dim); word-break: break-all; }

/* ---------- login */
.login {
  max-width: 360px; margin: 40px auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px;
}
.login h1 { font-size: 22px; margin-bottom: 6px; }
.login p { margin: 0 0 18px; color: var(--dim); font-size: 14px; }
.login label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.login input {
  width: 100%; padding: 9px 12px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; margin-bottom: 14px;
}
.login .err { color: var(--bad); font-size: 13px; min-height: 1.4em; margin: -6px 0 10px; }
.login { max-width: 440px; }

/* ---------- devices */
.devices li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; flex-wrap: wrap; }
.devices .dev { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.devices .dev .dim { font-size: 13px; }
.badge-inline {
  font-size: 11px; font-weight: 650; padding: 1px 8px; border-radius: 999px; margin-left: 6px;
  background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent);
}

.empty {
  text-align: center; padding: 60px 20px; color: var(--dim);
  border: 1px dashed var(--line); border-radius: var(--radius);
}

/* ---------- log sheet */
.sheet {
  position: fixed; inset: 0; z-index: 10; background: rgba(8, 10, 14, 0.55);
  display: grid; place-items: center; padding: 16px;
}
.sheet[hidden] { display: none; }
.sheet-card {
  width: min(900px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); overflow: hidden;
}
.sheet-head, .sheet-foot { display: flex; align-items: center; gap: 12px; padding: 14px 18px; flex-wrap: wrap; }
.sheet-head { border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 18px; }
.sheet-foot { border-top: 1px solid var(--line); font-size: 13px; }
.sheet pre {
  margin: 0; padding: 14px 18px; flex: 1; min-height: 240px; overflow: auto;
  background: #0c0f13; color: #d6dde6;
  font: 12.5px/1.55 ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
  white-space: pre-wrap; word-break: break-word;
}
.pill {
  font-size: 12px; font-weight: 650; padding: 3px 10px; border-radius: 999px;
  background: var(--panel-2); color: var(--dim); display: inline-flex; align-items: center; gap: 6px;
}
.pill.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.pill.failed { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.pill.running { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }

@media (max-width: 520px) {
  main { padding-top: 20px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .actions { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .action { min-height: 150px; padding: 14px; }
  .thumb .letter { font-size: 44px; }
  .page-head h1 { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  .tile, .action { transition: none; }
  .tile:hover, .action:hover { transform: none; }
}
