/**********************************************
 * Global box-sizing
 **********************************************/
.character-counter-container,
.character-counter-container *,
.character-counter-container *::before,
.character-counter-container *::after {
  box-sizing: border-box;
}

/**********************************************
 * CSS Variables - Light Mode (Default)
 **********************************************/
.character-counter-container {
  /* Background colors */
  --bg-primary: #f5f5f0;
  --bg-secondary: #fff;
  --bg-section: #fff;
  
  /* Borders */
  --border-color: #333;
  
  /* Text colors */
  --text-primary: #222;
  --text-secondary: #555;
  --text-light: #666;
  
  /* Brand colors */
  --color-accent: #3498db;
  --color-success: #27ae60;
  --color-warning: #f39c12;
  --color-danger: #e74c3c;
  --color-purple: #9b59b6;
  --color-teal: #1abc9c;
  
  /* Shadows (neobrutalism) */
  --shadow-sm: 2px 2px 0 rgba(0,0,0,0.1);
  --shadow-md: 4px 4px 0 rgba(0,0,0,0.15);
  --shadow-lg: 8px 8px 0 rgba(0,0,0,0.15);
  
  /* Border radius */
  --radius-container: 8px;
  --radius-section: 6px;
  --radius-button: 4px;
  --radius-input: 4px;
  
  /* Input focus */
  --input-focus-bg: #fffacd;
  
  /* Header title */
  --title-color: #2c3e50;
  --title-shadow: 2px 2px 0 rgba(255,255,255,0.5);
  
  /* Button hover background */
  --btn-hover-overlay: rgba(0,0,0,0.1);
  
  /* Copy button background */
  --copy-btn-bg: #fff;
  --copy-btn-hover-bg: #f0f0f0;
}

/**********************************************
 * CSS Variables - Dark Mode (Manual Toggle)
 **********************************************/
.character-counter-container.dark {
  /* Background colors */
  --bg-primary: #1a1a1a;
  --bg-secondary: #2d2d2d;
  --bg-section: #2d2d2d;
  
  /* Borders */
  --border-color: #e0e0e0;
  
  /* Text colors */
  --text-primary: #e8e8e8;
  --text-secondary: #b0b0b0;
  --text-light: #909090;
  
  /* Brand colors */
  --color-accent: #5dade2;
  --color-success: #52c77a;
  --color-warning: #f5b041;
  --color-danger: #ec7063;
  --color-purple: #af7ac5;
  --color-teal: #48d1cc;
  
  /* Shadows */
  --shadow-sm: 2px 2px 0 rgba(255,255,255,0.08);
  --shadow-md: 4px 4px 0 rgba(255,255,255,0.12);
  --shadow-lg: 8px 8px 0 rgba(255,255,255,0.12);
  
  /* Input focus */
  --input-focus-bg: #3a3a3a;
  
  /* Header title */
  --title-color: #7fb3d5;
  --title-shadow: 2px 2px 0 rgba(0,0,0,0.5);
  
  /* Button hover background */
  --btn-hover-overlay: rgba(255,255,255,0.1);
  
  /* Copy button background */
  --copy-btn-bg: #3a3a3a;
  --copy-btn-hover-bg: #4a4a4a;
}

/**********************************************
 * System Dark Mode Auto Detection
 **********************************************/
@media (prefers-color-scheme: dark) {
  .character-counter-container:not(.dark):not(.light) {
    /* Background colors */
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-section: #2d2d2d;
    
    /* Borders */
    --border-color: #e0e0e0;
    
    /* Text colors */
    --text-primary: #e8e8e8;
    --text-secondary: #b0b0b0;
    --text-light: #909090;
    
    /* Brand colors */
    --color-accent: #5dade2;
    --color-success: #52c77a;
    --color-warning: #f5b041;
    --color-danger: #ec7063;
    --color-purple: #af7ac5;
    --color-teal: #48d1cc;
    
    /* Shadows */
    --shadow-sm: 2px 2px 0 rgba(255,255,255,0.08);
    --shadow-md: 4px 4px 0 rgba(255,255,255,0.12);
    --shadow-lg: 8px 8px 0 rgba(255,255,255,0.12);
    
    /* Input focus */
    --input-focus-bg: #3a3a3a;
    
    /* Header title */
    --title-color: #7fb3d5;
    --title-shadow: 2px 2px 0 rgba(0,0,0,0.5);
    
    /* Button hover background */
    --btn-hover-overlay: rgba(255,255,255,0.1);
    
    /* Copy button background */
    --copy-btn-bg: #3a3a3a;
    --copy-btn-hover-bg: #4a4a4a;
  }
}

