*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #f3f4f6;
  color: #111827;
  min-height: 100vh;
}

header {
  background: #1d4ed8;
  color: #fff;
  padding: 1rem 1.5rem;
}

.header-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 700;
}

header p {
  font-size: 0.85rem;
  opacity: 0.8;
  margin-top: 0.2rem;
}

#viewToggle {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s;
}

#viewToggle:hover { background: rgba(255,255,255,0.25); }

main {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1rem;
  padding: 1rem;
  max-width: 1400px;
  margin: 0 auto;
}

/* ── Input panel ─────────────────────────────────────────────────────────── */
.inputs {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

section {
  background: #fff;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

section h2 {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6b7280;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.badge {
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: #374151;
  margin-bottom: 0.6rem;
}

label:last-of-type { margin-bottom: 0; }

label .hint {
  font-size: 0.72rem;
  color: #9ca3af;
}

input[type="number"] {
  padding: 0.45rem 0.6rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.9rem;
  width: 100%;
  background: #f9fafb;
  transition: border-color 0.15s;
}

input[type="number"]:focus {
  outline: none;
  border-color: #3b82f6;
  background: #fff;
}

button#calcBtn {
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s;
}

button#calcBtn:hover { background: #1d4ed8; }
button#calcBtn:active { background: #1e40af; }

/* ── Output panel ────────────────────────────────────────────────────────── */
.output {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.diagram-card {
  background: #fff;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

#diagram {
  display: block;
  width: 100%;
  height: auto;
}

.legend {
  display: flex;
  gap: 1.25rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: #6b7280;
  padding-top: 0.75rem;
  border-top: 1px solid #f3f4f6;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

.swatch-panel   { background: #3b82f6; border: 1px solid #1d4ed8; }
.swatch-clear   { background: repeating-linear-gradient(45deg, #fca5a5 0px, #fca5a5 3px, #fff 3px, #fff 7px); border: 1px solid #fca5a5; }
.swatch-usable  { background: #f9fafb; border: 1.5px dashed #9ca3af; }

/* ── Results ─────────────────────────────────────────────────────────────── */
.results-card {
  background: #fff;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.placeholder {
  color: #9ca3af;
  font-size: 0.9rem;
  text-align: center;
  padding: 1rem 0;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.result-box {
  border-radius: 8px;
  padding: 0.875rem 1rem;
  border: 2px solid #e5e7eb;
  background: #f9fafb;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.result-box:hover {
  border-color: #93c5fd;
  background: #f0f9ff;
}

.result-box.selected {
  background: #eff6ff;
  border-color: #3b82f6;
}

.result-box-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6b7280;
  margin-bottom: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.result-box.selected .result-box-label { color: #2563eb; }

.ori-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.best-badge {
  background: #d1fae5;
  color: #065f46;
  font-size: 0.6rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: none;
}

.result-count {
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1;
  color: #111827;
}

.result-box.selected .result-count { color: #1d4ed8; }

.result-unit {
  font-size: 0.85rem;
  color: #6b7280;
  margin-top: 0.1rem;
}

.result-detail {
  font-size: 0.78rem;
  color: #9ca3af;
  margin-top: 0.35rem;
}

.result-meta {
  font-size: 0.8rem;
  color: #6b7280;
  padding-top: 0.6rem;
  border-top: 1px solid #f3f4f6;
}

.result-meta span + span::before {
  content: ' · ';
}

/* ── Disclaimer ──────────────────────────────────────────────────────────── */
.disclaimer {
  background: #fefce8;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.78rem;
  color: #92400e;
  line-height: 1.5;
}

/* ── Responsive & forced mobile ──────────────────────────────────────────── */
@media (max-width: 768px) {
  main {
    grid-template-columns: 1fr;
  }
}

main.force-mobile {
  grid-template-columns: 1fr;
}

@media (max-width: 480px) {
  .results-grid {
    grid-template-columns: 1fr;
  }
}

main.force-mobile .results-grid {
  grid-template-columns: 1fr 1fr;
}
