/* ========================================
   Word Counter — Editor's Desk Theme
   ======================================== */

:root {
  --bg-primary: #faf6ef;
  --bg-panel: #f0ebe2;
  --bg-input: #fffdf8;
  --text-primary: #2d2a26;
  --text-secondary: #5c4d3c;
  --text-tertiary: #8a7b6b;
  --accent-primary: #c45d3e;
  --accent-secondary: #3d5a80;
  --accent-success: #5a8f6e;
  --accent-warning: #d4a03a;
  --accent-danger: #c0392b;
  --border-color: #e0d8cc;
  --border-light: #ebe5db;
  --shadow-sm: 0 1px 3px rgba(45, 42, 38, 0.06);
  --shadow-md: 0 4px 16px rgba(45, 42, 38, 0.08);
  --radius-sm: 6px;
  --radius-md: 10px;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --font-body: 'Source Sans 3', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

html {
  font-size: 16px;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  position: relative;
}

/* Paper texture overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
  background-size: 200px 200px;
  pointer-events: none;
  z-index: 0;
}

.container {
  position: relative;
  z-index: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 24px 48px;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-color);
}

.title {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.subtitle {
  font-family: var(--font-body);
  font-size: 1.05rem;
  color: var(--text-secondary);
  font-weight: 400;
}

/* Main layout */
.main {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 28px;
  align-items: start;
}

/* Editor section */
.editor-section {
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.editor-toolbar {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-light);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn:hover {
  background: var(--bg-primary);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.btn:active {
  transform: translateY(1px);
}

.btn svg {
  flex-shrink: 0;
}

.text-input {
  width: 100%;
  min-height: 520px;
  padding: 20px 22px;
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.75;
  color: var(--text-primary);
  background: transparent;
  border: none;
  outline: none;
  resize: vertical;
  tab-size: 2;
}

.text-input::placeholder {
  color: var(--text-tertiary);
  font-style: italic;
}

.text-input:focus {
  background: #fffefa;
}

/* Limit bar */
.limit-bar-wrapper {
  padding: 14px 18px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.limit-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.limit-selector label {
  font-weight: 600;
}

.limit-selector select {
  padding: 5px 10px;
  font-family: var(--font-body);
  font-size: 0.88rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  cursor: pointer;
}

.custom-limit-input {
  width: 100px;
  padding: 5px 10px;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
}

.limit-progress {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}

.limit-track {
  flex: 1;
  height: 8px;
  background: var(--border-light);
  border-radius: 4px;
  overflow: hidden;
}

.limit-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-success);
  border-radius: 4px;
  transition: width 0.3s ease, background 0.3s ease;
}

.limit-fill.warning {
  background: var(--accent-warning);
}

.limit-fill.danger {
  background: var(--accent-danger);
}

.limit-text {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.limit-text.over {
  color: var(--accent-danger);
  font-weight: 700;
}

/* Stats panel */
.stats-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.stats-group {
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
}

.stats-group-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
  letter-spacing: 0.01em;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-light);
}

.stat-row:last-child {
  border-bottom: none;
}

.stat-label {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  transition: color 0.2s ease;
}

.stat-highlight {
  font-size: 1.2rem;
  color: var(--accent-primary);
}

.stat-longest {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.stat-longest-word {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.stat-sublabel {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-tertiary);
}

/* Keyword density */
.keyword-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.keyword-empty {
  font-size: 0.88rem;
  color: var(--text-tertiary);
  font-style: italic;
  padding: 8px 0;
}

.keyword-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 8px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}

.keyword-word {
  font-family: var(--font-mono);
  color: var(--text-primary);
  font-weight: 500;
}

.keyword-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.keyword-count {
  font-family: var(--font-mono);
  color: var(--text-secondary);
  font-size: 0.82rem;
}

.keyword-bar-track {
  width: 60px;
  height: 5px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
}

.keyword-bar-fill {
  height: 100%;
  background: var(--accent-secondary);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.keyword-density {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-tertiary);
  min-width: 42px;
  text-align: right;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  padding: 10px 22px;
  background: var(--text-primary);
  color: var(--bg-input);
  font-size: 0.92rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  z-index: 100;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* Responsive */
@media (max-width: 900px) {
  .main {
    grid-template-columns: 1fr;
  }
  .text-input {
    min-height: 280px;
  }
  .stats-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
  }
}

@media (max-width: 520px) {
  .container {
    padding: 20px 14px 32px;
  }
  .title {
    font-size: 1.9rem;
  }
  .limit-bar-wrapper {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .limit-progress {
    min-width: auto;
  }
  .stats-panel {
    grid-template-columns: 1fr;
  }
}
