* { box-sizing: border-box; }

/* ══════════════════════════════
   MAIN SECTION LAYOUT
══════════════════════════════ */
#main-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}

/* Input — full width */
.chc-input-section {
  grid-column: 1 / -1;
}

/* Stats — full width */
.chc-stats-section {
  grid-column: 1 / -1;
}

/* Breakdown — left */
.chc-breakdown-section {
  grid-column: 1 / 2;
}

/* Limit Checker — right */
.chc-limit-section {
  grid-column: 2 / 3;
}

/* Top Words — full width */
.chc-topwords-section {
  grid-column: 1 / -1;
}

/* ── Section base ── */
#main-section > section {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 2px 12px rgba(99,102,241,0.07);
}

/* ══════════════════
   SECTION TITLE
══════════════════ */
.chc-section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #1e293b;
  margin: 0 0 16px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chc-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  flex-shrink: 0;
}

/* ══════════════════
   INPUT
══════════════════ */
.chc-input-wrap {
  position: relative;
}

.chc-textarea {
  width: 100%;
  height: 200px;
  resize: vertical;
  padding: 12px 14px;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  font-size: 0.95rem;
  outline: none;
  font-family: inherit;
  color: #1e293b;
  background: #ffffff;
  line-height: 1.7;
  transition: border-color 0.18s;
}

.chc-textarea:focus {
  border-color: #818cf8;
  box-shadow: 0 0 0 3px rgba(99,102,241,0.08);
}

.chc-clear-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 7px;
  padding: 4px 12px;
  font-size: 0.80rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  transition: background 0.18s;
}

.chc-clear-btn:hover {
  background: #e2e8f0;
  color: #ef4444;
}

/* ══════════════════
   STATS GRID
══════════════════ */
.chc-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.chc-stat-card {
  border-radius: 12px;
  padding: 16px 14px;
  text-align: center;
  border-left: 4px solid transparent;
  background: #f8f9ff;
  border: 1px solid #e2e8f0;
  transition: transform 0.15s, box-shadow 0.15s;
}

.chc-stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(99,102,241,0.10);
}

.chc-stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1.1;
  margin-bottom: 4px;
}

.chc-stat-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chc-stat-sub {
  font-size: 0.72rem;
  color: #94a3b8;
  margin-top: 3px;
}

/* Accent colours */
.chc-accent-purple .chc-stat-value { color: #7c3aed; }
.chc-accent-blue   .chc-stat-value { color: #2563eb; }
.chc-accent-indigo .chc-stat-value { color: #4338ca; }
.chc-accent-violet .chc-stat-value { color: #7c3aed; }
.chc-accent-sky    .chc-stat-value { color: #0284c7; }
.chc-accent-teal   .chc-stat-value { color: #0d9488; }
.chc-accent-green  .chc-stat-value { color: #16a34a; }
.chc-accent-orange .chc-stat-value { color: #ea580c; }

/* ══════════════════
   BREAKDOWN
══════════════════ */
.chc-breakdown-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chc-breakdown-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.chc-breakdown-bar-wrap {
  height: 8px;
  background: #f1f5f9;
  border-radius: 99px;
  overflow: hidden;
}

.chc-breakdown-bar {
  height: 100%;
  border-radius: 99px;
  transition: width 0.4s ease;
}

.chc-bar-letters   { background: linear-gradient(90deg, #6366f1, #8b5cf6); }
.chc-bar-uppercase { background: linear-gradient(90deg, #3b82f6, #6366f1); }
.chc-bar-lowercase { background: linear-gradient(90deg, #06b6d4, #3b82f6); }
.chc-bar-numbers   { background: linear-gradient(90deg, #f59e0b, #ef4444); }
.chc-bar-spaces    { background: linear-gradient(90deg, #10b981, #06b6d4); }
.chc-bar-special   { background: linear-gradient(90deg, #ec4899, #f43f5e); }

.chc-breakdown-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chc-breakdown-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: #475569;
}

.chc-breakdown-val {
  font-size: 0.82rem;
  font-weight: 700;
  color: #1e293b;
}

/* ══════════════════
   LIMIT CHECKER
══════════════════ */
.chc-limit-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chc-limit-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chc-limit-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chc-limit-name {
  font-size: 0.83rem;
  font-weight: 600;
  color: #475569;
}

.chc-limit-count {
  font-size: 0.80rem;
  font-weight: 700;
  color: #1e293b;
}

.chc-progress-wrap {
  height: 8px;
  background: #f1f5f9;
  border-radius: 99px;
  overflow: hidden;
}

.chc-progress-bar {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
  transition: width 0.4s ease, background 0.3s;
  max-width: 100%;
}

.chc-progress-bar.warn  { background: linear-gradient(90deg, #f59e0b, #ef4444); }
.chc-progress-bar.over  { background: linear-gradient(90deg, #ef4444, #dc2626); }

/* ══════════════════
   TOP WORDS
══════════════════ */
.chc-top-words-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 44px;
  align-items: center;
}

.chc-empty-msg {
  font-size: 0.85rem;
  color: #94a3b8;
  margin: 0;
}

.chc-word-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  background: #f8f9ff;
  border: 1.5px solid #e2e8f0;
  border-radius: 99px;
  padding: 5px 14px 5px 10px;
  font-size: 0.83rem;
  font-weight: 600;
  color: #1e293b;
  transition: border-color 0.18s;
}

.chc-word-chip:hover {
  border-color: #a5b4fc;
}

.chc-word-rank {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  font-size: 0.70rem;
  font-weight: 800;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chc-word-count {
  font-size: 0.75rem;
  color: #94a3b8;
  font-weight: 500;
}

/* ══════════════════
   DARK MODE
══════════════════ */
body.dark-mode #main-section > section {
  background: #0f172a;
  border-color: #1e293b;
}

body.dark-mode .chc-section-title { color: #e2e8f0; }

body.dark-mode .chc-textarea {
  background: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}

body.dark-mode .chc-textarea:focus {
  border-color: #818cf8;
}

body.dark-mode .chc-clear-btn {
  background: #1e293b;
  border-color: #334155;
  color: #94a3b8;
}

body.dark-mode .chc-clear-btn:hover {
  background: #334155;
  color: #ef4444;
}

body.dark-mode .chc-stat-card {
  background: #1e1b4b;
  border-color: #312e81;
}

body.dark-mode .chc-stat-label { color: #94a3b8; }
body.dark-mode .chc-stat-sub   { color: #64748b; }

body.dark-mode .chc-breakdown-bar-wrap,
body.dark-mode .chc-progress-wrap {
  background: #1e293b;
}

body.dark-mode .chc-breakdown-label { color: #94a3b8; }
body.dark-mode .chc-breakdown-val   { color: #e2e8f0; }
body.dark-mode .chc-limit-name      { color: #94a3b8; }
body.dark-mode .chc-limit-count     { color: #e2e8f0; }

body.dark-mode .chc-word-chip {
  background: #1e1b4b;
  border-color: #312e81;
  color: #e2e8f0;
}

body.dark-mode .chc-empty-msg { color: #475569; }

/* ══════════════════
   RESPONSIVE
══════════════════ */
@media (max-width: 900px) {
  .chc-stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 700px) {
  #main-section {
    grid-template-columns: 1fr;
  }

  .chc-input-section,
  .chc-stats-section,
  .chc-breakdown-section,
  .chc-limit-section,
  .chc-topwords-section {
    grid-column: 1 / -1;
  }

  .chc-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 400px) {
  .chc-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}