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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: #333;
  background: #f0f4f8;
}

/* ===== Header ===== */
header {
  background: linear-gradient(135deg, #1a2a4a 0%, #2c4a7c 100%);
  color: white;
  padding: 1.5rem 1rem;
  text-align: center;
}

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

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

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

/* ===== Ad unit ===== */
.ad-unit {
  min-height: 90px;
  background: #e2e8f0;
  margin: 1.25rem 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #a0aec0;
  font-size: 0.75rem;
  border-radius: 6px;
}

/* ===== Tool section ===== */
.tool-section {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* ===== Mode tabs ===== */
.mode-tabs {
  display: flex;
  border-bottom: 2px solid #e2e8f0;
}

.mode-tab {
  flex: 1;
  padding: 0.875rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  background: #f8fafc;
  color: #64748b;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 44px;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}

.mode-tab.active {
  background: white;
  color: #1a2a4a;
  border-bottom-color: #2c4a7c;
}

.mode-tab:hover:not(.active) {
  background: #f1f5f9;
  color: #475569;
}

/* ===== Mode panel ===== */
.mode-panel {
  padding: 1.25rem 1rem;
}

.mode-panel.hidden {
  display: none;
}

.panel-desc {
  font-size: 0.875rem;
  color: #64748b;
  margin-bottom: 1rem;
}

/* ===== Form ===== */
.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

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

.form-group input[type="time"],
.form-group input[type="number"] {
  width: 100%;
  padding: 0.65rem 0.75rem;
  font-size: 1rem; /* iOS zoom prevention */
  border: 1.5px solid #d1d5db;
  border-radius: 8px;
  background: #f9fafb;
  color: #111827;
  transition: border-color 0.2s;
  min-height: 44px; /* touch target */
}

.form-group input:focus {
  outline: none;
  border-color: #2c4a7c;
  background: white;
}

.form-group input.input-error {
  border-color: #dc2626;
  background: #fef2f2;
}

.field-error {
  color: #dc2626;
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

/* ===== Results container ===== */
.results-container {
  margin-top: 1.25rem;
}

.results-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
  margin-bottom: 0.75rem;
}

.result-cards {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* ===== Result card ===== */
.result-card {
  display: flex;
  align-items: center;
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  padding: 0.875rem 1rem;
  gap: 0.75rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.result-card.recommended {
  background: #eff6ff;
  border-color: #2c4a7c;
  box-shadow: 0 2px 8px rgba(44, 74, 124, 0.15);
}

.result-card .card-time {
  font-size: 1.6rem;
  font-weight: 700;
  color: #1a2a4a;
  min-width: 5.5rem;
  letter-spacing: -0.01em;
}

.result-card.recommended .card-time {
  color: #2c4a7c;
}

.result-card .card-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1;
}

.result-card .card-hours {
  font-size: 0.9rem;
  font-weight: 600;
  color: #374151;
}

.result-card .card-cycles {
  font-size: 0.8rem;
  color: #64748b;
}

.result-card .badge-recommended {
  background: #2c4a7c;
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 20px;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

/* ===== Sleep stage icons ===== */
.stage-icons {
  display: flex;
  gap: 3px;
  margin-top: 0.2rem;
  flex-wrap: wrap;
}

.stage-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.stage-dot.rem {
  background: #6366f1;
}

.stage-dot.nrem {
  background: #94a3b8;
}

/* ===== How-to section ===== */
.howto-section {
  margin-top: 1.5rem;
  background: white;
  border-radius: 12px;
  padding: 1.5rem 1rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.howto-section h2 {
  font-size: 1.05rem;
  color: #1a2a4a;
  margin-bottom: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e2e8f0;
}

.howto-section h2:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.howto-section ol {
  padding-left: 1.25rem;
  color: #4b5563;
  font-size: 0.9rem;
}

.howto-section ol li {
  margin-bottom: 0.5rem;
  line-height: 1.6;
}

.howto-section p {
  font-size: 0.9rem;
  color: #4b5563;
  line-height: 1.8;
  margin-bottom: 0.75rem;
}

.howto-section p:last-of-type {
  margin-bottom: 0;
}

/* ===== Affiliate block ===== */
.affiliate-block {
  margin-top: 1.5rem;
  padding: 1rem;
  background: #fafafa;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}

.affiliate-label {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  color: #9ca3af;
  border: 1px solid #d1d5db;
  padding: 0 0.35rem;
  border-radius: 3px;
  margin-bottom: 0.5rem;
}

.affiliate-desc {
  font-size: 0.85rem;
  color: #4b5563;
  margin-bottom: 0.6rem;
}

.affiliate-link {
  display: inline-block;
  font-size: 0.875rem;
  font-weight: 600;
  color: #2c4a7c;
  text-decoration: underline;
  min-height: 44px;
  line-height: 44px;
}

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.85rem;
  color: #9ca3af;
}

footer p {
  margin-bottom: 0.4rem;
}

footer a {
  color: #6b7280;
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* ===== Responsive: tablet+ ===== */
@media (min-width: 480px) {
  .form-row {
    flex-direction: row;
  }

  .form-group {
    flex: 1;
  }
}

@media (min-width: 640px) {
  header {
    padding: 2rem 1.5rem;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .subtitle {
    font-size: 0.95rem;
  }

  main {
    padding: 1.5rem 2rem;
  }

  .mode-panel {
    padding: 1.5rem;
  }

  .result-card .card-time {
    font-size: 1.8rem;
  }
}
