*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-color: #f6f2ea;
  --bg-page: #fbf9f4;
  --surface-color: #ffffff;
  --surface-hover: #f3efe6;
  --surface-card: #fdfcf9;
  --border-color: #ded8cc;
  --border-focus: #1f6f50;
  --ruled-line: rgba(29, 27, 24, 0.08);
  --text-main: #1d1b18;
  --text-muted: #5a544c;
  --text-dim: #7d766c;
  --accent-color: #1f6f50;
  --accent-hover: #17563e;
  --accent-subtle: rgba(31, 111, 80, 0.1);
  --accent-text: #1f6f50;
  --delete-color: #c0392b;
  --delete-bg: rgba(192, 57, 43, 0.1);
  --track-bg: #e2dcce;
  --font-serif: "Iowan Old Style", Charter, Georgia, serif;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-color: #1c1a17;
    --bg-page: #22201c;
    --surface-color: #272420;
    --surface-hover: #312d28;
    --surface-card: #25221e;
    --border-color: #3d3831;
    --border-focus: #5fbf94;
    --ruled-line: rgba(242, 237, 228, 0.07);
    --text-main: #f2ede4;
    --text-muted: #aba498;
    --text-dim: #827b70;
    --accent-color: #5fbf94;
    --accent-hover: #72cca3;
    --accent-subtle: rgba(95, 191, 148, 0.16);
    --accent-text: #5fbf94;
    --delete-color: #e26d5c;
    --delete-bg: rgba(226, 109, 92, 0.18);
    --track-bg: #35312a;
  }
}

body {
  background-color: var(--bg-color);
  background-image:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.5), transparent 70%),
    linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.02));
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

@media (prefers-color-scheme: dark) {
  body {
    background-image:
      radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.03), transparent 70%),
      linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.25));
  }
}

.site-wrapper {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem 1rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.site-header {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
}

.header-main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 760px) {
  .header-main {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.brand-logo {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: block;
}

.brand-title {
  font-family: var(--font-serif);
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.brand-desc {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.header-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.budget-card {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  min-width: 190px;
}

.budget-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  font-size: 0.75rem;
}

.budget-title {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  font-size: 0.6875rem;
}

.budget-value {
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.meter-track {
  width: 100%;
  height: 4px;
  background: var(--track-bg);
  border-radius: 9999px;
  overflow: hidden;
}

.meter-bar {
  height: 100%;
  background: var(--accent-color);
  transition: width 0.3s ease, background-color 0.3s ease;
  border-radius: 9999px;
}

.meter-bar.low {
  background: #c27803;
}

.meter-bar.empty {
  background: var(--delete-color);
}

.budget-alert {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--delete-color);
  background: var(--delete-bg);
  border: 1px solid var(--delete-color);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.5rem;
}

.lang-select {
  background: var(--surface-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.375rem 0.625rem;
  font-size: 0.8125rem;
  font-family: var(--font-sans);
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.lang-select:focus-visible {
  border-color: var(--border-focus);
  outline: 2px solid var(--border-focus);
  outline-offset: 1px;
}

.editor-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 760px) {
  .editor-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.pane {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.pane-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-page);
  gap: 0.75rem;
  flex-wrap: wrap;
}

.pane-title {
  font-family: var(--font-serif);
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--text-main);
}

.pane-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.lang-group {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.lang-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.counter {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.counter.limit {
  color: var(--delete-color);
  font-weight: 600;
}

.pane-body {
  padding: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 320px;
}

textarea#inputText {
  width: 100%;
  flex: 1;
  min-height: 320px;
  border: none;
  background: transparent;
  color: var(--text-main);
  font-family: var(--font-serif);
  font-size: 1rem;
  line-height: 32px;
  padding: 0.5rem 1.25rem;
  resize: vertical;
  outline: none;
  background-image: repeating-linear-gradient(transparent, transparent 31px, var(--ruled-line) 31px, var(--ruled-line) 32px);
  background-attachment: local;
  box-sizing: border-box;
}

textarea#inputText::placeholder {
  color: var(--text-dim);
  font-style: italic;
}

.output-viewer {
  width: 100%;
  flex: 1;
  min-height: 320px;
  color: var(--text-main);
  font-family: var(--font-serif);
  font-size: 1rem;
  line-height: 32px;
  padding: 0.5rem 1.25rem;
  background-image: repeating-linear-gradient(transparent, transparent 31px, var(--ruled-line) 31px, var(--ruled-line) 32px);
  background-attachment: local;
  white-space: pre-wrap;
  word-break: break-word;
  outline: none;
  overflow-y: auto;
  box-sizing: border-box;
}

.empty-state {
  color: var(--text-dim);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.9375rem;
  line-height: 1.6;
}

.proof-ins,
.diff-highlight {
  text-decoration: underline;
  text-decoration-color: var(--accent-color);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  background-color: var(--accent-subtle);
  color: inherit;
  border-radius: 2px;
  padding: 0 2px;
}

.diff-del {
  color: var(--delete-color);
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
  background-color: var(--delete-bg);
  border-radius: 2px;
  padding: 0 2px;
}

.pane-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-page);
  gap: 0.75rem;
}

@media (max-width: 759px) {
  .pane-input .pane-actions {
    position: sticky;
    bottom: 0;
    background: var(--surface-color);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
    z-index: 10;
  }
}

.action-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.5rem 1.125rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  user-select: none;
  text-decoration: none;
}

.btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-action,
.btn-primary {
  background: var(--accent-color);
  color: #ffffff;
  border-color: var(--accent-color);
}

@media (prefers-color-scheme: dark) {
  .btn-action,
  .btn-primary {
    color: #122119;
  }
}

.btn-action:hover:not(:disabled),
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-card);
  color: var(--text-main);
  border-color: var(--border-color);
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--text-dim);
}

.btn-secondary.copied {
  background: var(--accent-subtle);
  border-color: var(--accent-color);
  color: var(--accent-text);
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  border-top-color: #ffffff;
  animation: spin 0.75s linear infinite;
  display: inline-block;
}

@media (prefers-color-scheme: dark) {
  .spinner {
    border-color: rgba(18, 33, 25, 0.3);
    border-top-color: #122119;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.status-box {
  margin: 0.75rem 1.25rem 0;
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  line-height: 1.4;
}

.status-box.error {
  background: var(--delete-bg);
  border: 1px solid var(--delete-color);
  color: var(--delete-color);
}

.status-box.info {
  background: var(--accent-subtle);
  border: 1px solid var(--accent-color);
  color: var(--accent-text);
}

.changes-panel {
  border-top: 1px solid var(--border-color);
  padding: 0.875rem 1.25rem;
  background: var(--bg-page);
}

.changes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.625rem;
}

.changes-heading {
  font-family: var(--font-serif);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

.badge {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  background: var(--surface-card);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.changes-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 220px;
  overflow-y: auto;
}

.change-card,
.change-item {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}

.change-from {
  color: var(--delete-color);
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
  word-break: break-word;
  font-family: var(--font-serif);
}

.change-arrow {
  color: var(--text-dim);
  font-size: 0.75rem;
}

.change-to {
  color: var(--accent-color);
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 2px;
  font-weight: 600;
  word-break: break-word;
  font-family: var(--font-serif);
}

.pane-bar-actions,
.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.explanation-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.reasons-pane {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.reasons-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  padding: 1rem 1.25rem;
}

.reason-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
}

.reason-num {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-hover);
  border: 1px solid var(--border-color);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 0.125rem;
}

.reason-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.reason-header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.reason-text {
  color: var(--text-muted);
  font-size: 0.8125rem;
  line-height: 1.4;
  margin-top: 0.25rem;
}

