*, *::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%, #2c4a8c 100%);
  color: white;
  padding: 1.25rem 1rem 1.5rem;
  text-align: center;
}

.header-nav {
  text-align: left;
  margin-bottom: 0.75rem;
}

.back-link {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0;
  transition: color 0.2s;
}

.back-link:hover {
  color: white;
}

header h1 {
  font-size: 1.15rem;
  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);
}

/* ===== Input area ===== */
.input-area {
  padding: 1.25rem 1rem;
}

.input-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.input-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: #374151;
}

.input-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-secondary {
  padding: 0 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  background: #2c4a8c;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.2s;
}

.btn-secondary:hover {
  background: #1a2a6a;
}

.btn-ghost {
  padding: 0 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  background: transparent;
  color: #6b7280;
  border: 1.5px solid #d1d5db;
  border-radius: 6px;
  cursor: pointer;
  min-height: 44px;
  transition: all 0.2s;
}

.btn-ghost:hover {
  background: #f3f4f6;
  color: #374151;
}

textarea {
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans JP", sans-serif;
  line-height: 1.7;
  border: 1.5px solid #d1d5db;
  border-radius: 8px;
  background: #f9fafb;
  color: #111827;
  resize: vertical;
  min-height: 200px;
  transition: border-color 0.2s;
}

textarea:focus {
  outline: none;
  border-color: #2c4a8c;
  background: white;
}

.textarea-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.4rem;
}

.char-count {
  font-size: 0.8rem;
  color: #9ca3af;
}

.char-count.near-limit {
  color: #d97706;
  font-weight: 600;
}

/* ===== Results area ===== */
.results-area {
  margin-top: 0.5rem;
}

.results-area.hidden {
  display: none;
}

/* ===== Stats grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: white;
  border-radius: 10px;
  padding: 0.875rem 1rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.07);
  border-top: 3px solid #2c4a8c;
}

.stat-card.warn {
  border-top-color: #d97706;
}

.stat-card.danger {
  border-top-color: #dc2626;
}

.stat-card.good {
  border-top-color: #16a34a;
}

.stat-name {
  font-size: 0.75rem;
  color: #6b7280;
  font-weight: 500;
  margin-bottom: 0.2rem;
  line-height: 1.3;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: #111827;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.stat-unit {
  font-size: 0.75rem;
  font-weight: 500;
  color: #6b7280;
  margin-left: 0.15rem;
}

.stat-hint {
  font-size: 0.7rem;
  color: #9ca3af;
  margin-top: 0.25rem;
  line-height: 1.4;
}

/* ===== Suggestions ===== */
.suggestions-section {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.suggestions-section.hidden {
  display: none;
}

.section-heading {
  font-size: 1rem;
  font-weight: 700;
  color: #1a2a4a;
  margin-bottom: 0.6rem;
}

.suggestions-section .section-heading {
  color: #92400e;
}

.suggestions-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.suggestion-item {
  font-size: 0.875rem;
  color: #78350f;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  line-height: 1.5;
}

.suggestion-item::before {
  content: "!";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.2rem;
  height: 1.2rem;
  min-width: 1.2rem;
  background: #f59e0b;
  color: white;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 800;
  margin-top: 0.15rem;
}

/* ===== Heatmap section ===== */
.heatmap-section {
  background: white;
  border-radius: 12px;
  padding: 1.25rem 1rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
  margin-bottom: 1rem;
}

.section-desc {
  font-size: 0.8rem;
  color: #6b7280;
  margin-bottom: 0.75rem;
  margin-top: 0.25rem;
  line-height: 1.5;
}

.legend-blue {
  color: #2563eb;
  font-weight: 600;
}

.legend-red {
  color: #dc2626;
  font-weight: 600;
}

.heatmap {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.heatmap-row {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  border-radius: 6px;
  overflow: hidden;
}

.heatmap-bar {
  border-radius: 4px;
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: opacity 0.2s;
  flex: 1;
  word-break: break-all;
  cursor: default;
  position: relative;
}

.heatmap-bar:hover {
  opacity: 0.85;
}

.heatmap-label {
  font-size: 0.7rem;
  color: #9ca3af;
  min-width: 2.5rem;
  display: flex;
  align-items: center;
  padding-top: 0.5rem;
  flex-shrink: 0;
}

.heatmap-count {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.9);
  margin-left: auto;
  white-space: nowrap;
  padding-left: 0.5rem;
  flex-shrink: 0;
}

.heatmap-text {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  flex: 1;
}

/* ===== Chart section ===== */
.chart-section {
  background: white;
  border-radius: 12px;
  padding: 1.25rem 1rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
  margin-bottom: 1rem;
}

.chart-wrapper {
  position: relative;
  width: 100%;
  height: 220px;
  margin-top: 0.75rem;
}

/* ===== How-to section ===== */
.howto-section {
  margin-top: 1rem;
  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.7;
}

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

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

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

  header h1 {
    font-size: 1.4rem;
  }

  .subtitle {
    font-size: 0.95rem;
  }

  main {
    padding: 1.5rem 2rem;
  }

  .input-area {
    padding: 1.5rem;
  }

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

  .chart-wrapper {
    height: 260px;
  }

  .howto-section {
    padding: 1.5rem;
  }

  .heatmap-section,
  .chart-section {
    padding: 1.5rem;
  }
}
