:root {
  --navy: #0f2a4a; --accent: #b8892b; --bg: #f4f6f9; --card: #ffffff; --ink: #1f2937; --muted: #6b7280;
  --line: #e5e7eb; --ok: #16a34a; --warn: #b91c1c; --radius: 14px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif; }
body { padding-bottom: var(--safe-b); }
.screen { display: none; max-width: 820px; margin: 0 auto; padding: 0 16px 32px; }
.screen.active { display: block; }
.screen.fill.active { display: flex; flex-direction: column; height: 100vh; height: 100dvh; padding-bottom: 0; max-width: none; }
.top { display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; padding: calc(var(--safe-t) + 8px) 0 8px; }
.top h1 { text-align: center; font-size: 20px; margin: 0; color: var(--navy); }
h2 { font-size: 17px; color: var(--navy); margin: 22px 0 8px; }
button, .filebtn {
  font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--navy); border-radius: var(--radius);
  padding: 13px 16px; font-weight: 600; cursor: pointer; text-align: center; display: inline-block; min-height: 48px;
}
button:disabled { opacity: .45; }
button.primary, .filebtn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
button.warn { color: var(--warn); border-color: #fecaca; }
button.big, .filebtn.big { padding: 18px; font-size: 19px; width: 100%; }
button.small, .filebtn.small { padding: 8px 12px; min-height: 40px; font-size: 15px; }
button.icon { width: 44px; height: 44px; min-height: 0; padding: 0; border-radius: 50%; font-size: 22px; }
.filebtn input { display: none; }
.stack { display: flex; flex-direction: column; gap: 12px; margin: 16px 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.row-actions { flex-direction: row; flex-wrap: wrap; }
.row-actions button { flex: 1 1 140px; }
.banner { background: var(--navy); color: #fff; border-radius: var(--radius); padding: 18px; margin-top: 8px; }
.ev-name { font-size: 22px; font-weight: 700; }
.ev-sub { opacity: .8; }
.muted { color: var(--muted); }
.small { font-size: 14px; } .tiny { font-size: 12px; margin: 4px 0 0; }
.center { text-align: center; }
.tips { background: var(--card); border-radius: var(--radius); padding: 14px 14px 14px 34px; border: 1px solid var(--line); }
.tips li { margin: 6px 0; }
.form label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0; }
.form textarea { display: block; width: 100%; font: inherit; font-size: 16px; padding: 12px; margin-top: 4px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); resize: vertical; }
.form input, .form select { display: block; width: 100%; font: inherit; font-size: 17px; padding: 12px; margin-top: 4px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
.logo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#logo-preview { width: 84px; height: 84px; border: 1px dashed var(--line); border-radius: 10px; display: grid; place-items: center; background: #fff; overflow: hidden; }
#logo-preview img { max-width: 100%; max-height: 100%; }

/* editor */
#editor-host { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; background: #0b1220; position: relative; overflow: hidden; }
.stage { position: relative; }
.stage canvas, .stage svg { position: absolute; left: 0; top: 0; }
.loupe { display: none; position: absolute; border-radius: 50%; box-shadow: 0 6px 24px rgba(0,0,0,.5); pointer-events: none; z-index: 5; }
.pt-tag { display: none; position: absolute; background: rgba(15,42,74,.92); color: #fff; font-size: 13px; padding: 4px 8px; border-radius: 8px; pointer-events: none; z-index: 6; width: 160px; text-align: center; }
.editbar { background: var(--card); border-top: 1px solid var(--line); padding: 8px 12px calc(8px + var(--safe-b)); }
.editbar-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.editbar-row #edit-count { flex: 1; text-align: center; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; }
.chip { flex: none; font-size: 12px; padding: 4px 8px; border-radius: 999px; background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; }
.chip.ok { background: #fefce8; color: #713f12; border-color: #fde047; }

/* report */
#report-pages { display: flex; flex-direction: column; gap: 16px; }
.page { width: 100%; height: auto; background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.12); border-radius: 4px; }

/* event + history */
.person-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: 8px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 8px 0; }
.pr-name { display: flex; flex-direction: column; }
.tog { display: inline-flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 10px; border: 1px solid var(--line); font-size: 15px; }
.tog input { width: 22px; height: 22px; accent-color: var(--ok); }
.hist-group { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin: 12px 0; overflow: hidden; }
.hist-head { display: flex; gap: 10px; align-items: center; padding: 12px; border-bottom: 1px solid var(--line); }
.hist-head .muted { flex: 1; }
.hist-row { display: flex; justify-content: space-between; width: 100%; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: none; color: var(--ink); font-weight: 500; text-align: left; }

/* research */
.study { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.study-top { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 12px; background: var(--navy); color: #fff; border-radius: 999px; padding: 3px 8px; }
.tag.soft { background: #e0e7ff; color: #3730a3; }
.study-finding { font-size: 17px; font-weight: 600; }
.study-cite { font-size: 13px; color: var(--muted); }

.prose { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 18px 14px; }
.prose li { margin: 6px 0; }

.modal { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 50; align-items: center; justify-content: center; padding: 16px; }
.modal.on { display: flex; }
.modal-card { background: #fff; border-radius: 18px; padding: 20px; width: 100%; max-width: 460px; }
.modal-card h3 { margin: 0 0 8px; color: var(--navy); }
.modal-card label { display: block; font-size: 14px; color: var(--muted); margin-top: 12px; }
.modal-card input { display: block; width: 100%; font: inherit; padding: 12px; margin-top: 4px; border: 1px solid var(--line); border-radius: 10px; }
.modal-buttons { display: flex; gap: 10px; margin-top: 18px; }
.modal-buttons button { flex: 1; }
.busy { display: none; position: fixed; inset: 0; background: rgba(255,255,255,.8); z-index: 60; align-items: center; justify-content: center; flex-direction: column; gap: 12px; font-weight: 600; color: var(--navy); }
.busy.on { display: flex; }
.spinner { width: 42px; height: 42px; border: 4px solid #cbd5e1; border-top-color: var(--navy); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%) translateY(120px); background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 70; transition: transform .25s; max-width: 92vw; text-align: center; }
.toast.on { transform: translateX(-50%) translateY(0); }
@media (max-width: 520px) {
  .person-row { grid-template-columns: 1fr auto auto; }
  .person-row [data-open] { grid-column: 1 / -1; }
  .row3 { grid-template-columns: 1fr 1fr; }
}
