:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #e4e8ef;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --blue: #1d4ed8;
  --warn: #b45309;
  --warn-bg: #fff7ed;
  --error: #b42318;
  --error-bg: #fef3f2;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.07);
}

* { box-sizing: border-box; }

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

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 500px at 15% -10%, #e7f5f2 0%, transparent 60%),
    radial-gradient(900px 400px at 100% 0%, #e8eefc 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  background: rgba(255, 255, 255, 0.85);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  letter-spacing: 0.4px;
}

.topbar-note {
  color: var(--muted);
  font-size: 13px;
}

.page {
  width: min(1120px, 100% - 32px);
  margin: 32px auto 48px;
  flex: 1;
}

.footer {
  border-top: 1px solid var(--line);
  padding: 18px 28px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.hero {
  margin: 10px 0 24px;
}

.hero h1 {
  margin: 0 0 12px;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.hero-sub {
  margin: 0;
  color: var(--muted);
  max-width: 720px;
  font-size: 17px;
}

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

.form-card {
  margin-bottom: 20px;
}

form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.field-wide {
  grid-column: 1 / -1;
}

label {
  font-weight: 600;
  font-size: 14px;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid #cfd6e2;
  border-radius: 10px;
  font: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

input#quarter {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 18px;
  letter-spacing: 0.4px;
}

.examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.chip {
  border: 1px solid #cfd6e2;
  background: #f8fafc;
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  font: inherit;
  font-size: 12px;
  font-family: "Cascadia Mono", Consolas, monospace;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.checkbox {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 400;
  cursor: pointer;
}

.checkbox input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.btn-primary,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 10px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.btn-primary {
  grid-column: 1 / -1;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  padding: 14px 22px;
}

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

.btn-primary:disabled {
  opacity: 0.65;
  cursor: wait;
}

.btn-secondary {
  background: #fff;
  border-color: #cfd6e2;
  color: var(--text);
  font-size: 14px;
  padding: 9px 14px;
}

.btn-secondary:hover { border-color: var(--accent); color: var(--accent-dark); }

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.mini h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.mini p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.alert {
  border-radius: 12px;
  padding: 14px 16px;
  margin: 0 0 16px;
  font-size: 15px;
  border: 1px solid transparent;
}

.alert-error { background: var(--error-bg); border-color: #fecdca; color: var(--error); }
.alert-warn { background: var(--warn-bg); border-color: #fed7aa; color: var(--warn); }
.alert-info { background: #eff8ff; border-color: #b9e6fe; color: #175cd3; }

.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

.result-head h1 {
  margin: 6px 0 4px;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.2;
}

.back {
  font-size: 14px;
  text-decoration: none;
}

.head-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 6px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.stat-value {
  display: block;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-label {
  color: var(--muted);
  font-size: 13px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.card-head h2 {
  margin: 0;
  font-size: 20px;
}

.map-card { margin-bottom: 18px; padding-bottom: 14px; }

.map {
  height: 460px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #e8eef6;
  z-index: 1;
}

.map-fallback {
  padding: 18px;
  border-radius: 10px;
  background: var(--warn-bg);
  color: var(--warn);
}

.muted { color: var(--muted); font-size: 13px; font-weight: 400; }

.table-wrap { overflow-x: auto; }

.spaces-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.spaces-table th,
.spaces-table td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.spaces-table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.spaces-table tr:last-child td { border-bottom: none; }

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 8px;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
}

.badge-крупное { background: #d97706; }
.badge-среднее { background: #059669; }
.badge-малое { background: #4f46e5; }

.tag {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 9px;
  background: #eef2f7;
  color: #475467;
  font-size: 12px;
  white-space: nowrap;
}

.tag-warn { background: var(--warn-bg); color: var(--warn); }
.tag-ok { background: var(--ok-bg); color: var(--ok); }

.mono {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
}

.verdict {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.6;
  font-size: 15px;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
}

.verdict.markdown { white-space: normal; }

.verdict.markdown > :first-child { margin-top: 0; }
.verdict.markdown > :last-child { margin-bottom: 0; }

.verdict.markdown h1,
.verdict.markdown h2,
.verdict.markdown h3,
.verdict.markdown h4 {
  line-height: 1.3;
  margin: 22px 0 10px;
}

.verdict.markdown h1 { font-size: 22px; }
.verdict.markdown h2 { font-size: 19px; }
.verdict.markdown h3 { font-size: 17px; }
.verdict.markdown h4 { font-size: 15px; }

.verdict.markdown ul,
.verdict.markdown ol { padding-left: 22px; }

.verdict.markdown li { margin: 4px 0; }

.verdict.markdown table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 14px;
}

.verdict.markdown th,
.verdict.markdown td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.verdict.markdown th { background: #f4f6fa; }

.verdict.markdown code {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
  background: #eef2f7;
  border-radius: 4px;
  padding: 1px 5px;
}

.verdict.markdown pre {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
}

.verdict.markdown pre code {
  background: none;
  color: inherit;
  padding: 0;
}

.verdict.markdown blockquote {
  margin: 12px 0;
  padding: 2px 14px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  background: #f8fafc;
}

.details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 24px;
  margin: 0;
}

.details div { min-width: 0; }

.details dt {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.details dd { margin: 2px 0 0; }

.skipped {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.skipped summary { cursor: pointer; color: var(--muted); }

.skipped ul { margin: 12px 0 0; padding-left: 20px; }

.loading {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: rgba(23, 32, 51, 0.55);
  backdrop-filter: blur(3px);
}

.loading[hidden] { display: none; }

.loading-box {
  width: min(420px, calc(100% - 40px));
  background: #fff;
  border-radius: 16px;
  padding: 28px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(16, 24, 40, 0.3);
}

.loading-box p { margin: 14px 0 0; font-weight: 600; }
.loading-hint { font-weight: 400 !important; color: var(--muted); font-size: 13px; }

.spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto;
  border-radius: 50%;
  border: 4px solid #d9e2ec;
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

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

@media (max-width: 820px) {
  .grid-3 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .details { grid-template-columns: 1fr; }
  .result-head { flex-direction: column; }
}

@media (max-width: 600px) {
  form { grid-template-columns: 1fr; }
  .page { margin-top: 20px; }
  .card { padding: 18px; }
  .topbar { padding: 12px 16px; }
  .topbar-note { display: none; }
  .map { height: 340px; }
}
