:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #111114;
  --text: #f5f5f7;
  --muted: #98989f;
  --accent: #14b28a;
  --accent-dim: #1f4a3d;
  --accent-dim-text: #7fcbb6;
  --cta: #f6c343;
  --cta-text: #2b1d00;
  --cta-dim: #6b5a1a;
  --cta-dim-text: #d9c48f;
  --dotted: #303036;
  --border: #2c2c32;
  --placeholder: #6a6a72;
  --disabled-bg: #0a0a0c;
  --disabled-text: #55555c;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f4f4f7;
  --text: #16161a;
  --muted: #6b6b74;
  --accent: #0c8a6a;
  --accent-dim: #d9f0e9;
  --accent-dim-text: #5fa593;
  --cta: #f6c343;
  --cta-text: #3d2900;
  --cta-dim: #f8e9bd;
  --cta-dim-text: #a68a3f;
  --dotted: #d9d9de;
  --border: #d7d7dd;
  --placeholder: #9a9aa2;
  --disabled-bg: #ececef;
  --disabled-text: #a9a9b1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  transition: background 0.2s ease, color 0.2s ease;
}

body { padding-bottom: 96px; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 14px 20px;
  background: var(--bg);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

/* ---------- screen ---------- */
.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 20px;
}

.screen[hidden] { display: none; }

.brand-logo {
  display: block;
  width: 180px;
  max-width: 60%;
  height: auto;
  margin: 8px auto 20px;
}

:root[data-theme="dark"] .brand-logo { filter: invert(1); }

h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 8px 0 12px;
}

.lead {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
  margin: 0 0 24px;
}

.section-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 4px;
}

/* ---------- form ---------- */
form {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

label {
  font-size: 14px;
  font-weight: 600;
  margin-top: 14px;
  color: var(--text);
}

input, select {
  font: inherit;
  font-size: 15px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-top: 6px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

input::placeholder { color: var(--placeholder); }

input:focus, select:focus { border-color: var(--accent); }

input:disabled {
  background: var(--disabled-bg);
  color: var(--disabled-text);
}

/* ---------- dotted divider ---------- */
.dotted {
  border-top: 1px dashed var(--dotted);
  margin: 24px 0;
}

/* ---------- contract text (plain reading view) ---------- */
#contractText {
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
}

#contractText h3 {
  font-size: 17px;
  font-weight: 700;
  margin: 28px 0 10px;
  color: var(--text);
}

#contractText h3:first-child { margin-top: 0; }

#contractText p { margin: 0 0 16px; }

#contractText strong { font-weight: 700; }

#contractText table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  margin-top: 16px;
  font-size: 14.5px;
}

#contractText td {
  vertical-align: top;
  padding: 4px 10px 4px 0;
  width: 50%;
  word-break: break-word;
  overflow-wrap: break-word;
}

#sentinel { height: 1px; }

/* ---------- rule checkboxes ---------- */
.rule-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  font-size: 14.5px;
  line-height: 1.5;
  cursor: pointer;
  margin-top: 16px;
}

.rule-row.locked { opacity: 0.45; cursor: not-allowed; }

.rule-check {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  margin: 2px 0 0;
  cursor: pointer;
  position: relative;
}

.rule-check:disabled { cursor: not-allowed; }

.rule-check:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.rule-check:checked::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: #fff;
}

.sign-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sign-label { display: block; }

.sign-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin: 8px 0 0;
}

.sign-note a {
  color: var(--accent);
  text-decoration: underline;
}

.clear-btn {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px;
  margin-top: 14px;
}

.signature-box {
  position: relative;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  height: 280px;
  overflow: hidden;
}

.signature-box::after {
  content: "";
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: 48px;
  border-bottom: 1px dashed var(--dotted);
  pointer-events: none;
}

.signature-box.locked { opacity: 0.45; }

.signature-box.locked .signature-canvas { pointer-events: none; }

.signature-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--placeholder);
  font-size: 15px;
  pointer-events: none;
}

.signature-placeholder.hidden { display: none; }

.signature-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* ---------- buttons ---------- */
.accept-btn, .ghost-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 16px;
  border-radius: 999px;
  border: none;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.accept-btn {
  background: var(--cta);
  color: var(--cta-text);
}

.accept-btn:disabled {
  background: var(--cta-dim);
  color: var(--cta-dim-text);
  cursor: not-allowed;
}

.ghost-btn {
  background: var(--surface);
  color: var(--text);
  margin-bottom: 12px;
}

.arrow { font-size: 15px; }

/* ---------- sticky footer ---------- */
.footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

.footer .accept-btn {
  max-width: 560px;
  margin: 0 auto;
}

@media print {
  .topbar, .footer, form, .sign-note, .dotted, #successCard, #clearSignatureBtn {
    display: none !important;
  }
  .signature-box { border: none; height: auto; }
  .signature-box::after { display: none; }
  .signature-box.locked { opacity: 1; }
  .signature-placeholder { display: none !important; }
  body { padding-bottom: 0; background: #fff; color: #000; }
  #contractText { color: #000; }
}
