*, *::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 {
  margin: 1.25rem 0;
}

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

/* ===== Color inputs row ===== */
.color-inputs-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.color-block {
  flex: 1;
  min-width: 0;
}

.color-block-header {
  margin-bottom: 0.5rem;
}

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

.color-input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1.5px solid #d1d5db;
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
  background: #f9fafb;
  min-height: 44px;
}

.color-picker {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 4px;
  padding: 0;
  cursor: pointer;
  background: none;
  flex-shrink: 0;
}

.color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-picker::-webkit-color-swatch {
  border: 1px solid #d1d5db;
  border-radius: 4px;
}

.hex-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  font-size: 1rem;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  color: #111827;
  padding: 0;
  letter-spacing: 0.05em;
}

.hex-input:focus {
  outline: none;
}

.hex-input.input-error {
  color: #dc2626;
}

/* ===== Swap button ===== */
.swap-col {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 0.15rem;
}

.swap-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid #d1d5db;
  background: #f9fafb;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
  flex-shrink: 0;
}

.swap-btn:hover {
  background: #eff6ff;
  border-color: #2c4a7c;
  color: #2c4a7c;
  transform: rotate(90deg);
}

.swap-btn:active {
  transform: rotate(180deg);
}

/* ===== Preview area ===== */
.preview-area {
  margin-top: 1.25rem;
  border-radius: 8px;
  padding: 1.25rem 1rem;
  border: 1.5px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: background-color 0.15s, color 0.15s;
}

.preview-text {
  transition: color 0.15s;
  line-height: 1.5;
}

.preview-normal {
  font-size: 1rem;
}

.preview-large {
  font-size: 1.5rem;
  font-weight: 400;
}

.preview-bold {
  font-size: 0.875rem;
  font-weight: 700;
}

/* ===== Contrast ratio display ===== */
.ratio-display {
  margin-top: 1.25rem;
  text-align: center;
  padding: 1rem 0;
  border-bottom: 1px solid #e2e8f0;
}

.ratio-number {
  font-size: 3rem;
  font-weight: 800;
  color: #1a2a4a;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.ratio-label {
  font-size: 0.8rem;
  color: #64748b;
  margin-top: 0.25rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ===== Results grid ===== */
.results-grid {
  margin-top: 1.25rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.result-category {
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.875rem;
}

.result-category--full {
  grid-column: 1 / -1;
}

.category-title {
  font-size: 0.875rem;
  font-weight: 700;
  color: #1a2a4a;
  margin-bottom: 0.6rem;
  line-height: 1.3;
}

.category-sub {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  color: #64748b;
  margin-top: 0.1rem;
}

.criteria-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.criteria-row:last-child {
  margin-bottom: 0;
}

.criteria-label {
  font-size: 0.8rem;
  color: #4b5563;
}

.criteria-label strong {
  color: #1a2a4a;
}

/* ===== Badge ===== */
.criteria-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  white-space: nowrap;
  min-width: 60px;
  justify-content: center;
  background: #e2e8f0;
  color: #94a3b8;
}

.criteria-badge.pass {
  background: #dcfce7;
  color: #16a34a;
}

.criteria-badge.fail {
  background: #fee2e2;
  color: #dc2626;
}

/* ===== Swatches section ===== */
.swatches-section {
  padding: 1.25rem 1rem;
}

.swatches-title {
  font-size: 1rem;
  color: #1a2a4a;
  font-weight: 700;
  margin-bottom: 0.3rem;
}

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

.swatches-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.swatch-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-height: 44px;
  text-align: left;
}

.swatch-item:hover {
  border-color: #2c4a7c;
  box-shadow: 0 2px 6px rgba(44, 74, 124, 0.12);
}

.swatch-preview {
  display: flex;
  flex-shrink: 0;
  border-radius: 4px;
  overflow: hidden;
  width: 40px;
  height: 28px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.swatch-fg {
  flex: 1;
}

.swatch-bg {
  flex: 1;
}

.swatch-info {
  flex: 1;
  min-width: 0;
}

.swatch-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: #374151;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.swatch-ratio {
  font-size: 0.75rem;
  color: #64748b;
}

/* ===== 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) {
  .swatches-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@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;
  }

  .tool-section {
    padding: 1.5rem;
  }

  .ratio-number {
    font-size: 3.5rem;
  }

  .swatches-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 720px) {
  .swatches-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}
