/* ==========================================================================
   Case & Count — styles
   ========================================================================== */

:root {
  color-scheme: light;

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  --bg: #f4f5fa;
  --glow: rgba(81, 69, 229, 0.09);
  --surface: #ffffff;
  --surface-2: #f5f6fb;
  --field: #fcfcff;
  --text: #171a26;
  --text-muted: #565f73;
  --text-faint: #6b7489;
  --border: #e3e6ef;
  --border-strong: #ccd2e1;
  --accent: #5145e5;
  --accent-hover: #4235d2;
  --accent-soft: #eeecfe;
  --accent-contrast: #ffffff;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --focus: #6d5ef0;
  --shadow: 0 1px 2px rgba(20, 23, 40, 0.04),
    0 16px 40px -18px rgba(20, 23, 40, 0.18);

  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0b0d14;
  --glow: rgba(139, 132, 255, 0.1);
  --surface: #12161f;
  --surface-2: #181d29;
  --field: #0f131b;
  --text: #eef1f8;
  --text-muted: #acb5c9;
  --text-faint: #939db3;
  --border: #242b3a;
  --border-strong: #384155;
  --accent: #918aff;
  --accent-hover: #a79fff;
  --accent-soft: #201f3d;
  --accent-contrast: #0b0d14;
  --danger: #ff9b91;
  --danger-soft: #2b1817;
  --focus: #a79fff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4),
    0 18px 44px -20px rgba(0, 0, 0, 0.7);
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 520px at 12% -12%, var(--glow), transparent 70%),
    radial-gradient(760px 480px at 102% -6%, var(--glow), transparent 65%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.shell {
  width: min(100% - 40px, 940px);
  margin-inline: auto;
  padding: 30px 0 40px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -100px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 650;
  text-decoration: none;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 12px;
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand__mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 15px;
  background: linear-gradient(145deg, var(--accent), #7c5cf5);
  color: #fff;
  font-size: 1.22rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  box-shadow: 0 8px 20px -10px rgba(81, 69, 229, 0.65);
  user-select: none;
}

.brand__text {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 760;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.brand p {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.icon-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease,
    background-color 0.15s ease;
}

.icon-btn:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
}

.icon-btn:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

[data-theme="dark"] .icon--moon {
  display: none;
}

.icon--sun {
  display: none;
}

[data-theme="dark"] .icon--sun {
  display: block;
}

.icon {
  width: 19px;
  height: 19px;
  flex: none;
}

/* --------------------------------------------------------------------------
   Editor
   -------------------------------------------------------------------------- */

.editor {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

#text-input {
  display: block;
  width: 100%;
  min-height: 330px;
  margin: 0;
  padding: 24px 24px 20px;
  border: 0;
  border-radius: 0;
  outline: none;
  background: var(--field);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1.06rem;
  line-height: 1.72;
  resize: vertical;
  caret-color: var(--accent);
  transition: box-shadow 0.15s ease, background-color 0.15s ease;
}

#text-input::placeholder {
  color: var(--text-faint);
  opacity: 1;
}

#text-input:hover {
  background: var(--surface);
}

#text-input:focus {
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--focus);
}

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.toolbar__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.toolbar__label {
  margin-right: 2px;
  color: var(--text-faint);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.toolbar__row--actions {
  justify-content: space-between;
  gap: 10px 16px;
  padding-top: 11px;
  border-top: 1px dashed var(--border);
}

.toolbar__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

/* Buttons ----------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 15px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease,
    color 0.15s ease, transform 0.08s ease;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

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

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn--case {
  min-width: 0;
  padding-inline: 13px;
}

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

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

.btn--ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-muted);
}

.btn--ghost:hover:not(:disabled) {
  border-color: var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.btn--ghost[data-action="clear"]:hover:not(:disabled) {
  border-color: transparent;
  background: var(--danger-soft);
  color: var(--danger);
}

.btn.is-copied {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
}

/* Smart title switch ------------------------------------------------------ */

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.switch__input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.switch__track {
  position: relative;
  flex: none;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background-color 0.18s ease;
}

.switch__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s ease;
}

.switch__input:checked + .switch__track {
  background: var(--accent);
}

.switch__input:checked + .switch__track::after {
  transform: translateX(16px);
}

.switch__input:focus-visible + .switch__track {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.switch__text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 650;
  line-height: 1.25;
}

.switch__text small {
  color: var(--text-faint);
  font-size: 0.73rem;
  font-weight: 500;
}

