:root {
  --navy: #291A6F; --magenta: #D916A8; --coax: #1F5FBF; --green: #2E9E44;
  --bg: #f4f4f7; --card: #fff; --ink: #1b1b1f; --mute: #6b6b75; --line: #dcdce3;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; }
#app { min-height: 100%; display: flex; flex-direction: column; }
button, input, select { font: inherit; }
a { color: var(--navy); }

header.bar { background: var(--navy); color: #fff; padding: calc(var(--sat) + 10px) 12px 10px;
  display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 5; }
header.bar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
header.bar .back { background: none; border: 0; color: #fff; font-size: 22px; padding: 4px 8px 4px 0; }
main { padding: 14px 14px calc(var(--sab) + 24px); display: flex; flex-direction: column; gap: 14px; }

.card { background: var(--card); border-radius: 12px; padding: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--navy); text-transform: uppercase;
  letter-spacing: .04em; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { min-width: 0; }
.grow { flex: 1; }
.mute { color: var(--mute); font-size: 14px; }
.small { font-size: 13px; }

input[type=text], input[type=number], select { width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; }
label.f { display: block; font-size: 13px; color: var(--mute); margin-bottom: 4px; }
.btn { background: var(--navy); color: #fff; border: 0; border-radius: 10px; padding: 12px 16px;
  font-weight: 600; cursor: pointer; }
.btn.sec { background: #e9e8f3; color: var(--navy); }
.btn.danger { background: #fde8ef; color: #b0114f; }
.btn.big { width: 100%; padding: 14px; font-size: 17px; }
.btn:disabled { opacity: .5; }
.btn.icon { padding: 8px 10px; }

.joblist { display: flex; flex-direction: column; gap: 10px; }
.job { display: block; text-decoration: none; color: inherit; }
.job .name { font-weight: 600; }
.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: #eee; color: var(--mute); margin-right: 4px; }
.chip.ok { background: #e3f5e7; color: var(--green); }
.chip.no { background: #fdecec; color: #b3261e; }

.levels { display: flex; flex-direction: column; gap: 10px; }
.level { display: grid; grid-template-columns: 72px 1fr auto; gap: 10px; align-items: center; }
.level img { width: 72px; height: 54px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line);
  background: #fff; }
.level .name { font-weight: 600; width: 100%; padding: 6px 8px; }
.level .ctl { display: flex; flex-direction: column; gap: 4px; }
.level .ctl .row button { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 4px 8px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
th { color: var(--mute); font-weight: 600; font-size: 12px; text-transform: uppercase; }
td.n, th.n { text-align: right; white-space: nowrap; }
tr.tot td { font-weight: 700; border-top: 2px solid var(--navy); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: #f0eff8; border-radius: 10px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 22px; color: var(--navy); }
.stat span { font-size: 12px; color: var(--mute); }
.dl { display: flex; flex-wrap: wrap; gap: 8px; }
.dl a { display: inline-block; background: #e9e8f3; color: var(--navy); text-decoration: none;
  padding: 10px 12px; border-radius: 10px; font-weight: 600; font-size: 14px; }
.overlay-img { width: 100%; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; }
.err { background: #fdecec; color: #8a1c14; border-radius: 10px; padding: 12px; }
details summary { cursor: pointer; font-weight: 600; padding: 6px 0; }

/* ---------- editor ---------- */
.editor { position: fixed; inset: 0; display: flex; flex-direction: column; background: #2a2a2e; }
.editor .bar { padding-top: calc(var(--sat) + 8px); }
.modes { display: flex; gap: 6px; padding: 8px 10px; background: #1d1d21; }
.modes button { flex: 1; background: #3a3a40; color: #fff; border: 0; border-radius: 8px; padding: 10px 4px;
  font-weight: 600; font-size: 14px; }
.modes button.on { background: var(--magenta); }
.modes button.ghost { flex: 0 0 auto; background: #3a3a40; padding: 10px 12px; }
.viewport { flex: 1; position: relative; overflow: hidden; touch-action: none; user-select: none;
  -webkit-user-select: none; cursor: crosshair; }
.stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.stage img { display: block; pointer-events: none; -webkit-user-drag: none; }
.stage svg { position: absolute; left: 0; top: 0; overflow: visible; }
.hint { background: #1d1d21; color: #ddd; font-size: 13px; padding: 8px 12px calc(var(--sab) + 8px);
  text-align: center; min-height: 36px; }
.hint b { color: #fff; }
.sheet { position: absolute; left: 12px; right: 12px; bottom: 12px; background: #fff; border-radius: 12px;
  padding: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.4); z-index: 4; }

#toast { position: fixed; left: 50%; bottom: calc(var(--sab) + 24px); transform: translateX(-50%);
  background: #1b1b1f; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; font-size: 14px;
  max-width: 90vw; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid #fff6; border-top-color: #fff;
  border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

.rules { display: flex; flex-direction: column; gap: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.rule { display: grid; grid-template-columns: 1fr 96px; gap: 10px; align-items: center; padding: 9px 10px;
  border-bottom: 1px solid var(--line); }
.rule:last-child { border-bottom: 0; }
.rule:nth-child(even) { background: #f4f4f9; }
.rule span { font-size: 14px; }
.rule small { display: block; color: var(--mute); font-size: 12px; }
.rule input { text-align: right; padding: 8px 10px; background: #fff; }
.rule:has(input:not(:placeholder-shown)) { background: #fff7e0; }
.rule:has(input:not(:placeholder-shown)) input { border-color: #e0b64a; font-weight: 600; }

.btn.save { background: #3a3a40; color: #cfcbe6; }
.btn.save.dirty { background: var(--green); color: #fff; }

.hint.paused { background: #b7791f; color: #fff; font-size: 16px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { background: #b7791f; } 50% { background: #f0b429; color: #1b1b1f; } }
.nudge { position: absolute; left: 12px; right: 12px; top: 12px; background: #fff; color: #1b1b1f; border-radius: 12px;
  padding: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.4); z-index: 4; display: flex; gap: 10px; align-items: center; }
.nudge b { flex: 1; }
