:root {
  color-scheme: light;
  --bg: #e9eff6;
  --surface: #ffffff;
  --surface-soft: #f3f6fb;
  --text: #0f172a;
  --muted: #475569;
  --border: rgba(15, 23, 42, 0.12);
  --primary: #6366f1;
  --primary-soft: rgba(99, 102, 241, 0.16);
  --success: #22c55e;
  --danger: #ef4444;
  --shadow: 0 24px 60px rgba(15, 23, 42, 0.12);
}

body.dark-mode {
  color-scheme: dark;
  --bg: #060b18;
  --surface: #0e1726;
  --surface-soft: #13223d;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: rgba(148, 163, 184, 0.16);
  --primary: #818cf8;
  --primary-soft: rgba(129, 140, 248, 0.18);
  --success: #4ade80;
  --danger: #f87171;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, rgba(99, 102, 241, 0.1), transparent 28%), var(--bg);
  color: var(--text);
}

.wrapper {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: 32px 20px 48px;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
}

.page-header h1 {
  margin: 0;
  font-size: clamp(2rem, 2.8vw, 2.6rem);
}

.page-header p {
  margin: 0;
  color: var(--muted);
  max-width: 760px;
}

.toggle-theme {
  border: 0;
  background: var(--surface-soft);
  color: var(--primary);
  padding: 12px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--border);
  transition: transform 0.2s ease, background 0.2s ease;
}

.toggle-theme:hover {
  transform: translateY(-1px);
  background: var(--surface);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
  align-items: start;
}

.form-grid p {
  margin: 0;
}

form button,
form input[type="submit"] {
  width: 100%;
  max-width: 280px;
}

label {
  display: grid;
  gap: 8px;
  font-size: 0.95rem;
  color: var(--muted);
}

input[type="number"] {
  width: 100%;
  max-width: 240px;
  appearance: none;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  padding: 12px 14px;
  font-size: 1rem;
}

button,
input[type="submit"] {
  margin-top: 10px;
  border: none;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--primary), #6366f1 80%);
  color: white;
  padding: 14px 20px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 18px 40px rgba(99, 102, 241, 0.18);
}

button:hover,
input[type="submit"]:hover {
  filter: brightness(1.05);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.result-card {
  margin-top: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 24px;
}

.result-card h2 {
  margin-top: 0;
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 18px;
  overflow: hidden;
  border-radius: 18px;
}

.result-table th,
.result-table td {
  padding: 14px 18px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.result-table th {
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.result-table tbody tr:last-child td {
  border-bottom: none;
}

.result-table tr {
  background: rgba(255, 255, 255, 0.03);
}

.result-table td {
  font-size: 0.96rem;
}

.stat-bar {
  position: relative;
  width: 100%;
  max-width: 340px;
  height: 28px;
  background: var(--surface-soft);
  border-radius: 999px;
  overflow: hidden;
}

.avg-marker {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 0;
  width: 3px;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.85);
  pointer-events: none;
  z-index: 2;
}

.bar-fill {
  display: block;
  height: 100%;
  min-width: 10px;
  background: linear-gradient(90deg, #ef4444 0%, #f97316 50%, #22c55e 100%);
  transition: width 0.25s ease, background 0.25s ease;
}

body.dark-mode .avg-marker {
  background: rgba(226, 232, 240, 0.85);
}

.bar-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.7);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.9rem;
}

.error {
  background: rgba(239, 68, 68, 0.12);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 18px;
  padding: 14px 18px;
}

.model-viewer-card {
  margin: 0 auto;
  width: min(100%, 440px);
  max-width: 100%;
  border-radius: 28px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  box-shadow: var(--shadow);
}

.model-viewer-card model-viewer {
  width: 100%;
  height: 420px;
  display: block;
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0));
}

@media (max-width: 600px) {
  .wrapper {
    padding: 24px 16px 36px;
  }

  .model-viewer-card model-viewer {
    height: 320px;
  }
}