/**********************************************
 * Dark Mode Toggle Button
 **********************************************/
.dark-mode-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 6px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-button);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
  font-size: 17.5px;
  font-weight: 600;
  color: var(--text-primary);
  z-index: 10;
}

.dark-mode-toggle:hover {
  transform: translate(0.5px, 0.5px);
  box-shadow: 1.5px 1.5px 0 rgba(0,0,0,0.15);
}

.dark-mode-toggle:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

/**********************************************
 * Main Container
 **********************************************/
.character-counter-container {
  position: relative;
  max-width: 1000px;
  width: 100%;
  margin: 8px auto;
  padding: 8px;
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-container);
  font-family: 'Noto Sans KR', 'Malgun Gothic', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  line-height: 1.5;
}

/**********************************************
 * Header
 **********************************************/
.header {
  text-align: center;
  padding: 8px 0;
  border-bottom: 3px double var(--border-color);
  margin-bottom: 8px;
}

.header h2 {
  font-size: 30px;
  font-weight: 700;
  color: var(--title-color);
  text-shadow: var(--title-shadow);
  margin: 0 0 4px 0;
  letter-spacing: -0.5px;
}

.subtitle {
  font-size: 16px;
  color: var(--text-secondary);
  margin: 0;
}

/**********************************************
 * Main Grid (2 Columns)
 **********************************************/
.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

/**********************************************
 * Sections
 **********************************************/
.input-section,
.result-section {
  background: var(--bg-section);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-section);
  padding: 8px;
  box-shadow: var(--shadow-md);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border-color);
}

.section-header svg {
  color: var(--color-accent);
  flex-shrink: 0;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

/**********************************************
 * Input Area
 **********************************************/
#textInput {
  width: 100%;
  min-height: 250px;
  padding: 7px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-input);
  font-size: 16px;
  font-family: 'Noto Sans KR', 'Malgun Gothic', -apple-system, BlinkMacSystemFont, sans-serif;
  resize: vertical;
  box-shadow: inset 1px 1px 2px rgba(0,0,0,0.1);
  transition: all 0.2s;
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
}

#textInput:focus {
  outline: none;
  background: var(--input-focus-bg);
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

#textInput::placeholder {
  color: var(--text-light);
}

.input-limit {
  margin-top: 6px;
  font-size: 15px;
  color: var(--text-secondary);
  text-align: right;
  font-family: 'Courier New', monospace;
}

/**********************************************
 * Buttons
 **********************************************/
.button-group {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.btn {
  padding: 7px 12px;
  border-radius: var(--radius-button);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  white-space: nowrap;
}

.btn svg {
  flex-shrink: 0;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
  border: 1.5px solid var(--border-color);
  box-shadow: var(--shadow-md);
}

.btn-primary:hover {
  transform: translate(1px, 1px);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.15);
}

.btn-primary:active {
  transform: translate(4px, 4px);
  box-shadow: none;
}

.btn-success {
  background: var(--color-success);
  color: #fff;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
}

.btn-success:hover {
  transform: translate(1px, 1px);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.15);
}

.btn-success:active {
  transform: translate(4px, 4px);
  box-shadow: none;
}

.btn-warning {
  background: var(--color-warning);
  color: #fff;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
}

.btn-warning:hover {
  transform: translate(1px, 1px);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.15);
}

.btn-warning:active {
  transform: translate(4px, 4px);
  box-shadow: none;
}

.btn-full-width {
  width: 100%;
  justify-content: center;
}

/**********************************************
 * Result Items
 **********************************************/
.result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-color);
}

.result-item:last-child {
  border-bottom: none;
}

