/* safezone: styles. Light/dark via prefers-color-scheme, no external assets. */

:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #f1f3f7;
  --text: #0f172a;
  --muted: #5b6477;
  --border: #e2e6ee;
  --accent: #5b5bd6;
  --accent-soft: rgba(91, 91, 214, 0.12);
  --accent-text: #ffffff;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --stage-bg: #dfe3ea;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d12;
    --panel: #141821;
    --panel-2: #1b202b;
    --text: #e7eaf0;
    --muted: #97a0b3;
    --border: #262c39;
    --accent: #8b8cf6;
    --accent-soft: rgba(139, 140, 246, 0.16);
    --accent-text: #0b0d12;
    --ok: #22c55e;
    --warn: #f59e0b;
    --bad: #f87171;
    --stage-bg: #05060a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------- header */

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 16px 8px;
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 26px; height: 26px; color: var(--accent); align-self: center; }
.brand-name { font-size: 20px; font-weight: 750; letter-spacing: -0.02em; }
.tagline { margin: 0; color: var(--muted); font-size: 14px; }

/* ---------------------------------------------------------------- layout */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px;
  align-items: start;
}

.preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 16px;
}

.controls { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .preview { position: static; }
}

/* ----------------------------------------------------------------- stage */

.stage {
  --k: 0.3; /* stage px per frame px, set by app.js */
  position: relative;
  width: min(100%, calc((100vh - 150px) * 9 / 16), 460px);
  min-width: 220px;
  aspect-ratio: 9 / 16;
  border-radius: 18px;
  overflow: hidden;
  background: var(--stage-bg);
  box-shadow: var(--shadow), 0 0 0 1px var(--border);
  user-select: none;
  -webkit-user-select: none;
}

@media (max-width: 860px) {
  .stage { width: min(100%, 420px); }
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.overlay { position: absolute; inset: 0; pointer-events: none; }

.zone {
  --c: #888;
  position: absolute;
  border: 1.5px solid var(--c);
  transition: box-shadow 0.12s ease;
}

.zone::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--c);
  opacity: var(--zone-alpha, 0.45);
}

.zone.is-hit {
  border-color: var(--bad);
  box-shadow: inset 0 0 0 3px var(--bad);
}

.zone.is-hit::before {
  background: repeating-linear-gradient(135deg, var(--bad) 0 8px, transparent 8px 16px), var(--c);
}

.zone-label,
.safe-label {
  position: absolute;
  top: 4px;
  left: 4px;
  max-width: calc(100% - 8px);
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: max(9px, calc(var(--k) * 26px));
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.safe {
  position: absolute;
  border: 2px dashed #22c55e;
  border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.safe-label { background: rgba(22, 101, 52, 0.85); }

/* -------------------------------------------------------------- text box */

.textbox {
  --fs: 64;                 /* font size in frame px, set by app.js */
  --status: #ffffff;
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--status);
  border-radius: 4px;
  cursor: grab;
  touch-action: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.textbox[hidden] { display: none; }
.textbox.is-dragging { cursor: grabbing; }
.textbox:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.textbox[data-status="ok"]   { --status: #22c55e; }
.textbox[data-status="warn"] { --status: #f59e0b; }
.textbox[data-status="bad"]  { --status: #ef4444; background: rgba(239, 68, 68, 0.18); border-style: solid; }

.textbox-text {
  width: 100%;
  padding: 0.2em;
  color: #fff;
  font-family: var(--font);
  font-weight: 800;
  font-size: calc(var(--fs) * var(--k) * 1px);
  line-height: 1.2;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  -webkit-text-stroke: 0.14em rgba(0, 0, 0, 0.85);
  paint-order: stroke fill;
  pointer-events: none;
}

.textbox-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--status);
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  cursor: nwse-resize;
}

/* Larger touch target without a larger visual dot. */
.textbox-handle::after { content: ""; position: absolute; inset: -12px; }

textarea {
  width: 100%;
  min-height: 60px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  resize: vertical;
}

textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
textarea:disabled, input:disabled { opacity: 0.5; }

.status {
  margin: 0;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  background: var(--panel-2);
  color: var(--muted);
}

.status:empty { display: none; }
.status[data-status="ok"]   { color: var(--ok);   background: color-mix(in srgb, var(--ok) 12%, transparent); }
.status[data-status="warn"] { color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.status[data-status="bad"]  { color: var(--bad);  background: color-mix(in srgb, var(--bad) 12%, transparent); }

/* ---------------------------------------------------------------- button */

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}

.btn-primary svg { width: 18px; height: 18px; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.6; cursor: progress; }

/* ---------------------------------------------------------------- legend */

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 13px;
}

.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; background: var(--c); }
.legend i.dashed { background: none; border: 2px dashed #22c55e; }

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.hint { margin: 0; color: var(--muted); font-size: 13px; }
.hint.is-error { color: var(--bad); }

.field { display: flex; flex-direction: column; gap: 6px; }

.field-label {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 550;
}

.field-label output { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 500; }

/* -------------------------------------------------------------- dropzone */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 18px 12px;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.dropzone svg { width: 26px; height: 26px; color: var(--accent); margin-bottom: 4px; }
.dropzone strong { font-size: 14px; }
.dropzone span { color: var(--muted); font-size: 12.5px; }

.dropzone:hover,
body.is-dragging .dropzone {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------ segmented control */

.segmented {
  display: flex;
  padding: 3px;
  gap: 3px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.segmented--wrap { flex-wrap: wrap; }

.segmented button {
  flex: 1 1 auto;
  min-height: 34px;
  padding: 6px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.segmented button:hover { color: var(--text); }

.segmented button[aria-pressed="true"] {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
}

/* ------------------------------------------------------ switches & ranges */

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
}

.switch span { order: -1; }

.switch input {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 38px;
  height: 22px;
  margin: 0;
  border-radius: 999px;
  background: var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.switch input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}

.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }

input[type="range"] { width: 100%; margin: 0; accent-color: var(--accent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------- footer */

.site-footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 8px 16px 28px;
  color: var(--muted);
  font-size: 13px;
}

.site-footer p { margin: 0; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
