:root {
  --bg0: #0b1020;
  --bg1: #0b0f14;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-2: rgba(255, 255, 255, 0.08);
  --text: #e6eaf2;
  --muted: rgba(230, 234, 242, 0.72);
  --border: rgba(255, 255, 255, 0.12);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --accent: #7c3aed;
  --accent-2: #6366f1;
  --success: #22c55e;
  --danger: #ef4444;
  --radius-lg: 18px;
  --radius: 14px;
  --radius-sm: 12px;
  --maxw: 940px;
  --focus: 0 0 0 4px rgba(124, 58, 237, 0.33);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg0: #f3f6ff;
    --bg1: #f8fafc;
    --surface: rgba(255, 255, 255, 0.78);
    --surface-2: rgba(255, 255, 255, 0.92);
    --text: #0f172a;
    --muted: rgba(15, 23, 42, 0.66);
    --border: rgba(15, 23, 42, 0.12);
    --shadow: 0 12px 36px rgba(2, 6, 23, 0.12);
    --focus: 0 0 0 4px rgba(124, 58, 237, 0.2);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100svh;
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  background:
    radial-gradient(900px 520px at 12% -10%, rgba(124, 58, 237, 0.35), transparent 60%),
    radial-gradient(740px 520px at 100% 0%, rgba(34, 197, 94, 0.18), transparent 55%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
}

a { color: #8ab4f8; color: color-mix(in srgb, var(--accent), var(--text) 12%); }
code {
  font-family: var(--mono);
  font-size: 0.95em;
  padding: 0.12em 0.42em;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  background: color-mix(in srgb, var(--surface-2), transparent 20%);
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  background: color-mix(in srgb, var(--surface-2), transparent 10%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.topbar__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; flex-direction: column; gap: 2px; }
.brand__title { font-weight: 760; letter-spacing: -0.02em; font-size: 1.02rem; }
.brand__sub { color: var(--muted); font-size: 0.9rem; }
.topbar__actions { display: inline-flex; align-items: center; gap: 10px; }

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px 16px 28px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card__header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  background: color-mix(in srgb, var(--surface-2), transparent 14%);
}
.title { margin: 0; font-size: 1.35rem; letter-spacing: -0.02em; }
.subtitle { margin: 8px 0 0; color: var(--muted); line-height: 1.45; }
.card__body { padding: 16px; }

.grid {
  display: grid;
  gap: 16px;
  align-items: start;
}
@media (min-width: 880px) {
  .grid { grid-template-columns: 380px 1fr; }
}

.panel { display: grid; gap: 12px; }

.btnRow { display: flex; gap: 10px; flex-wrap: wrap; }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  background: color-mix(in srgb, var(--surface-2), transparent 12%);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-weight: 650;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, opacity 120ms ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); background: color-mix(in srgb, var(--surface-2), transparent 0%); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: rgba(124, 58, 237, 0.45);
  border-color: color-mix(in srgb, var(--accent), var(--border) 55%);
}
.btn-primary:hover { filter: brightness(1.03); }

.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); background: color-mix(in srgb, var(--surface-2), transparent 2%); }

.btn__spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: rgba(255, 255, 255, 0.95);
  display: none;
  animation: spin 0.8s linear infinite;
}
.btn[data-loading="true"] .btn__spinner { display: inline-block; }

@keyframes spin { to { transform: rotate(360deg); } }

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.meta {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  background: color-mix(in srgb, var(--surface-2), transparent 10%);
}
.meta__label { font-size: 0.83rem; color: var(--muted); }
.meta__value { font-weight: 650; word-break: break-word; }

.status {
  margin: 0;
  display: none;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  background: color-mix(in srgb, var(--surface-2), transparent 8%);
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.status.is-visible { display: block; }
.status[data-tone="success"] {
  border-color: rgba(34, 197, 94, 0.5);
  border-color: color-mix(in srgb, var(--success), var(--border) 40%);
  background: rgba(34, 197, 94, 0.12);
  background: color-mix(in srgb, rgba(34, 197, 94, 0.16), var(--surface-2) 70%);
}
.status[data-tone="error"] {
  border-color: rgba(239, 68, 68, 0.52);
  border-color: color-mix(in srgb, var(--danger), var(--border) 40%);
  background: rgba(239, 68, 68, 0.1);
  background: color-mix(in srgb, rgba(239, 68, 68, 0.14), var(--surface-2) 72%);
}

.hint { margin: 0; color: var(--muted); line-height: 1.45; }

.hintCard {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  background: color-mix(in srgb, var(--surface-2), transparent 10%);
  display: grid;
  gap: 6px;
}
.hintCard__label { font-size: 0.83rem; color: var(--muted); font-weight: 650; }
.hintCard__code { display: block; max-width: 100%; }
.hintCard__sub { color: var(--muted); line-height: 1.45; }

.previewWrap {
  min-height: 320px;
  border-radius: var(--radius);
  border: 1px dashed var(--border);
  border: 1px dashed color-mix(in srgb, var(--border), transparent 10%);
  background: var(--surface-2);
  background: color-mix(in srgb, var(--surface-2), transparent 12%);
  padding: 12px;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}
.previewWrap.has-image { border-style: solid; }
.preview {
  max-width: 100%;
  max-height: min(66vh, 720px);
  display: none;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}
.previewWrap.has-image .preview { display: block; }
.previewWrap.has-image .placeholder { display: none; }

.placeholder {
  text-align: center;
  padding: 10px;
  color: var(--muted);
}
.placeholder__title {
  font-weight: 750;
  color: var(--text);
  color: color-mix(in srgb, var(--text), var(--muted) 40%);
}
.placeholder__sub { margin-top: 6px; line-height: 1.45; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  background: color-mix(in srgb, var(--surface-2), transparent 10%);
  color: var(--muted);
  font-weight: 650;
  font-size: 0.85rem;
  white-space: nowrap;
}
.chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18);
}
.chip-offline .dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.16);
}

.footer {
  margin-top: 14px;
  padding: 8px 2px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.92rem;
}
.footer__link { color: var(--muted); }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 1000;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  background: color-mix(in srgb, var(--surface-2), transparent 12%);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text);
  font-weight: 650;
  line-height: 1.35;
  transform: translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

