:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  
  --background: #1C1C1C;
  --foreground: #EAEAEA;
  --card-background: #2B2B2B;
  --card-border: #3D3D3D;
  
  --primary: #C0A04E;
  --primary-hover: #D9B86A;
  --primary-disabled: #555;
  --primary-foreground: #1C1C1C;
  --success-color: #4CAF50;
  --error-color: #f44336;
  
  --input-background: #333333;
  --input-border: #4D4D4D;
  --input-focus-ring: rgba(192, 160, 78, 0.3);
  
  --text-muted: #888888;
  --text-error: #E57373;
  --badge-bg: #4e4019;
  --badge-text: #ffe08a;

  --header-border: #3D3D3D;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background-color: var(--background);
  color: var(--foreground);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    margin: 0;
    font-weight: 600;
    color: var(--foreground);
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  padding: 1rem;
  border-bottom: 1px solid var(--header-border);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

.header-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 1.5rem;
}

.header-nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  transition: color 0.2s;
}

.header-nav a:hover {
  color: var(--foreground);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.coin-balance {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--primary);
  font-weight: 600;
}

.btn-logout {
  background: none;
  border: 1px solid var(--input-border);
  color: var(--text-muted);
  padding: 0.3rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}
.btn-logout:hover {
  background-color: var(--input-border);
  color: var(--foreground);
}

.login-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
  margin-top: 0.25rem;
}

.data-sources-header {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

.data-sources-header a {
    color: var(--text-muted);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: color 0.2s;
}

.data-sources-header a:hover {
    color: var(--foreground);
}

.app-main {
  flex-grow: 1;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  width: 100%;
}

.page-intro {
    text-align: center;
    margin-bottom: 1rem;
    max-width: 700px;
}

.page-intro h1 {
    font-size: 2rem;
    font-weight: 800;
    margin: 0 0 0.75rem;
    color: var(--foreground);
    line-height: 1.2;
}

.page-intro p {
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1.6;
    max-width: 600px;
    margin: 0 auto;
}

.search-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  width: 100%;
  max-width: 500px;
  margin-bottom: 1rem;
}

.search-form {
  position: relative;
  width: 100%;
}

.search-form input[type="search"] {
  width: 100%;
  padding: 1rem 3rem 1rem 1.5rem;
  font-size: 1rem;
  border-radius: 9999px;
  border: 1px solid var(--input-border);
  background-color: var(--input-background);
  color: var(--foreground);
}
.search-form input[type="search"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--input-focus-ring);
}
.search-form .search-button {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.search-form .search-button:hover {
  color: var(--foreground);
}

.intro {
  text-align: center;
  margin-bottom: 0;
  max-width: 600px;
}

.intro h2 {
  font-size: 2rem;
  font-weight: 800;
  margin: 0 0 0.5rem;
  color: var(--primary);
}

.intro p {
  color: var(--text-muted);
  font-size: 1.125rem;
  line-height: 1.6;
}

.cleaner-card {
  background-color: var(--card-background);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 700px;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -2px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
}

.input-area, .output-area {
  margin-bottom: 1.5rem;
}

.input-area {
    position: relative;
}

.output-area {
    margin-top: 2rem;
    opacity: 0;
    animation: fadeIn 0.5s ease-in-out forwards;
}

.input-area > label, .diff-pane > label, .api-key-card label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--foreground);
}

.output-header > label {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0;
    color: var(--foreground);
}

textarea, .api-key-card input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  background-color: var(--input-background);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
textarea {
  min-height: 150px;
  resize: vertical;
}

textarea:focus, .api-key-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--input-focus-ring);
}

textarea:disabled {
    background-color: color-mix(in srgb, var(--card-border) 50%, transparent);
    cursor: not-allowed;
}

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

.char-count-badge {
    position: absolute;
    top: 0;
    right: 0;
    background-color: var(--badge-bg);
    color: var(--badge-text);
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 9999px;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

.clean-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary-foreground);
  background-color: var(--primary);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s;
  width: 100%;
}

.clean-button:hover {
  background-color: var(--primary-hover);
}

.clean-button:disabled {
  background-color: var(--primary-disabled);
  color: var(--text-muted);
  cursor: not-allowed;
}

.clean-button svg {
    width: 20px;
    height: 20px;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes fadeIn {
  to { opacity: 1; }
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toggle-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin: 0;
    cursor: pointer;
}

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 24px;
  flex-shrink: 0;
}

.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #4D4D4D;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
}

input:checked + .slider {
  background-color: var(--primary);
}

input:focus + .slider {
  box-shadow: 0 0 1px var(--primary);
}

input:checked + .slider:before {
  transform: translateX(16px);
}

.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

.copy-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    transition: background-color 0.2s, color 0.2s;
}
.copy-button:hover {
    background-color: color-mix(in srgb, var(--card-border) 50%, transparent);
    color: var(--foreground);
}
.copy-button svg {
    width: 16px;
    height: 16px;
}

.error-message {
    margin-top: 1rem;
    color: var(--text-error);
    background-color: color-mix(in srgb, var(--text-error) 10%, transparent);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-align: left;
}

