/* ===== Reset & Root ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #dc2626;
  --primary-hover: #b91c1c;
  --primary-rgb: 220, 38, 38;
  --primary-light: #fef2f2;
  --primary-border: #fecaca;
  --bg: #f9f7f4;
  --surface: #ffffff;
  --text: #1a1a2e;
  --muted: #6b7280;
  --border: #e5e7eb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 6px 20px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06);
  --transition: 0.15s ease;
}

body {
  font-family: 'Outfit', 'BIZ UDPGothic', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3 {
  letter-spacing: -0.01em;
}

/* ===== Header ===== */
header {
  background: linear-gradient(135deg, #991b1b 0%, #dc2626 60%, #ef4444 100%);
  color: white;
  padding: 2.25rem 1.25rem 1.75rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

header::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 70%, rgba(255, 255, 255, 0.08) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 15%, rgba(255, 255, 255, 0.05) 0%, transparent 50%);
  pointer-events: none;
}

.header-inner {
  position: relative;
}

header h1 {
  font-size: clamp(1.3rem, 4.5vw, 1.9rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}

header h1 .bi {
  font-size: 0.9em;
  vertical-align: -0.05em;
  margin-right: 0.25em;
}

.subtitle {
  margin-top: 0.4rem;
  font-size: 0.875rem;
  opacity: 0.88;
}

/* ===== Main ===== */
main {
  max-width: 800px;
  margin: 0 auto;
  padding: 1.25rem 1rem;
}

/* ===== Privacy Note ===== */
.privacy-note {
  font-size: 0.8125rem;
  color: var(--muted);
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.875rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.privacy-note .bi {
  color: #16a34a;
  flex-shrink: 0;
}

/* ===== Ad Units ===== */
.ad-unit {
  min-height: 90px;
  background: #f1f5f9;
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius-sm);
  margin: 1.25rem 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 0.75rem;
}

/* ===== Tool Section ===== */
.tool-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

/* ===== Tab Bar ===== */
.tab-bar {
  display: flex;
  gap: 0.375rem;
  background: var(--bg);
  padding: 0.375rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.5rem;
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 0.75rem;
  min-height: 44px;
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}

.tab-btn:hover {
  background: rgba(220, 38, 38, 0.07);
  color: var(--primary);
}

.tab-btn:active {
  transform: scale(0.98);
}

.tab-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.tab-btn .bi {
  font-size: 1em;
}

/* ===== Tab Panels ===== */
.tab-panel {
  display: block;
}

.tab-panel[hidden] {
  display: none;
}

/* ===== Form Elements ===== */
.form-grid {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.field-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: #374151;
}

.field-hint {
  font-size: 0.8125rem;
  color: var(--muted);
}

input[type="number"],
input[type="text"],
select {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  font-size: 0.9375rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

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

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%236b7280' d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
}

/* ===== Primary Button ===== */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  min-height: 48px;
  padding: 0.625rem 1.5rem;
  font-size: 0.9375rem;
  font-weight: 700;
  font-family: inherit;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.35);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(var(--primary-rgb), 0.4);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(var(--primary-rgb), 0.25);
}

