:root {
  --bg: #f3f2ee;
  --panel: #ffffff;
  --fg: #1f2320;
  --muted: #6f756f;
  --line: #e1e0d9;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #e4f1ec;
  --bad: #b3261e;
  --bad-soft: #fbe9e7;
  --warn: #b7791f;
  --warn-soft: #fbf0db;
  --shadow: 0 10px 30px rgba(31, 35, 32, 0.14);
  --ui: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font-family: var(--ui); font-size: 14px; line-height: 1.45; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
button.ghost, a.ghost { background: transparent; border-color: transparent; color: var(--muted); text-decoration: none; padding: 7px 10px; border-radius: 8px; }
button.ghost:hover, a.ghost:hover { background: var(--accent-soft); color: var(--fg); }
button:disabled { opacity: 0.45; cursor: default; }
.editor { position: relative; height: 100%; display: flex; flex-direction: column; }

.bar { position: relative; display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.tabs { display: flex; gap: 2px; background: var(--bg); padding: 3px; border-radius: 999px; }
.tabs button { border: 0; background: transparent; padding: 5px 12px; border-radius: 999px; color: var(--muted); }
.tabs button.on { background: var(--panel); color: var(--fg); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.spacer { flex: 1; }
.actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
button.badge { border: 0; cursor: pointer; padding: 3px 10px; }
button.badge:hover { filter: brightness(0.95); }
.answer .problems { display: grid; gap: 6px; }
.answer .problem { display: grid; gap: 2px; padding: 6px 10px; border-radius: 8px; background: var(--warn-soft); }
.answer .problem .detail { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

.status { display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px; border-radius: 999px; background: var(--bg); color: var(--muted); font-size: 13px; min-width: 0; max-width: 40vw; }
.status #status-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status .pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.bar.busy .status { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.bar.busy .status .pulse { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.bar.done .status { background: var(--accent-soft); color: var(--accent); }
.bar.done .status .pulse { background: var(--accent); }
.bar.failed .status { background: var(--bad-soft); color: var(--bad); }
.bar.failed .status .pulse { background: var(--bad); }
.bar.offline .status .pulse { background: var(--warn); }
.steps { display: flex; gap: 4px; }
.steps span { width: 22px; height: 4px; border-radius: 2px; background: var(--line); }
.steps span.on { background: var(--accent); }
.steps span.done { background: var(--accent); opacity: 0.45; }
.progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; background: linear-gradient(90deg, transparent, var(--accent), transparent); background-size: 40% 100%; background-repeat: no-repeat; animation: slide 1.1s linear infinite; display: none; }
.bar.busy .progress { display: block; }
@keyframes slide { from { background-position: -40% 0; } to { background-position: 140% 0; } }
@keyframes pulse { 0%, 100% { transform: scale(0.7); opacity: 0.5; } 50% { transform: scale(1.2); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .progress { animation: none; background: var(--accent); } .bar.busy .status .pulse { animation: none; } }

.frame { position: relative; flex: 1; min-height: 0; padding: 12px 12px 110px; display: flex; justify-content: center; }
iframe { width: 100%; max-width: var(--device-width, 100%); height: 100%; border: 1px solid var(--line); border-radius: 10px; background: #fff; transition: max-width 0.25s ease; }
.frame.device iframe { border-radius: 22px; border-width: 6px; border-color: #2a2d2b; box-shadow: var(--shadow); }
.devices { display: flex; gap: 2px; background: var(--bg); padding: 3px; border-radius: 999px; }
.devices button { border: 0; background: transparent; padding: 4px 10px; border-radius: 999px; color: var(--muted); font-size: 14px; line-height: 1.3; }
.devices button.on { background: var(--panel); color: var(--fg); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
@media (prefers-reduced-motion: reduce) { iframe { transition: none; } }

.float { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); width: min(760px, calc(100% - 32px)); display: grid; gap: 10px; z-index: 5; }
.float > * { min-width: 0; }
.composer { display: flex; align-items: center; gap: 8px; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 6px 6px 16px; box-shadow: var(--shadow); }
.composer input { flex: 1 1 0; width: 0; border: 0; background: transparent; min-width: 0; padding: 8px 0; font-size: 15px; }
.composer input:focus-visible { outline: none; }
.composer .target { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; padding: 4px 8px; border-radius: 999px; white-space: nowrap; max-width: 260px; min-width: 0; overflow: hidden; flex: 0 1 auto; }
.composer .target span { overflow: hidden; text-overflow: ellipsis; }
.composer .target button { border: 0; background: transparent; padding: 0 2px; color: inherit; font-size: 15px; line-height: 1; }
.composer .send { border-radius: 999px; width: 40px; height: 40px; padding: 0; display: grid; place-items: center; flex: none; }
.answer { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); display: grid; gap: 8px; animation: rise 0.25s ease-out; }
.answer.error { border-color: var(--bad); }
.answer .text { white-space: pre-wrap; }
.answer .meta { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.answer .meta button { padding: 3px 9px; font-size: 12px; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .answer { animation: none; } }

.drawer { position: absolute; top: 12px; right: 12px; bottom: 12px; width: min(380px, calc(100% - 24px)); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 16px; overflow: auto; z-index: 6; }
.drawer h3 { margin: 0 0 10px; font-size: 14px; display: flex; align-items: center; justify-content: space-between; }
.drawer h3.later { margin-top: 18px; }
.history .item.live { outline: 2px solid var(--accent); outline-offset: -2px; }
.history .item .tag { font-size: 11px; font-weight: 600; color: var(--accent); }
.history { display: grid; gap: 6px; }
.history .item { display: grid; grid-template-columns: auto 1fr auto; gap: 8px 10px; align-items: baseline; padding: 8px 10px; border-radius: 8px; background: var(--bg); }
.history .item time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.history .item .req { font-weight: 500; overflow-wrap: anywhere; }
.history .item .what { color: var(--muted); font-size: 12px; grid-column: 2; }
.history .item button { font-size: 12px; padding: 3px 8px; }
.empty { color: var(--muted); font-size: 13px; padding: 10px; }

@media (max-width: 720px) {
  body { padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
  .bar { gap: 6px; padding: 6px 10px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .bar::-webkit-scrollbar { display: none; }
  .brand .dot { display: none; }
  .brand { font-size: 13px; flex: none; }
  .tabs { flex: none; }
  .tabs button { padding: 4px 9px; font-size: 13px; }
  .status { position: fixed; left: 50%; transform: translateX(-50%); top: 52px; z-index: 7; display: none; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
  .bar.busy .status, .bar.done .status, .bar.failed .status, .bar.offline .status { display: inline-flex; }
  .steps { display: none; }
  .devices { display: none; }
  .spacer { display: none; }
  .actions { flex: none; margin-left: auto; gap: 2px; }
  .actions .label { display: none; }
  .actions .ghost { padding: 6px 8px; font-size: 16px; }
  .actions #open-preview { display: none; }
  #unpublished { display: none; }
  .frame { padding: 8px 8px 96px; }
  iframe { border-radius: 8px; }
  .float { width: calc(100% - 16px); bottom: calc(10px + env(safe-area-inset-bottom, 0px)); gap: 8px; }
  .composer { padding: 4px 4px 4px 12px; }
  .composer input { font-size: 16px; padding: 10px 0; }
  .composer .target { max-width: 40%; }
  .frame.device iframe { max-width: 100%; border: 1px solid var(--line); border-radius: 8px; box-shadow: none; }
  .composer .send { width: 38px; height: 38px; }
  .answer { padding: 10px 12px; max-height: 45vh; overflow: auto; }
  .drawer { top: 8px; right: 8px; bottom: 8px; width: calc(100% - 16px); padding-bottom: 96px; }
  .history .item { grid-template-columns: auto 1fr; }
  .history .item button { grid-column: 1 / -1; justify-self: start; }
}