.error-message svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.app-footer {
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.875rem;
  width: 100%;
  max-width: 700px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.dopamine-text {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.dopamine-text .dot {
  width: 12px;
  height: 12px;
  background-color: var(--primary);
  border-radius: 50%;
  flex-shrink: 0;
}

.dopamine-text a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}
.dopamine-text a:hover {
  text-decoration: underline;
}

.faucet-text {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.faucet-text:hover {
    color: var(--foreground);
}

.faucet-tag {
  background-color: var(--card-border);
  color: var(--foreground);
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
}


.character-table-container {
    margin-top: 1.5rem;
}
.character-table-container h4 {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}
.character-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.character-table th, .character-table td {
    border: 1px solid var(--card-border);
    padding: 0.5rem 0.75rem;
    text-align: left;
}
.character-table th {
    background-color: color-mix(in srgb, var(--card-border) 50%, transparent);
}
.character-table td:first-child {
    font-family: monospace;
}
.character-table td:nth-child(3) {
    word-break: break-all;
    max-width: 150px;
}

.diff-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-top: 1rem;
}
@media (min-width: 640px) {
    .diff-container {
        grid-template-columns: 1fr 1fr;
    }
}

.diff-pane h4 {
    font-size: 0.875rem;
    font-weight: 500;
    margin: 0 0 0.5rem;
}
.diff-content {
    min-height: 100px;
    background-color: var(--input-background);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    padding: 0.75rem;
    font-size: 1rem;
    white-space: pre-wrap;
    word-break: break-word;
}
.diff-deleted {
    background-color: #442121;
    color: #f87171;
    text-decoration: none;
    border-radius: 3px;
    padding: 0.1rem 0.2rem;
}
.diff-inserted {
    background-color: #2c5237;
    color: #9ae6b4;
    text-decoration: none;
    border-radius: 3px;
    padding: 0.1rem 0.2rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 1rem;
    text-align: center;
}

.stat-item {
    background-color: color-mix(in srgb, var(--card-border) 50%, transparent);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--card-border);
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.word-freq-chart {
    margin-top: 2rem;
}

.word-freq-chart h4 {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
}

.bar-item {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.bar-label {
    width: 120px;
    text-align: right;
    padding-right: 0.75rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-container {
    flex-grow: 1;
    height: 20px;
    background-color: var(--card-border);
    border-radius: 4px;
    overflow: hidden;
}

.bar {
    height: 100%;
    background-color: var(--primary);
    transition: width 0.3s ease-in-out;
}

.bar-value {
    width: 40px;
    text-align: left;
    padding-left: 0.75rem;
    font-weight: 500;
}

.safe-char-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.safe-char-list li {
    background-color: color-mix(in srgb, var(--card-border) 50%, transparent);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--card-border);
}

.safe-char-list li strong {
    font-weight: 600;
    color: var(--foreground);
    font-size: 1rem;
    display: block;
    margin-bottom: 0.25rem;
}

.safe-char-list li strong code {
    font-family: monospace;
    background-color: var(--badge-bg);
    color: var(--badge-text);
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    font-size: 0.9em;
}

.safe-char-list li p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.875rem;
    line-height: 1.6;
}

.api-key-card .api-key-input-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.api-key-card .api-key-input-group input {
    flex-grow: 1;
    min-width: 200px;
    min-height: auto;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}

.api-key-card .api-key-input-group button {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
    border: 1px solid transparent;
    cursor: pointer;
    border-radius: 6px;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}

.api-key-card .api-key-input-group button.api-key-save {
    background-color: var(--primary);
    color: var(--primary-foreground);
}

.api-key-card .api-key-input-group button.api-key-save:hover {
    background-color: var(--primary-hover);
}

.api-key-card .api-key-input-group button.api-key-clear {
    background-color: transparent;
    color: var(--text-muted);
    border-color: var(--input-border);
}

.api-key-card .api-key-input-group button.api-key-clear:hover {
    background-color: var(--card-border);
    color: var(--foreground);
}


.api-key-card .api-key-input-group button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.api-key-card .api-key-status {
    margin-top: 1rem;
    margin-bottom: 0;
    font-size: 0.875rem;
    color: var(--primary);
    background-color: color-mix(in srgb, var(--primary) 10%, transparent);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    text-align: center;
    border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);
}

.login-form-container {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--card-border);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: flex-start;
}
.login-form.shake {
  animation: shake 0.5s;
}

.login-form-inputs {
    display: flex;
    gap: 0.5rem;
    width: 100%;
}

.login-form input {
  flex-grow: 1;
  width: auto;
  min-height: auto;
}

.login-form .btn-login-register {
  background-color: var(--success-color);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.875rem;
  white-space: nowrap;
  transition: background-color 0.2s;
}
.login-form .btn-login-register:hover {
    background-color: color-mix(in srgb, var(--success-color) 90%, black);
}


@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

.coin-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background-color: var(--primary);
  color: var(--primary-foreground);
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  font-weight: 600;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  animation: slideInAndOut 2s ease-in-out forwards;
}

@keyframes slideInAndOut {
  0% { transform: translateX(120%); opacity: 0; }
  20% { transform: translateX(0); opacity: 1; }
  80% { transform: translateX(0); opacity: 1; }
  100% { transform: translateX(120%); opacity: 0; }
}

@media (min-width: 640px) {
    .controls {
        flex-direction: row;
        justify-content: space-between;
    }
    .clean-button {
        width: auto;
    }
    .app-main {
        padding: 2rem 1rem;
    }
    .page-intro h1 {
        font-size: 2.5rem;
    }
}