/* ── VARIABLES ── */
:root {
  --bg: #F9F9F7;
  --surface: #FFFFFF;
  --ink: #111111;
  --ink-muted: #5E5C58;
  --ink-faint: #A6A4A0;
  --accent: #DD4A3D;
  --accent-hover: #C53B2F;

  --hl-hard: #FFEBEB;
  --hl-hard-border: #FF8A8A;
  --hl-vhard: #FFD6D6;
  --hl-vhard-border: #E63946;
  --hl-passive: #FFF6DB;
  --hl-passive-border: #F4A261;
  --hl-adverb: #E7F6E7;
  --hl-adverb-border: #4CAF50;
  --hl-complex: #ECF4FC;
  --hl-complex-border: #457B9D;
  --hl-weak: #F4EBFB;
  --hl-weak-border: #9D4EDD;
  --hl-grammar: rgba(43, 108, 176, 0.15);
  --hl-grammar-border: #2B6CB0;
  --hl-spelling: rgba(221, 74, 61, 0.15);
  --hl-spelling-border: var(--accent);

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 12px 32px rgba(0, 0, 0, 0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* ── CUSTOM SCROLLBAR ── */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: var(--radius-pill);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

/* ── RESET ── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 100% 0%, rgba(221, 74, 61, 0.04) 0%, transparent 35%),
    radial-gradient(circle at 0% 100%, rgba(69, 123, 157, 0.04) 0%, transparent 35%);
  color: var(--ink);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.ad-footer {
  background: transparent;
  border-top: none;
  display: flex;
  align-items: center;
  padding: 0 16px;
  min-height: 90px;
  flex-shrink: 0;
  grid-column: 2;
}

.ad-sidebar {
  margin: 20px 18px;
  border-radius: var(--radius-md);
  background: var(--bg);
  border: 1px dashed rgba(0, 0, 0, 0.15);
  min-height: 270px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: var(--transition);
}

.ad-sidebar:hover {
  background: var(--surface);
  border-color: rgba(0, 0, 0, 0.25);
  box-shadow: var(--shadow-sm);
}

.ad-label {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 9px;
  color: var(--ink-faint);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-family: 'DM Mono', monospace;
  font-weight: 500;
}

.ad-placeholder {
  background: rgba(0, 0, 0, 0.02);
  border: 1px dashed rgba(0, 0, 0, 0.1);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  line-height: 1.6;
  transition: var(--transition);
}

.ad-placeholder:hover {
  background: rgba(0, 0, 0, 0.04);
}

.ad-placeholder--leaderboard {
  width: 728px;
  max-width: 100%;
  height: 90px;
}

.ad-placeholder--rectangle {
  width: 300px;
  height: 250px;
}

/* ── HEADER ── */
header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 32px;
  background: rgba(249, 249, 247, 0.85);
  /* Matches var(--bg) with opacity */
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.02);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: baseline;
  gap: 10px;
  cursor: pointer;
  transition: var(--transition);
}

.logo:hover {
  opacity: 0.85;
}

.logo-mark {
  font-family: 'Playfair Display', serif;
  font-size: 24px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.5px;
}

.logo-mark span {
  color: var(--accent);
}

.logo-tagline {
  font-size: 12px;
  color: var(--ink-muted);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: rgba(0, 0, 0, 0.05);
  padding: 4px 8px;
  border-radius: var(--radius-pill);
}

.footer-logo {
  grid-column: 1;
  padding: 0 16px;
}

.global-toolbar {
  position: sticky;
  bottom: 0px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  width: max-content;
  margin: auto auto 0;
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(0, 0, 0, 0.04);
  border-radius: var(--radius-pill);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
  z-index: 20;
  flex-shrink: 0;
}

.grade-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-muted);
}

.grade-pill {
  font-family: 'DM Mono', monospace;
  font-size: 14px;
  font-weight: 600;
  background: var(--surface);
  color: var(--ink);
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  min-width: 42px;
  text-align: center;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.mode-toggle {
  display: flex;
  background: rgba(0, 0, 0, 0.05);
  border-radius: var(--radius-pill);
  padding: 4px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.03);
  position: relative;
}

.mode-btn {
  font-size: 13px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: var(--radius-pill);
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--ink-muted);
  font-family: 'DM Sans', sans-serif;
  transition: var(--transition);
  position: relative;
  z-index: 1;
}

.mode-btn:hover {
  color: var(--ink);
}