.result-label {
  color: var(--text-secondary);
  font-size: 15px;
}

.result-value {
  font-weight: 700;
  color: var(--color-accent);
  font-size: 18px;
  font-family: 'Courier New', monospace;
}

/**********************************************
 * Additional Features
 **********************************************/
.additional-features {
  background: var(--bg-section);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-section);
  padding: 8px;
  box-shadow: var(--shadow-md);
  margin-bottom: 8px;
}

.additional-features .section-title {
  font-size: 18px;
  padding-bottom: 6px;
  margin-bottom: 8px;
  border-bottom: 2px solid var(--border-color);
}

/**********************************************
 * Feature Tabs
 **********************************************/
.feature-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 6px 12px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-button);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
  font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
}

.tab-btn:hover {
  transform: translate(0.5px, 0.5px);
  box-shadow: 1.5px 1.5px 0 rgba(0,0,0,0.1);
}

.tab-btn:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

.tab-btn.active {
  background: var(--color-accent);
  color: #fff;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/**********************************************
 * Feature Groups
 **********************************************/
.feature-group {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-section);
  padding: 8px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
}

.feature-group:last-child {
  margin-bottom: 0;
}

.feature-header {
  margin-bottom: 8px;
}

.feature-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.feature-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
}

/**********************************************
 * Keyword Cloud
 **********************************************/
.keyword-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  padding: 8px 0;
}

.keyword-item {
  display: inline-flex;
  align-items: center;
  background: var(--bg-primary);
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}

.keyword-item:hover {
  transform: translate(0.5px, 0.5px);
  box-shadow: 1.5px 1.5px 0 rgba(0,0,0,0.1);
}

.keyword-text {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 15px;
}

.keyword-count {
  margin-left: 4px;
  background: var(--color-accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  border-radius: 8px;
  padding: 2px 5px;
  min-width: 18px;
  text-align: center;
}

.keyword-primary {
  background: var(--color-accent);
  border-color: var(--color-accent);
}

.keyword-primary .keyword-text {
  color: #fff;
}

.keyword-primary .keyword-count {
  background: rgba(255,255,255,0.3);
}

.keyword-secondary {
  background: var(--color-success);
  border-color: var(--color-success);
}

.keyword-secondary .keyword-text {
  color: #fff;
}

.keyword-secondary .keyword-count {
  background: rgba(255,255,255,0.3);
}

/**********************************************
 * Reading Stats
 **********************************************/
.reading-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.reading-stat {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-section);
  padding: 8px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.reading-stat-label {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.reading-stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-accent);
}

/**********************************************
 * Reading Guide
 **********************************************/
.reading-guide {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.reading-guide-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-secondary);
}

.reading-guide-icon {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}

.reading-guide-icon.easy {
  background: var(--color-success);
}

.reading-guide-icon.medium {
  background: var(--color-warning);
}

.reading-guide-icon.hard {
  background: var(--color-danger);
}

/**********************************************
 * SEO Status Container
 **********************************************/
.seo-status-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.seo-gauge {
  text-align: center;
}

.seo-meter {
  width: 200px;
  height: 100px;
  position: relative;
  margin: 0 auto 10px;
  overflow: hidden;
}

.seo-meter:before {
  content: "";
  position: absolute;
  width: 200px;
  height: 200px;
  border: 3px solid var(--border-color);
  border-radius: 50%;
  top: 0;
  left: 0;
  clip-path: polygon(0 50%, 100% 50%, 100% 100%, 0 100%);
  box-shadow: var(--shadow-sm);
}

.seo-meter:after {
  content: "";
  position: absolute;
  width: 160px;
  height: 160px;
  background: var(--bg-primary);
  border-radius: 50%;
  top: 20px;
  left: 20px;
  z-index: 1;
}

.seo-needle {
  position: absolute;
  width: 3px;
  height: 90px;
  background: var(--color-danger);
  bottom: 0;
  left: 98px;
  transform-origin: bottom center;
  transition: transform 0.5s ease;
  z-index: 3;
  border-radius: 2px;
  box-shadow: 0 0 4px rgba(0,0,0,0.3);
}