/* ===== AB Grid ===== */
.ab-grid {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.ab-group {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 1rem;
  border: 1px solid var(--border);
}

.ab-label {
  font-size: 0.875rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.ab-label.ab-a {
  color: #1d4ed8;
}

.ab-label.ab-b {
  color: var(--primary);
}

.ab-group .field + .field {
  margin-top: 0.75rem;
}

/* ===== Result Area ===== */
.result-area {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.result-area[hidden] {
  display: none;
}

/* ===== Result Panel ===== */
.result-panel {
  background: linear-gradient(135deg, #fef2f2 0%, #fff5f5 100%);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  animation: fadeIn 0.25s ease;
}

.result-panel[hidden] {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.result-main {
  text-align: center;
  margin-bottom: 1.25rem;
}

.result-value-wrap {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.25rem;
  line-height: 1;
}

.result-value {
  font-size: clamp(2.75rem, 10vw, 4.5rem);
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
  letter-spacing: -0.03em;
}

.result-unit {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
  padding-bottom: 0.25rem;
}

.result-desc {
  font-size: 0.875rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.stat-item {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.75rem;
  text-align: center;
  border: 1px solid var(--border);
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.stat-value {
  display: block;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
}

/* ===== Gacha Panel ===== */
.gacha-panel {
  background: linear-gradient(135deg, #fffbeb 0%, #fef9ee 100%);
  border-color: #fde68a;
}

.result-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: #92400e;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.gacha-milestones {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.625rem;
  margin-bottom: 1rem;
}

.milestone-item {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.5rem;
  text-align: center;
  border: 2px solid var(--border);
  transition: box-shadow var(--transition);
}

.milestone-item:hover {
  box-shadow: var(--shadow-hover);
}

.milestone-pct {
  display: block;
  font-size: 1.375rem;
  font-weight: 800;
  line-height: 1.1;
}

.milestone-50 .milestone-pct { color: #16a34a; }
.milestone-90 .milestone-pct { color: #d97706; }
.milestone-99 .milestone-pct { color: var(--primary); }

.milestone-label {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  margin: 0.2rem 0 0.3rem;
}

.milestone-val {
  display: block;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
}

.gacha-comment {
  background: rgba(220, 38, 38, 0.06);
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  color: #7f1d1d;
  margin-bottom: 1rem;
  line-height: 1.6;
}

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

.table-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.gacha-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.gacha-table th {
  background: #f1f5f9;
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-weight: 600;
  color: #374151;
  border-bottom: 2px solid var(--border);
}

.gacha-table td {
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.gacha-table tr:hover td {
  background: rgba(220, 38, 38, 0.04);
}

.gacha-table .pct-high { color: var(--primary); font-weight: 700; }
.gacha-table .pct-mid  { color: #d97706; font-weight: 600; }
.gacha-table .pct-low  { color: var(--muted); }

/* ===== AB Test Result ===== */
.ab-result-header {
  margin-bottom: 1rem;
}

.ab-result-verdict {
  font-size: 1.125rem;
  font-weight: 700;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  text-align: center;
}

.verdict-significant {
  background: #f0fdf4;
  color: #15803d;
  border: 1.5px solid #86efac;
}

.verdict-not-significant {
  background: #fef9c3;
  color: #854d0e;
  border: 1.5px solid #fde047;
}

.ab-result-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.ab-stat {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ab-stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}

.ab-stat-label.ab-a { color: #1d4ed8; }
.ab-stat-label.ab-b { color: var(--primary); }

.ab-stat-val {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
}

.ab-interpretation {
  font-size: 0.875rem;
  color: #374151;
  line-height: 1.65;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  border: 1px solid var(--border);
}

/* ===== Chart ===== */
.chart-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.chart-wrap[hidden] {
  display: none;
}

.chart-title {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1rem;
}

#pmf-chart {
  max-height: 280px;
}

.chart-note {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-top: 0.5rem;
  text-align: center;
}

/* ===== Howto / Accordion ===== */
.howto-section {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.accordion {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  overflow: hidden;
  transition: box-shadow var(--transition);
}

.accordion:hover {
  box-shadow: var(--shadow-hover);
}

.accordion-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  list-style: none;
  min-height: 52px;
  transition: background var(--transition);
  user-select: none;
}

.accordion-summary::-webkit-details-marker {
  display: none;
}

.accordion-summary::after {
  content: '\F282'; /* bi-chevron-down */
  font-family: 'bootstrap-icons';
  font-size: 1rem;
  margin-left: auto;
  transition: transform 0.2s ease;
  color: var(--muted);
}

details[open] .accordion-summary::after {
  transform: rotate(180deg);
}

.accordion-summary:hover {
  background: rgba(220, 38, 38, 0.04);
}

.accordion-summary .bi {
  color: var(--primary);
  font-size: 1em;
}

.accordion-body {
  padding: 0 1.25rem 1.25rem;
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.75;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.75rem;
}

.howto-list {
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.howto-list li {
  color: var(--text);
  font-size: 0.9375rem;
}

.formula-box {
  background: #1a1a2e;
  color: #f1f5f9;
  border-radius: var(--radius-sm);
  padding: 0.875rem 1rem;
  font-family: 'Outfit', monospace;
  font-size: 0.9375rem;
  margin: 0.75rem 0;
  overflow-x: auto;
}

/* ===== FAQ ===== */
.faq-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.faq-item {
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
}

.faq-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.faq-q {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}

.faq-q .bi {
  color: var(--primary);
  flex-shrink: 0;
}

.faq-a {
  font-size: 0.9rem;
  color: #374151;
  line-height: 1.7;
  padding-left: 1.5rem;
}

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 2.5rem 1rem 2rem;
  font-size: 0.8125rem;
  color: var(--muted);
  margin-top: 1rem;
}

footer p + p {
  margin-top: 0.375rem;
}

footer a {
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color var(--transition);
}

footer a:hover {
  color: var(--primary);
}

/* ===== Responsive: Tablet+ ===== */
@media (min-width: 640px) {
  main {
    padding: 1.75rem 1.5rem;
  }

  .tool-section {
    padding: 2rem;
  }

  .form-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .ab-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .tab-btn {
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
  }
}

/* ===== Responsive: Desktop ===== */
@media (min-width: 900px) {
  .result-stats {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ===== Error State ===== */
.field-error {
  color: #dc2626;
  font-size: 0.8rem;
  margin-top: 0.25rem;
  display: none;
}

.is-invalid {
  border-color: #dc2626 !important;
}

/* ===== Gacha Hero Card ===== */
.gacha-hero-card {
  background: var(--primary-light, #fee2e2);
  border-radius: 12px;
  padding: 1.25rem;
  text-align: center;
  margin-bottom: 1rem;
}

.gacha-hero-label {
  font-size: 0.9rem;
  color: #7f1d1d;
  margin-bottom: 0.5rem;
}

.gacha-hero-value {
  font-size: clamp(2.5rem, 8vw, 4rem);
  font-weight: 700;
  color: var(--primary, #dc2626);
}

/* ===== Sample Warning ===== */
.sample-warning {
  background: #fefce8;
  border-left: 3px solid #eab308;
  color: #713f12;
  padding: 0.6rem 0.875rem;
  border-radius: 0 6px 6px 0;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}