.mode-btn.active {
  background: var(--ink);
  color: var(--surface);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-highlight {
  background: var(--ink);
  color: var(--surface);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: var(--transition);
  width: 100%;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.btn-highlight:hover {
  background: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(221, 74, 61, 0.25);
  color: #fff;
}

.btn-outline {
  background: var(--bg);
  color: var(--ink);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: var(--transition);
  width: 100%;
  text-align: center;
}

.btn-outline:hover {
  background: rgba(221, 74, 61, 0.04);
  border-color: rgba(221, 74, 61, 0.3);
  color: var(--accent);
  transform: translateY(-1px);
}

.clear-btn {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-muted);
  background: none;
  border: none;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.clear-btn:hover {
  background: rgba(221, 74, 61, 0.08);
  color: var(--accent);
  transform: translateY(-1px);
}

/* ── LAYOUT ── */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr 280px;
  flex: 1;
  min-height: 0;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* ── MAIN / EDITOR ── */
main {
  overflow-y: auto;
  padding: 48px 40px 24px;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.editor-wrap {
  flex: 1;
  width: 100%;
  max-width: 740px;
  margin: 0 auto;
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

.editor-layer {
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  margin: 0;
  padding: 0 10px;
  border: none;
  font-family: 'Playfair Display', serif;
  font-size: 21px;
  line-height: 1.8;
  white-space: pre-wrap;
  word-wrap: break-word;
  background: transparent;
  outline: none;
}

#editor {
  z-index: 2;
  color: var(--ink);
  caret-color: var(--accent);
  resize: none;
  overflow-y: hidden;
  border-left: 2px solid transparent;
  transition: border-color 0.3s ease;
}

#editor:focus {
  border-left-color: rgba(0, 0, 0, 0.1);
}

#editor::placeholder {
  color: var(--ink-faint);
  font-style: italic;
}

#backdrop {
  z-index: 1;
  color: transparent;
  pointer-events: none;
  overflow-y: hidden;
  border-left: 2px solid transparent;
  /* match #editor border for padding parity */
}

/* ── HIGHLIGHT CLASSES ── */
.hl-hard {
  background: var(--hl-hard);
  border-bottom: 2px solid var(--hl-hard-border);
  border-radius: 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.hl-vhard {
  background: var(--hl-vhard);
  border-bottom: 2px solid var(--hl-vhard-border);
  border-radius: 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.hl-passive {
  background: var(--hl-passive);
  border-bottom: 2px solid var(--hl-passive-border);
  border-radius: 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.hl-adverb {
  background: var(--hl-adverb);
  border-bottom: 2px solid var(--hl-adverb-border);
  border-radius: 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.hl-complex {
  background: var(--hl-complex);
  border-bottom: 2px solid var(--hl-complex-border);
  border-radius: 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.hl-weak {
  background: var(--hl-weak);
  border-bottom: 2px solid var(--hl-weak-border);
  border-radius: 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.hl-grammar {
  background: var(--hl-grammar);
  border-bottom: 2px solid var(--hl-grammar-border);
  border-radius: 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.hl-spelling {
  background: var(--hl-spelling);
  border-bottom: 2px dotted var(--hl-spelling-border);
  border-radius: 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

span[class^="hl-"] {
  position: relative;
  cursor: help;
  transition: background-color 0.2s ease;
}

span[class^="hl-"]:hover {
  filter: brightness(0.95);
}

/* ── SIDEBAR ── */
aside {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-left: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.02);
  z-index: 2;
  min-height: 0;
}

.sidebar-left {
  border-left: none;
  border-right: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 8px 0 32px rgba(0, 0, 0, 0.02);
}

.sidebar-section {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.sidebar-title {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
}

.sidebar-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(0, 0, 0, 0.06);
  margin-left: 12px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 12px;
  margin: 0 -12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-muted);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.stat-row:hover {
  background: var(--bg);
  transform: translateX(4px);
}

.stat-val {
  font-family: 'DM Mono', monospace;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.03);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

.stat-val.warn {
  color: var(--accent);
  background: rgba(221, 74, 61, 0.06);
}

.grade-display {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.grade-big {
  font-family: 'Playfair Display', serif;
  font-size: 52px;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
  transition: color 0.4s ease;
  flex-shrink: 0;
}

.grade-desc {
  font-size: 13px;
  color: var(--ink-muted);
  line-height: 1.5;
}

.grade-desc strong {
  color: var(--ink);
  font-weight: 600;
}

.ease-bar-wrap {
  height: 8px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-top: 8px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}

.ease-bar {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--accent);
  transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.4s;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin: 0 -12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-muted);
  line-height: 1.4;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  cursor: pointer;
}

.legend-item:hover {
  background: var(--bg);
  transform: translateX(4px);
  color: var(--ink);
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05), inset 0 -2px 0 rgba(0, 0, 0, 0.05);
}

/* ── FOOTER ── */
footer {
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 8px 16px;
  background: var(--bg);
  z-index: 5;
  flex-shrink: 0;
}

.footer-bottom {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  padding: 0 16px;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-faint);
  text-align: right;
  grid-column: 3;
}

/* ── RESPONSIVE ── */
@media (max-width: 1024px) {
  .layout {
    grid-template-columns: 1fr 260px;
  }

  .sidebar-left {
    display: none;
  }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr 240px;
  }
}

@media (max-width: 768px) {
  body {
    height: auto;
    overflow-y: auto;
  }

  .layout {
    display: flex;
    flex-direction: column;
  }

  main,
  aside {
    overflow-y: visible;
    min-height: auto;
  }

  aside {
    border-left: none;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.02);
  }

  header {
    padding: 12px 20px;
    flex-wrap: wrap;
    gap: 12px;
  }

  main {
    padding: 32px 20px 16px;
  }

  #editor {
    font-size: 18px;
  }

  .ad-placeholder--leaderboard {
    width: 100%;
  }

  footer {
    display: flex;
    flex-direction: column;
    padding: 16px;
  }

  .footer-bottom {
    align-items: center;
    text-align: center;
    padding: 12px 0 0;
  }
}