.seo-scale {
  display: flex;
  justify-content: space-between;
  width: 180px;
  margin: 0 auto;
  position: relative;
  z-index: 4;
  padding-top: 8px;
}

.seo-marker {
  position: relative;
  text-align: center;
  width: 40px;
}

.seo-marker:before {
  content: "";
  position: absolute;
  width: 2px;
  height: 8px;
  background: var(--border-color);
  top: -15px;
  left: 50%;
  transform: translateX(-50%);
}

.seo-marker span {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
}

.seo-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-accent);
  margin-top: 8px;
}

.seo-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--bg-primary);
  padding: 8px;
  border-radius: var(--radius-section);
  border: 1px solid var(--border-color);
}

.seo-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.seo-stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

.seo-stat-value {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  font-family: 'Courier New', monospace;
}

/**********************************************
 * SEO Tips List
 **********************************************/
.seo-tips-list {
  padding-left: 18px;
  margin: 0;
}

.seo-tip {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  line-height: 1.5;
}

.seo-tip:last-child {
  margin-bottom: 0;
}

/**********************************************
 * Keyword Density Chart
 **********************************************/
.keyword-density-chart {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.density-bar-container {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--radius-section);
  transition: background 0.2s;
}

.density-bar-container:hover {
  background: var(--bg-primary);
}

.density-keyword {
  min-width: 80px;
  max-width: 100px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
}

.density-bar-wrapper {
  flex-grow: 1;
  height: 18px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 9px;
  overflow: hidden;
  position: relative;
}

.density-bar {
  height: 100%;
  border-radius: 9px;
  transition: width 0.5s ease;
}

.density-bar-good {
  background: var(--color-success);
}

.density-bar-warning {
  background: var(--color-warning);
}

.density-bar-optimal {
  background: var(--color-accent);
}

.density-value {
  min-width: 70px;
  text-align: right;
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 600;
  font-family: 'Courier New', monospace;
}

.density-marker {
  position: absolute;
  top: 0;
  height: 100%;
  width: 2px;
  background: var(--border-color);
  z-index: 2;
}

.density-marker-1 {
  left: 10%;
}

.density-marker-3 {
  left: 30%;
}

.density-markers-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-light);
  padding: 0 5px;
  margin-top: 2px;
}

/**********************************************
 * Empty Message
 **********************************************/
.empty-message {
  color: var(--text-light);
  font-style: italic;
  font-size: 15px;
  text-align: center;
  padding: 20px 0;
}

/**********************************************
 * Toast Notification
 **********************************************/
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--color-success);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius-button);
  border: 2px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  font-size: 16px;
  font-weight: 600;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
  max-width: 90%;
}

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

.toast.warning {
  background: var(--color-warning);
}

.toast.error {
  background: var(--color-danger);
}

/**********************************************
 * Responsive Design
 **********************************************/
@media screen and (max-width: 768px) {
  .character-counter-container {
    margin: 6px 5px;
    width: calc(100% - 10px);
    padding: 7px;
  }
  
  .main-grid {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  
  .header h2 {
    font-size: 26px;
  }
  
  .subtitle {
    font-size: 15px;
  }
  
  #textInput {
    min-height: 200px;
  }
  
  .button-group {
    flex-wrap: wrap;
  }
  
  .btn {
    flex: 1;
    min-width: 0;
    justify-content: center;
  }
  
  .reading-stats {
    grid-template-columns: 1fr;
  }
  
  .seo-stats {
    grid-template-columns: 1fr;
  }
  
  .feature-tabs {
    gap: 4px;
  }
  
  .tab-btn {
    flex: 1;
    font-size: 14px;
    padding: 6px 8px;
  }
}

@media screen and (max-width: 480px) {
  .character-counter-container {
    padding: 6px;
    border-width: 1px;
  }
  
  .header h2 {
    font-size: 22px;
  }
  
  .section-title {
    font-size: 16px;
  }
  
  .result-label,
  .result-value {
    font-size: 14px;
  }
  
  .dark-mode-toggle {
    padding: 4px 8px;
    font-size: 16px;
  }
}