:root {
  --bg: #f3f1ec;
  --card: #ffffff;
  --text: #1c1b19;
  --muted: #6b675f;
  --line: #dcd8cf;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --ok: #2e7d32;
  --warn: #b26a00;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412;
    --card: #211f1c;
    --text: #f1eee8;
    --muted: #a39e94;
    --line: #38352f;
    --accent: #7fb0ff;
    --accent-text: #0d1b33;
    --danger: #ff8a80;
    --ok: #81c784;
    --warn: #ffb74d;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
header, main { max-width: 560px; margin: 0 auto; padding: 0 16px; }
header { display: flex; align-items: center; justify-content: space-between; padding-top: 18px; padding-bottom: 6px; }
h1 { font-size: 1.35rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
main { padding-bottom: 96px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card h2 { margin-bottom: 0; }

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  text-align: center;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible, .link:focus-visible, input:focus-visible, textarea:focus-visible,
.segmented input:focus-visible + span, .chips input:focus-visible + .chip,
.file:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.link { background: none; border: 0; color: var(--accent); font: inherit; padding: 12px 0 12px 12px; cursor: pointer; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.status { margin: 0; display: flex; align-items: center; gap: 10px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--muted); }
.dot.error { background: var(--danger); }
.dot.busy { background: var(--warn); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .dot.busy { animation: none; } }

.frame-wrap {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 120px;
}
#preview { display: block; max-width: 100%; max-height: 46vh; border: 6px solid #2a2927; border-radius: 3px; background: #fff; }
#preview.dimmed { opacity: 0.3; }
#preview[hidden], #crop[hidden] { display: none; }
.hint { margin: 0; color: var(--muted); font-size: 0.9rem; }

#crop {
  display: block;
  max-width: 100%;
  max-height: 60vh;
  margin: 0 auto;
  border-radius: 6px;
  border: 1px solid var(--line);
  touch-action: none;
  cursor: grab;
}

.segmented { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.segmented.three { grid-template-columns: 1fr 1fr 1fr; }
.field.stacked { flex-direction: column; align-items: stretch; gap: 6px; }
.segmented label { display: block; }
.segmented input, .chips input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: flex; align-items: center; justify-content: center; min-height: 40px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.segmented input:checked + span { background: var(--accent); color: var(--accent-text); }

.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field-name { color: var(--muted); }
.chips { display: flex; gap: 8px; }
.chip { display: block; width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; }
.chips input:checked + .chip { box-shadow: 0 0 0 3px var(--card), 0 0 0 6px var(--accent); }
.c-black { background: #000; } .c-white { background: #fff; } .c-yellow { background: #f5d800; }
.c-red { background: #d32f2f; } .c-blue { background: #1e4fd6; } .c-green { background: #2e9d48; }

textarea, input[type="password"] {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
textarea { resize: vertical; min-height: 84px; }

#toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  max-width: 528px;
  margin: 0 auto;
  padding: 14px 16px;
  border-radius: 12px;
  background: #1c1b19;
  color: #fff;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: none; }
#toast.bad { background: #8c1d18; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

body.login main { padding-top: 12vh; }
body.login form { display: flex; flex-direction: column; gap: 12px; }
body.login label { color: var(--muted); }
.notice { margin: 0; padding: 12px; border-radius: 10px; border: 1px solid var(--line); }
.notice.bad { color: var(--danger); border-color: var(--danger); }
code { font-size: 0.9em; }