.empty-message-card {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 3rem 1.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.empty-message-text {
  color: var(--text-muted);
  font-family: var(--font-serif);
  font-size: 1rem;
  max-width: 480px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

[hidden] {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Refined Additional Features: View Switcher, CEFR Explorer, History, Clear Button */

.pane-actions-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-quiet {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 0.375rem 0.625rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-quiet:hover {
  background: var(--surface-hover);
  color: var(--text-main);
  border-color: var(--border-color);
}

/* View Switcher Segmented Control */
.view-switcher {
  display: inline-flex;
  align-items: center;
  background: var(--surface-hover);
  padding: 0.1875rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  gap: 0.25rem;
}

.view-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.3125rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-family: var(--font-sans);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.view-tab:hover {
  color: var(--text-main);
}

.view-tab.active {
  background: var(--surface-color);
  color: var(--text-main);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* History Trigger & Drawer */
.history-trigger {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}

.history-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.125rem;
  height: 1.125rem;
  padding: 0 0.25rem;
  font-size: 0.6875rem;
  font-weight: 700;
  border-radius: 9999px;
  background: var(--accent-color);
  color: #ffffff;
}

.history-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  z-index: 1000;
  display: flex;
  justify-content: flex-end;
}

.history-drawer {
  width: 100%;
  max-width: 420px;
  height: 100%;
  background: var(--bg-page);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
}

.history-header {
  padding: 1.125rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-title {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  color: var(--text-main);
  font-weight: 600;
}

.history-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.history-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.history-empty {
  color: var(--text-muted);
  font-family: var(--font-serif);
  font-size: 0.9375rem;
  text-align: center;
  margin-top: 3rem;
}

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.history-item {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: border-color 0.15s ease;
}

.history-item:hover {
  border-color: var(--accent-color);
}

.history-item-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.badge-lang {
  font-weight: 600;
  text-transform: uppercase;
  background: var(--track-bg);
  color: var(--text-main);
}

.history-item-date {
  flex: 1;
}

.history-item-preview {
  font-family: var(--font-serif);
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--text-main);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.history-item-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.btn-sm {
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
}

/* CEFR Legend Panel */
.cefr-legend-panel {
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--surface-card);
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.cefr-legend-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.cefr-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-main);
  font-family: var(--font-sans);
}

.cefr-hint {
  font-size: 0.6875rem;
  color: var(--text-dim);
}

.cefr-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  align-items: center;
}

.cefr-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3125rem;
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-family: var(--font-sans);
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  background: var(--surface-color);
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.cefr-chip:hover {
  border-color: var(--border-color);
  color: var(--text-main);
}

.cefr-chip.active {
  box-shadow: 0 0 0 1.5px currentColor;
}

.chip-all.active {
  background: var(--track-bg);
  color: var(--text-main);
  border-color: var(--text-muted);
}

.chip-a1 { color: #2e7d32; background: rgba(46, 125, 50, 0.08); border-color: rgba(46, 125, 50, 0.2); }
.chip-a2 { color: #00897b; background: rgba(0, 137, 123, 0.08); border-color: rgba(0, 137, 123, 0.2); }
.chip-b1 { color: #d97706; background: rgba(217, 119, 6, 0.08); border-color: rgba(217, 119, 6, 0.2); }
.chip-b2 { color: #ea580c; background: rgba(234, 88, 12, 0.08); border-color: rgba(234, 88, 12, 0.2); }
.chip-c1 { color: #7c3aed; background: rgba(124, 58, 237, 0.08); border-color: rgba(124, 58, 237, 0.2); }
.chip-c2 { color: #dc2626; background: rgba(220, 38, 38, 0.08); border-color: rgba(220, 38, 38, 0.2); }

.chip-count {
  font-size: 0.625rem;
  opacity: 0.85;
  padding: 0.05rem 0.3rem;
  border-radius: 9999px;
  background: rgba(0, 0, 0, 0.06);
}

/* Natural Editorial CEFR Prose Typography - NO CHUNKY BOXES */
.cefr-rendered-text {
  font-family: var(--font-serif);
  font-size: 1.0625rem;
  line-height: 1.85;
  color: var(--text-main);
  word-spacing: normal;
}

.cefr-word {
  position: relative;
  display: inline;
  padding: 0 1px;
  cursor: pointer;
  transition: all 0.15s ease;
}

/* Subtle, tasteful bottom accents instead of harsh rectangular borders */
.cefr-word.cefr-lvl-A1 {
  border-bottom: 1px dotted rgba(46, 125, 50, 0.35);
}
.cefr-word.cefr-lvl-A2 {
  border-bottom: 1px dotted rgba(0, 137, 123, 0.45);
}
.cefr-word.cefr-lvl-B1 {
  border-bottom: 2px solid #d97706;
}
.cefr-word.cefr-lvl-B2 {
  border-bottom: 2px solid #ea580c;
}
.cefr-word.cefr-lvl-C1 {
  border-bottom: 2px solid #7c3aed;
  font-weight: 500;
}
.cefr-word.cefr-lvl-C2 {
  border-bottom: 2px solid #dc2626;
  font-weight: 500;
}

.cefr-word:hover {
  background: var(--surface-hover);
  border-radius: 2px;
}

/* Filter Focus State: when user clicks a specific level */
.cefr-word.cefr-highlighted {
  border-radius: 3px;
  padding: 1px 3px;
  font-weight: 600;
}
.cefr-word.cefr-highlighted.cefr-lvl-A1 { background: rgba(46, 125, 50, 0.18); }
.cefr-word.cefr-highlighted.cefr-lvl-A2 { background: rgba(0, 137, 123, 0.18); }
.cefr-word.cefr-highlighted.cefr-lvl-B1 { background: rgba(217, 119, 6, 0.2); color: #b45309; }
.cefr-word.cefr-highlighted.cefr-lvl-B2 { background: rgba(234, 88, 12, 0.2); color: #c2410c; }
.cefr-word.cefr-highlighted.cefr-lvl-C1 { background: rgba(124, 58, 237, 0.2); color: #6d28d9; }
.cefr-word.cefr-highlighted.cefr-lvl-C2 { background: rgba(220, 38, 38, 0.2); color: #b91c1c; }

@media (prefers-color-scheme: dark) {
  .cefr-word.cefr-highlighted.cefr-lvl-B1 { color: #fbbf24; }
  .cefr-word.cefr-highlighted.cefr-lvl-B2 { color: #fb923c; }
  .cefr-word.cefr-highlighted.cefr-lvl-C1 { color: #c084fc; }
  .cefr-word.cefr-highlighted.cefr-lvl-C2 { color: #f87171; }
}

.cefr-word.cefr-dimmed {
  opacity: 0.22;
  border-bottom: none !important;
}

/* Floating Hover Tooltip */
.cefr-floating-tooltip {
  position: absolute;
  z-index: 2000;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.65rem;
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--text-main);
  pointer-events: none;
  animation: fadeIn 0.1s ease-out;
}

.cefr-tooltip-badge {
  font-weight: 700;
  padding: 0.125rem 0.45rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: #ffffff;
}

.lvl-A1 { background: #2e7d32; }
.lvl-A2 { background: #00897b; }
.lvl-B1 { background: #d97706; }
.lvl-B2 { background: #ea580c; }
.lvl-C1 { background: #7c3aed; }
.lvl-C2 { background: #dc2626; }

.cefr-tooltip-word {
  font-weight: 600;
  font-family: var(--font-serif);
}

.cefr-tooltip-desc {
  color: var(--text-muted);
  font-size: 0.75rem;
}


/* Inline Reason on Change Cards */
.change-reason-inline {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-family: var(--font-sans);
  line-height: 1.45;
}

/* Inline Explanation Modal / Drawer */
.explain-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  z-index: 1100;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.25rem;
  box-sizing: border-box;
}

.explain-drawer {
  width: 100%;
  max-width: 680px;
  max-height: 88vh;
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.explain-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  background: var(--bg-page);
}

.explain-title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  color: var(--text-main);
  font-weight: 600;
  margin: 0;
}

.explain-subtitle {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin: 0.25rem 0 0 0;
}

.explain-body {
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.explain-diff-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 600px) {
  .explain-diff-card {
    grid-template-columns: 1fr;
  }
}

.diff-block {
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
}

.diff-label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.diff-content {
  font-family: var(--font-serif);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text-main);
  max-height: 160px;
  overflow-y: auto;
}

.diff-del {
  background: rgba(220, 38, 38, 0.22);
  color: #f87171;
  text-decoration: line-through;
  padding: 0.15rem 0.35rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.explain-reasons-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.explain-reasons-title {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0;
}

.explain-reasons-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.explain-reason-item {
  display: flex;
  gap: 0.75rem;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  align-items: flex-start;
}

.explain-reason-num {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--border-color);
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.explain-reason-content {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
}

.explain-change-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.875rem;
}

.explain-reason-text {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.explain-empty-li {
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 1rem;
  text-align: center;
}

.diff-content .proof-ins {
  background: rgba(16, 185, 129, 0.22);
  color: #34d399;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 0.15rem 0.35rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
}


/* Urban Graffiti Tag for LevioraLabs */
.brand-logo-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.graffiti-tag {
  display: inline-block;
  font-family: 'Impact', 'Arial Black', sans-serif;
  font-style: italic;
  font-weight: 900;
  font-size: 0.6875rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-decoration: none;
  background: linear-gradient(135deg, #facc15 0%, #fde047 35%, #ec4899 50%, #a855f7 80%, #7c3aed 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(1px 1px 0px #000000) drop-shadow(-1px -1px 0px #2e1065) drop-shadow(0 0 6px rgba(168, 85, 247, 0.75));
  transform: rotate(-3deg);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), filter 0.2s ease;
  white-space: nowrap;
  padding: 1px 2px;
}

.graffiti-tag:hover {
  transform: rotate(0deg) scale(1.12);
  filter: drop-shadow(1px 1px 0px #000000) drop-shadow(0 0 12px rgba(250, 204, 21, 0.95)) drop-shadow(0 0 18px rgba(168, 85, 247, 0.9));
}


/* Anime Graffiti Badge */
.brand-logo-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  flex-shrink: 0;
}

.graffiti-link {
  display: inline-block;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

.graffiti-img {
  width: 96px !important;
  max-width: 96px !important;
  height: auto !important;
  display: block !important;
  filter: drop-shadow(0 2px 6px rgba(168, 85, 247, 0.5));
  transform: rotate(-2deg);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), filter 0.2s ease;
}

.graffiti-link:hover .graffiti-img {
  transform: rotate(0deg) scale(1.15);
  filter: drop-shadow(0 4px 14px rgba(250, 204, 21, 0.75)) drop-shadow(0 0 18px rgba(168, 85, 247, 0.85));
}


/* Phase 1 Features: Tone Switcher, Speech, Score, Popover */
.tone-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.tone-select {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 0.35rem 0.65rem;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.tone-select:focus {
  border-color: var(--accent-color);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-playing {
  background: rgba(16, 185, 129, 0.15) !important;
  border-color: rgba(16, 185, 129, 0.5) !important;
  color: #10b981 !important;
  animation: pulseListen 1.5s infinite ease-in-out;
}

@keyframes pulseListen {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
  70% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* CEFR Readiness Score Banner */
.cefr-score-banner {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.875rem 1.125rem;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-bottom: 0.875rem;
}

.score-dial {
  display: flex;
  align-items: baseline;
  gap: 0.15rem;
  padding: 0.5rem 0.875rem;
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.score-number {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
}

.score-max {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.score-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.score-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-main);
}

.score-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
  color: #ffffff;
}

.score-badge.lvl-A1 { background: #00897b; }
.score-badge.lvl-A2 { background: #00acc1; }
.score-badge.lvl-B1 { background: #3949ab; }
.score-badge.lvl-B2 { background: #1e88e5; }
.score-badge.lvl-C1 { background: #d81b60; }
.score-badge.lvl-C2 { background: #8e24aa; }

.score-desc {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Vocabulary Upgrade Popover */
.vocab-upgrade-popover {
  position: absolute;
  z-index: 2200;
  width: 290px;
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  animation: popIn 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

.vocab-popover-header {
  padding: 0.625rem 0.875rem;
  background: var(--bg-page);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.vocab-popover-word-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.vocab-popover-word {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--text-main);
}

.vocab-popover-level {
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-sm);
  background: #00897b;
  color: #ffffff;
}

.vocab-popover-body {
  padding: 0.75rem 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.vocab-upgrade-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.vocab-upgrade-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.vocab-upgrade-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.65rem;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.vocab-upgrade-item:hover {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.4);
  transform: translateX(2px);
}

.vocab-item-word {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-main);
}

.vocab-item-level {
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.1rem 0.3rem;
  border-radius: var(--radius-sm);
  color: #ffffff;
}

.vocab-item-level.lvl-B2 { background: #1e88e5; }
.vocab-item-level.lvl-C1 { background: #d81b60; }
.vocab-item-level.lvl-C2 { background: #8e24aa; }

.vocab-click-hint {
  font-size: 0.6875rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 0.2rem;
}


/* ========================================================
   Custom Editorial Dark Scrollbars
   Replaces default OS / Google Chrome white scrollbars globally
   ======================================================== */
:root {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.22) rgba(0, 0, 0, 0.15);
}

html, body, * {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.22) rgba(0, 0, 0, 0.15);
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.18);
  border-radius: 4px;
}

*::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.22);
  border-radius: 9999px;
  border: 2px solid transparent;
  background-clip: padding-box;
  transition: background-color 0.2s ease;
}

*::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.38);
  background-clip: padding-box;
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

@media (prefers-color-scheme: light) {
  :root, html, body, * {
    scrollbar-color: rgba(0, 0, 0, 0.25) rgba(0, 0, 0, 0.05);
  }
  *::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.06);
  }
  *::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.25);
  }
  *::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.42);
  }
}

/* Enhanced comparison card in Why Did It Change modal */
.explain-comparison {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

.explain-comparison-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  flex-wrap: wrap;
}

.comparison-box {
  flex: 1;
  min-width: 180px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.65rem;
  font-family: var(--font-serif);
  font-size: 0.9375rem;
  line-height: 1.5;
}

.comparison-box.from-box {
  border-left: 3px solid #ef4444;
}

.comparison-box.to-box {
  border-left: 3px solid #10b981;
}

.comparison-tag {
  display: block;
  font-family: var(--font-sans);
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
  color: var(--text-muted);
}


/* ========================================================
   Mobile Polish & Touch Optimization (Phone UX)
   ======================================================== */
@media (max-width: 640px) {
  /* Hide desktop keyboard shortcut on phones */
  .action-hint {
    display: none !important;
  }

  /* Header polish on mobile */
  .header-main {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
  }

  .nav-actions {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  /* Input Pane bar on mobile: compact controls */
  .pane-input .pane-bar {
    padding: 0.625rem 0.875rem;
    gap: 0.5rem;
  }

  .pane-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    justify-content: space-between;
  }

  .lang-group, .tone-group {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
  }

  .lang-label {
    font-size: 0.6875rem;
  }

  .lang-select, .tone-select {
    font-size: 0.75rem;
    padding: 0.35rem 0.5rem;
    min-height: 38px;
  }

  /* Touch-friendly Action Bar */
  .pane-input .pane-actions {
    padding: 0.625rem 0.875rem;
    gap: 0.625rem;
    padding-bottom: calc(0.625rem + env(safe-area-inset-bottom, 0px));
  }

  .pane-actions-left {
    display: flex;
    align-items: center;
  }

  #clearBtn {
    min-height: 44px;
    padding: 0.5rem 0.875rem;
    font-size: 0.875rem;
  }

  .btn-action {
    flex: 1;
    min-height: 44px;
    font-size: 0.9375rem;
    font-weight: 700;
    justify-content: center;
  }

  /* Output Pane Toolbar on mobile */
  .pane-output .pane-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.625rem 0.875rem;
  }

  .view-switcher {
    display: flex;
    width: 100%;
  }

  .view-tab {
    flex: 1;
    text-align: center;
    padding: 0.45rem 0.5rem;
    font-size: 0.8125rem;
    min-height: 38px;
  }

  .pane-bar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    width: 100%;
  }

  .pane-bar-actions .btn {
    flex: 1;
    min-width: 65px;
    padding: 0.4rem 0.5rem;
    font-size: 0.75rem;
    min-height: 38px;
    justify-content: center;
  }

  /* CEFR Score banner on mobile */
  .cefr-score-banner {
    flex-direction: row;
    padding: 0.625rem 0.75rem;
    gap: 0.75rem;
  }

  .score-dial {
    padding: 0.35rem 0.6rem;
  }

  .score-number {
    font-size: 1.25rem;
  }

  .score-title {
    font-size: 0.8125rem;
  }

  .score-desc {
    font-size: 0.75rem;
  }

  /* Explain Modal on mobile */
  .explain-drawer {
    width: 95%;
    max-height: 90vh;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
  }
}


/* Live Writing Statistics & Flash Upgrade */
.counter-stats {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.04);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

@keyframes flashUpgrade {
  0% { background: rgba(16, 185, 129, 0.45); transform: scale(1.05); }
  50% { background: rgba(16, 185, 129, 0.25); }
  100% { background: transparent; transform: scale(1); }
}

.vocab-upgraded-flash {
  display: inline-block;
  animation: flashUpgrade 1.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  border-radius: 3px;
}


/* Go To Games Navigation Button */
.btn-games-nav {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: linear-gradient(135deg, rgba(72, 187, 120, 0.15) 0%, rgba(159, 122, 234, 0.22) 100%);
  border: 1px solid rgba(159, 122, 234, 0.45);
  color: #f0f2f5;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.9rem;
  text-decoration: none;
  transition: all 0.2s ease;
  min-height: 40px;
}

.btn-games-nav:hover {
  border-color: var(--accent, #48bb78);
  box-shadow: 0 0 16px rgba(72, 187, 120, 0.35);
  transform: translateY(-1px);
}

.games-nav-badge {
  font-size: 0.65rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
  background: #e53e3e;
  color: #ffffff;
  letter-spacing: 0.5px;
}

.model-badge-subtle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.25rem;
  font-size: 0.6875rem;
  color: var(--text-muted, #94a3b8);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  opacity: 0.75;
  user-select: none;
  letter-spacing: 0.02em;
}

.model-badge-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #10b981;
  display: inline-block;
  opacity: 0.9;
  flex-shrink: 0;
}
