:root {
  color-scheme: light;
  --bg: #f3f4f7;
  --panel: #ffffff;
  --text: #17191c;
  --muted: #686d76;
  --line: #dfe2e7;
  --accent: #ff5a00;
  --accent-text: #ffffff;
  --soft: #fff2ea;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --shadow: 0 20px 60px rgba(0, 0, 0, .10);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101113;
  --panel: #1a1c20;
  --text: #f5f7fa;
  --muted: #aeb4bd;
  --line: #343840;
  --soft: #382419;
  --danger: #ff8f85;
  --danger-bg: #3a1d1b;
  --shadow: 0 20px 60px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.shell {
  min-height: 100vh;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
}
.card {
  width: min(100%, 460px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
h1, h2 { margin: 0; letter-spacing: -.03em; }
h1 { font-size: 30px; }
h2 { font-size: 24px; }
.eyebrow { margin: 0 0 3px; color: var(--accent); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.notice { display: grid; gap: 4px; background: var(--soft); border-radius: 16px; padding: 14px; margin-bottom: 18px; font-size: 14px; }
.notice span, .hint, .offline-state, details p { color: var(--muted); }
label { display: block; margin: 14px 0 6px; font-weight: 700; font-size: 14px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 13px;
  padding: 12px 13px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,90,0,.12); }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.square { width: 48px; min-width: 48px; padding: 12px 0 !important; }
button { border: 0; border-radius: 13px; padding: 12px 14px; cursor: pointer; font-weight: 800; }
.primary { background: var(--accent); color: var(--accent-text); }
.secondary { background: transparent; color: var(--text); border: 1px solid var(--line); }
.danger { background: var(--danger-bg); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }
.full { width: 100%; }
.actions { display: grid; gap: 8px; margin: 16px 0 10px; }
.actions.two { grid-template-columns: 1fr 1fr; }
.link-button { width: 100%; background: transparent; color: var(--muted); font-weight: 600; margin-top: 8px; }
.icon-button { width: 44px; height: 44px; padding: 0; background: transparent; color: var(--text); border: 1px solid var(--line); }
.error { color: var(--danger); font-size: 12px; margin: 5px 0 0; }
.hidden { display: none !important; }
.magic-box { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.magic-box summary { cursor: pointer; font-weight: 800; }
.magic-box p { font-size: 13px; line-height: 1.45; }
.magic-box textarea { margin: 8px 0; resize: vertical; }
.qr-view { text-align: center; }
.qr-button { display: block; margin: 8px auto 18px; padding: 20px; background: #fff; border-radius: 24px; box-shadow: inset 0 0 0 1px #eee; }
#qrcode { width: 256px; height: 256px; display: grid; place-items: center; }
#qrcode img, #qrcode canvas, #qrcode svg { display: block !important; max-width: 100%; height: auto !important; }
.progress { height: 5px; overflow: hidden; background: var(--line); border-radius: 99px; }
.progress span { display: block; height: 100%; background: var(--accent); transform-origin: left; }
.progress span.running { animation: countdown 5s linear infinite; }
@keyframes countdown { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.hint, .offline-state { font-size: 13px; line-height: 1.45; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: #111; color: #fff; border-radius: 99px; padding: 10px 14px; font-size: 13px; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
body.fullscreen-qr .shell { padding: 0; background: #fff; }
body.fullscreen-qr .qr-view { position: fixed; inset: 0; width: 100%; max-width: none; border: 0; border-radius: 0; display: grid; place-items: center; background: #fff; box-shadow: none; z-index: 20; }
body.fullscreen-qr .qr-view > :not(.qr-button) { display: none; }
body.fullscreen-qr .qr-button { margin: 0; box-shadow: none; padding: 8vw; }
body.fullscreen-qr #qrcode { width: min(78vw, 420px); height: min(78vw, 420px); }
body.fullscreen-qr #qrcode img, body.fullscreen-qr #qrcode canvas, body.fullscreen-qr #qrcode svg { width: 100% !important; height: 100% !important; image-rendering: pixelated; }
@media (max-width: 380px) {
  .card { padding: 18px; }
  .actions.two { grid-template-columns: 1fr; }
  #qrcode { width: 230px; height: 230px; }
}
