:root {
  --bg: #f7f7fb;
  --surface: #ffffff;
  --text: #1a1a2e;
  --muted: #5c5c72;
  --border: #e2e2ee;
  --accent: #5b47e0;
  --accent-hover: #4736c2;
  --danger: #d64545;
  --danger-bg: #fdeaea;
  --low: #2fa84f;
  --mid: #e0a72f;
  --high: #d64545;
  --shadow: 0 8px 30px rgba(20, 20, 50, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14141f;
    --surface: #1d1d2c;
    --text: #eeeef7;
    --muted: #a3a3b8;
    --border: #2e2e42;
    --accent: #8474ff;
    --accent-hover: #9a8bff;
    --danger: #ff6b6b;
    --danger-bg: #3a2222;
    --low: #4ecb75;
    --mid: #f0bb52;
    --high: #ff6b6b;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.wrap {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 20px 24px;
  flex: 1;
}

header.top {
  text-align: center;
  margin-bottom: 28px;
}

header.top h1 {
  font-size: 1.7rem;
  margin: 0 0 8px;
}

header.top p {
  color: var(--muted);
  margin: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.field {
  margin-bottom: 22px;
}

.field:last-child {
  margin-bottom: 0;
}

label.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

input[type="text"],
input[type="email"],
textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
}

input[type="text"]:focus,
input[type="email"]:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.scale {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.scale label {
  position: relative;
  flex: 1;
  min-width: 44px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 6px;
  cursor: pointer;
  font-size: 0.95rem;
  background: var(--bg);
  transition: border-color 0.15s, background 0.15s;
}

.scale label input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.scale label:has(input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
}

/* Fallback for browsers without :has() — highlight via JS "checked" class */
.scale label.checked {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
}

.scale-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 6px;
}

.checkbox-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.checkbox-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  background: var(--bg);
}

.checkbox-row input {
  width: 16px;
  height: 16px;
}

.btn {
  display: inline-block;
  width: 100%;
  text-align: center;
  padding: 14px 20px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.secondary:hover {
  background: var(--bg);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.error-box {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 18px;
  font-size: 0.92rem;
  display: none;
}

.error-box.visible {
  display: block;
}

/* --- Risk gauge --- */
.gauge-wrap {
  text-align: center;
  margin: 8px 0 24px;
}

.gauge-score {
  font-size: 3.2rem;
  font-weight: 800;
  line-height: 1;
}

.gauge-max {
  font-size: 1.1rem;
  color: var(--muted);
  font-weight: 500;
}

.gauge-label {
  margin-top: 6px;
  font-size: 1.15rem;
  font-weight: 600;
}

.gauge-bar-track {
  position: relative;
  width: 100%;
  height: 22px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin-top: 18px;
}

.gauge-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--low), var(--mid), var(--high));
  transition: width 0.6s ease;
}

.gauge-scale-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 6px;
}

.reason-box {
  background: var(--bg);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 14px 16px;
  margin: 20px 0;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 24px;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

/* --- Report page --- */
.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 28px 0 12px;
}

.section-title:first-of-type {
  margin-top: 0;
}

ul.report-list {
  padding-left: 20px;
  margin: 0;
}

ul.report-list li {
  margin-bottom: 8px;
}

.plan-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
  background: var(--bg);
}

.plan-item h4 {
  margin: 0 0 6px;
  font-size: 1.02rem;
}

.plan-item .why {
  color: var(--muted);
  margin: 0 0 8px;
  font-size: 0.92rem;
}

.plan-item .step {
  font-size: 0.92rem;
  font-weight: 600;
}

.tag {
  display: inline-block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  margin-bottom: 10px;
}

footer.disclaimer {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 20px;
  max-width: 640px;
  margin: 0 auto;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.5);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -3px;
  margin-right: 8px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-page {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

@media (max-width: 480px) {
  .card {
    padding: 20px;
  }
  .gauge-score {
    font-size: 2.4rem;
  }
}