/* Shortcut hints ---------------------------------------------------------- */

.shortcuts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 0;
  padding: 0 18px 15px;
  background: var(--surface);
  color: var(--text-faint);
  font-size: 0.73rem;
}

.shortcuts span {
  white-space: nowrap;
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  line-height: 1.45;
}

/* --------------------------------------------------------------------------
   Stats
   -------------------------------------------------------------------------- */

.stats {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 18px 0;
  margin-top: 16px;
  padding: 19px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.stat--hero {
  flex: 1 1 160px;
  padding-right: 20px;
}

.stat--hero + .stat--hero {
  padding-left: 22px;
  border-left: 1px solid var(--border);
}

.stat__label {
  color: var(--text-faint);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.075em;
  line-height: 1.3;
  text-transform: uppercase;
}

.stat__value {
  color: var(--text);
  font-weight: 720;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat--hero .stat__value {
  font-size: clamp(2.1rem, 5.4vw, 2.9rem);
  line-height: 1.08;
}

.stats__secondary {
  display: grid;
  flex: 2 1 430px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px 18px;
  align-content: center;
  padding-left: 22px;
  border-left: 1px solid var(--border);
}

.stats__secondary .stat__value {
  font-size: 1.18rem;
  line-height: 1.25;
}

#count-reading {
  font-size: 1.05rem;
}

/* --------------------------------------------------------------------------
   Footer, toast, noscript
   -------------------------------------------------------------------------- */

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 24px;
  margin-top: 22px;
  padding-inline: 4px;
  color: var(--text-faint);
  font-size: 0.78rem;
}

.site-footer p {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.site-footer .icon {
  width: 14px;
  height: 14px;
}

.toast {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--surface);
  box-shadow: 0 12px 32px -10px rgba(0, 0, 0, 0.4);
  font-size: 0.85rem;
  font-weight: 650;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 14px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.noscript {
  position: fixed;
  inset: auto 16px 16px;
  z-index: 60;
  margin: 0;
  padding: 14px 18px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  text-align: center;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 720px) {
  .stats {
    gap: 16px 0;
    padding: 17px 18px;
  }

  .stat--hero {
    flex: 1 1 40%;
    padding-right: 14px;
  }

  .stat--hero + .stat--hero {
    padding-left: 16px;
  }

  .stats__secondary {
    flex-basis: 100%;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding-top: 15px;
    padding-left: 0;
    border-top: 1px solid var(--border);
    border-left: 0;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100% - 24px, 940px);
    padding-top: 20px;
  }

  .brand__mark {
    width: 42px;
    height: 42px;
    border-radius: 13px;
    font-size: 1.08rem;
  }

  .brand h1 {
    font-size: 1.28rem;
  }

  .brand p {
    font-size: 0.83rem;
  }

  #text-input {
    min-height: 250px;
    padding: 18px 16px 16px;
    font-size: 1rem;
    line-height: 1.68;
  }

  .toolbar {
    gap: 9px;
    padding: 12px;
  }

  .toolbar__label {
    display: none;
  }

  .toolbar__row--cases {
    gap: 6px;
  }

  .btn {
    min-height: 44px;
    padding-inline: 13px;
    font-size: 0.83rem;
  }

  .btn--case {
    flex: 1 1 auto;
    padding-inline: 10px;
  }

  .toolbar__row--actions {
    gap: 8px;
  }

  .switch {
    min-height: 40px;
  }

  .toolbar__actions {
    flex: 1 1 100%;
    justify-content: flex-end;
  }

  .shortcuts {
    display: none;
  }

  .stats {
    padding: 16px;
  }

  .stats__secondary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 13px 16px;
  }

  .stats__secondary .stat__value {
    font-size: 1.12rem;
  }

  .site-footer {
    justify-content: center;
    text-align: center;
  }
}

@media (max-width: 360px) {
  .brand p {
    display: none;
  }

  .btn--case {
    flex-basis: calc(50% - 3px);
  }

  .toolbar__actions .btn--ghost {
    padding-inline: 10px;
  }
}

/* --------------------------------------------------------------------------
   Motion & contrast preferences
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

@media (forced-colors: active) {
  .btn,
  .icon-btn,
  .stats,
  .editor {
    border: 1px solid ButtonBorder;
  }

  .btn--primary {
    background: ButtonFace;
    color: ButtonText;
  }
}
