* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
       background: #f5f3f7; color: #1a1a2e; line-height: 1.6; }
.container { max-width: 1000px; margin: 0 auto; padding: 32px 24px; }
h1 { font-size: 1.875rem; font-weight: 700; color: #440154; letter-spacing: -0.02em; }
.subtitle { color: #5e548e; font-size: 0.95rem; margin-bottom: 28px; }
.card { background: #fff; border-radius: 16px; padding: 28px; margin-bottom: 24px;
        box-shadow: 0 4px 12px rgba(68,1,84,0.06), 0 1px 3px rgba(68,1,84,0.04); }
.card h2 { font-size: 0.875rem; color: #5e548e; margin-bottom: 16px; text-transform: uppercase;
           letter-spacing: 0.08em; font-weight: 600; }
label { display: block; font-weight: 600; margin-bottom: 8px; font-size: 0.875rem; color: #1a1a2e; }
input[type="number"], input[type="text"] {
  width: 100%; padding: 12px 16px; border: 1.5px solid #c2df2340; border-radius: 10px;
  font-size: 1rem; transition: all 0.2s ease; background: #fafafa; }
input:focus { outline: none; border-color: #21908d; box-shadow: 0 0 0 3px rgba(33,144,141,0.15); background: #fff; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 18px; }
.help { font-size: 0.8rem; color: #8e7aa0; margin-top: 8px; }
.help code { background: #f0eef5; padding: 2px 6px; border-radius: 4px; font-size: 0.78rem; font-family: 'SF Mono', monospace; color: #3e4989; }
.presets { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }
.preset-btn { padding: 8px 18px; border: 1.5px solid #c2df2340; border-radius: 24px;
              background: #fff; cursor: pointer; font-size: 0.85rem; color: #5e548e;
              transition: all 0.2s ease; font-weight: 500; }
.preset-btn:hover { border-color: #21908d; color: #21908d; background: #e8f8f5; transform: translateY(-1px); }
.preset-btn.active { border-color: #440154; color: #fff; background: #440154; box-shadow: 0 2px 8px rgba(68,1,84,0.3); }
.btn { display: inline-block; padding: 14px 36px; background: linear-gradient(135deg, #440154 0%, #482878 100%); color: #fff; border: none;
       border-radius: 10px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: all 0.2s ease;
       letter-spacing: 0.02em; box-shadow: 0 2px 8px rgba(68,1,84,0.3); }
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(68,1,84,0.4); }
.btn:active { transform: translateY(0); }
.btn:disabled { background: #b8b0c8; cursor: not-allowed; box-shadow: none; transform: none; }

/* Results Header */
.results-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.results-title { flex: 1; }
.results-title h1 { margin-bottom: 6px; }
.results-subtitle { color: #5e548e; font-size: 0.9rem; }
.status-badge { display: inline-flex; align-items: center; padding: 6px 16px; border-radius: 20px; font-size: 0.8rem;
                font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.status-badge::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; }
.status-optimal { background: #e8f8f5; color: #0d6944; }
.status-optimal::before { background: #35b779; }
.status-satisfy { background: #fdf8e8; color: #7a6c00; }
.status-satisfy::before { background: #c2df23; }
.status-error { background: #f8e8e8; color: #8b1a1a; }
.status-error::before { background: #d64040; }

/* Stats Grid */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }
.stat { text-align: center; padding: 20px 12px; background: linear-gradient(135deg, #f8f6fb 0%, #f0eef5 100%);
        border-radius: 12px; border: 1px solid #e0dce8; }
.stat-val { font-size: 1.75rem; font-weight: 700; color: #440154; line-height: 1.2; }
.stat-label { font-size: 0.7rem; color: #8e7aa0; margin-top: 6px; text-transform: uppercase;
              letter-spacing: 0.08em; font-weight: 600; }

/* Pair Coverage */
.pair-coverage { margin-top: 8px; padding: 16px; background: #f8f6fb; border-radius: 12px; border: 1px solid #e0dce8; }
.pair-bar { height: 12px; border-radius: 6px; background: #e0dce8; margin: 12px 0; overflow: hidden; }
.pair-fill { height: 100%; border-radius: 6px; transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1); }
.pair-fill.good { background: linear-gradient(90deg, #35b779, #21908d); }
.pair-fill.ok { background: linear-gradient(90deg, #8fd744, #35b779); }
.pair-fill.low { background: linear-gradient(90deg, #3e4989, #482878); }
.pair-detail { display: flex; justify-content: space-between; font-size: 0.875rem; color: #5e548e; font-weight: 500; }

/* Round Cards */
.round-card { border: 1px solid #e0dce8; border-radius: 14px; padding: 20px; margin-bottom: 16px;
              transition: all 0.2s ease; background: #fff; }
.round-card:hover { box-shadow: 0 4px 16px rgba(68,1,84,0.08); border-color: #c8c0d8; }
.round-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;
                padding-bottom: 12px; border-bottom: 1px solid #f0eef5; }
.round-num { font-weight: 700; font-size: 1.125rem; color: #440154; }
.round-meta { font-size: 0.8rem; color: #8e7aa0; font-weight: 500; background: #f0eef5;
              padding: 4px 12px; border-radius: 16px; }
.groups-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.group-chip { padding: 10px 16px; border-radius: 10px; font-size: 0.875rem; line-height: 1.4;
              font-weight: 500; transition: transform 0.15s ease; }
.group-chip:hover { transform: translateY(-1px); }
.group-chip .tlabel { font-weight: 700; margin-right: 8px; opacity: 0.8; }
.extra-chip { background: #fdf8e8; border: 1.5px solid #c2df23; color: #7a6c00; }
.extra-label { font-weight: 700; color: #7a6c00; margin-right: 8px; }
.t1 { background: linear-gradient(135deg, #f3eef8 0%, #e8e0f0 100%); border: 2px solid #482878; color: #3a2060; }
.t2 { background: linear-gradient(135deg, #eef3f8 0%, #e0ecf0 100%); border: 2px solid #3e4989; color: #2e3a6e; }
.t3 { background: linear-gradient(135deg, #eef8f5 0%, #e0f0ec 100%); border: 2px solid #21908d; color: #166e6c; }
.t4 { background: linear-gradient(135deg, #eef8ee 0%, #e0f0e0 100%); border: 2px solid #35b779; color: #248a5e; }
.t5 { background: linear-gradient(135deg, #f8f8ee 0%, #f0f0e0 100%); border: 2px solid #8fd744; color: #5e9a20; }
.t6 { background: linear-gradient(135deg, #f8f6ee 0%, #f0ece0 100%); border: 2px solid #c2df23; color: #8a9a10; }

/* Summary Table */
.text-results { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.text-results table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.875rem; }
.text-results th { background: #f0eef5; padding: 12px 16px; text-align: left; font-weight: 600;
                   color: #5e548e; border-bottom: 2px solid #e0dce8; font-size: 0.75rem;
                   text-transform: uppercase; letter-spacing: 0.06em; position: sticky; top: 0; }
.text-results td { padding: 12px 16px; border-bottom: 1px solid #f0eef5; vertical-align: middle; }
.text-results tr:hover td { background: #f8f6fb; }
.cell-chip { display: inline-flex; align-items: center; justify-content: center;
             padding: 4px 12px; border-radius: 16px; font-size: 0.8rem; font-weight: 600; min-width: 32px; }
.cell-extra { background: #fdf8e8; color: #7a6c00; border: 1px solid #c2df23; }

/* Tabs */
.section-tabs { display: flex; gap: 4px; margin-bottom: 20px; background: #f0eef5; padding: 4px;
                border-radius: 12px; border: 1px solid #e0dce8; }
.tab-btn { padding: 10px 20px; border: none; background: transparent; cursor: pointer; font-size: 0.875rem;
           color: #8e7aa0; font-weight: 500; border-radius: 8px; transition: all 0.2s ease; flex: 1; }
.tab-btn:hover { color: #440154; background: #e8e4f0; }
.tab-btn.active { color: #fff; background: #440154; box-shadow: 0 2px 8px rgba(68,1,84,0.3); }
.tab-panel { display: none; animation: fadeIn 0.3s ease; }
.tab-panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Raw Output */
.raw-output { background: linear-gradient(135deg, #1a1a2e 0%, #2d2640 100%); color: #e0dce8; padding: 24px;
              border-radius: 12px; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.85rem;
              white-space: pre-wrap; overflow-x: auto; line-height: 1.8; border: 1px solid #482878;
              text-align: left; }

/* SVG Container */
.svg-container { text-align: center; padding: 16px 0; cursor: zoom-in; transition: all 0.3s ease;
                 background: #f0eef5; border-radius: 12px; border: 1px solid #e0dce8; }
.svg-container svg { max-width: 100%; height: auto; transition: max-width 0.3s ease; border-radius: 8px; }
.svg-container.expanded { cursor: zoom-out; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
                          z-index: 1000; background: #fff; display: flex;
                          align-items: center; justify-content: center; padding: 32px; margin: 0; }
.svg-container.expanded svg { max-width: 95vw; max-height: 90vh; box-shadow: 0 25px 50px rgba(0,0,0,0.3); }

/* Navigation */
.nav-actions { display: flex; gap: 12px; margin-top: 24px; }
.back-link { display: inline-flex; align-items: center; padding: 12px 24px; background: #fff; color: #5e548e;
             border: 1.5px solid #e0dce8; border-radius: 10px; font-size: 0.9rem; font-weight: 500;
             cursor: pointer; text-decoration: none; transition: all 0.2s ease; }
.back-link:hover { background: #f8f6fb; border-color: #c8c0d8; color: #440154; text-decoration: none;
                   transform: translateY(-1px); box-shadow: 0 2px 8px rgba(68,1,84,0.08); }
.back-link svg { margin-right: 8px; }

/* Loading State */
.spinner { display: inline-block; width: 40px; height: 40px; border: 3px solid #e0dce8;
           border-top-color: #440154; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 768px) {
  .container { padding: 20px 16px; }
  .form-row { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .stat { padding: 16px 8px; }
  .stat-val { font-size: 1.5rem; }
  .results-header { flex-direction: column; gap: 12px; }
  .section-tabs { overflow-x: auto; }
  .tab-btn { min-width: 80px; }
}
@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .groups-grid { gap: 8px; }
  .group-chip { padding: 8px 12px; font-size: 0.8rem; }
}
