:root {
  color-scheme: light dark;
  --bg: #f8fafc;
  --fg: #0f172a;
  --muted: #475569;
  --border: rgba(15, 23, 42, 0.12);
  --accent: #0ea5e9;
  --card: rgba(255, 255, 255, 0.92);
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.15);
  font-size: 16px;
}

html[data-theme="dark"] {
  --bg: #0f172a;
  --fg: #e2e8f0;
  --muted: #94a3b8;
  --border: rgba(226, 232, 240, 0.12);
  --accent: #38bdf8;
  --card: rgba(15, 23, 42, 0.92);
  --shadow: 0 20px 48px rgba(8, 47, 73, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  display: flex;
  flex-direction: column;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem clamp(1.5rem, 5vw, 3.5rem);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  position: sticky;
  top: 0;
  z-index: 10;
}

.top-bar__brand {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.top-bar__brand .brand__name {
  color: inherit;
  text-decoration: none;
}

.top-bar__brand .brand__name:hover,
.top-bar__brand .brand__name:focus-visible {
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 60%, transparent);
}

.brand__tagline {
  font-size: 0.875rem;
  color: var(--muted);
  font-weight: 500;
}

.top-bar__actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.top-bar__home-link {
  font-size: 0.95rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  border-bottom: 1px solid transparent;
  transition: border-color 120ms ease;
}

.top-bar__home-link:hover,
.top-bar__home-link:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
}

.privacy-note {
  font-size: 0.875rem;
  color: var(--muted);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  border: 1px solid transparent;
  background: color-mix(in srgb, var(--accent) 12%, var(--bg));
  color: var(--fg);
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

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

.icon-button:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
}

.lang-button {
  border: none;
  background: none;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.lang-button[data-active="true"] {
  background: color-mix(in srgb, var(--accent) 14%, var(--bg));
  color: var(--fg);
}

.lang-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: clamp(1.5rem, 5vw, 3rem);
  gap: clamp(1rem, 3vw, 1.5rem);
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  text-align: center;
  font-weight: 700;
}

.editor-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  min-height: clamp(400px, 70vh, 720px);
}

.editor {
  flex: 1;
  width: 100%;
  min-height: 100%;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 98%, transparent);
  padding: clamp(1.25rem, 3vw, 1.75rem);
  font-family: "JetBrains Mono", "SFMono-Regular", "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: clamp(1rem, 1.2vw, 1.15rem);
  line-height: 1.6;
  color: var(--fg);
  resize: none;
  outline: none;
  box-shadow: 0 24px 40px -32px rgba(15, 23, 42, 0.35);
  transition: border-color 120ms ease;
}

.editor:focus {
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
}

.preview {
  position: absolute;
  inset: clamp(1rem, 2.5vw, 1.5rem);
  padding: clamp(1.25rem, 2vw, 1.75rem);
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: var(--shadow);
  overflow: auto;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  color-scheme: inherit;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.preview[hidden] {
  display: none;
}

.preview h1,
.preview h2,
.preview h3,
.preview h4,
.preview h5,
.preview h6 {
  margin: 0;
  font-weight: 700;
}

.preview p,
.preview blockquote,
.preview ul,
.preview ol {
  margin: 0;
}

.preview ul,
.preview ol {
  padding-left: 1.25rem;
}

.preview blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  color: var(--muted);
}

.preview .muted {
  color: var(--muted);
  font-style: italic;
}

.preview pre {
  margin: 0;
  background: color-mix(in srgb, var(--bg) 80%, #000 5%);
  border-radius: 16px;
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.95rem;
}

.preview code {
  font-family: "JetBrains Mono", "SFMono-Regular", "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.preview .inline-code {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-radius: 6px;
  padding: 0.1rem 0.35rem;
}

.preview a {
  color: var(--accent);
}

.preview .token.keyword {
  color: #f97316;
}

.preview .token.string,
.preview .token.attr-value {
  color: #22c55e;
}

.preview .token.number {
  color: #38bdf8;
}

.preview .token.comment {
  color: #94a3b8;
  font-style: italic;
}

.preview .token.tag,
.preview .token.attr-name {
  color: #e879f9;
}

.preview .token.punctuation {
  color: #fbbf24;
}

.word-counter {
  position: absolute;
  inset: auto clamp(1.25rem, 2vw, 1.75rem) clamp(1.25rem, 2vw, 1.75rem) auto;
  display: inline-flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 0.85rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  transition: opacity 120ms ease;
  pointer-events: none;
}

.editor:focus + .preview + .word-counter,
.editor:focus ~ .word-counter {
  opacity: 1;
}

.word-counter:hover {
  opacity: 1;
}

.hint {
  position: absolute;
  bottom: clamp(1.25rem, 3vw, 1.75rem);
  left: clamp(1.25rem, 3vw, 1.75rem);
  padding: 0.65rem 1rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 95%, transparent);
  color: var(--muted);
  font-size: 0.875rem;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  box-shadow: 0 16px 30px -24px rgba(15, 23, 42, 0.45);
}

.hint[hidden] {
  display: none;
}

.hint__dismiss {
  border: none;
  background: none;
  color: inherit;
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem;
}

.hint__dismiss:focus-visible {
  outline: 2px solid var(--accent);
  border-radius: 999px;
}

.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
}

.footer-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem clamp(1.5rem, 5vw, 3.5rem);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.static-main {
  flex: 1;
  display: flex;
  padding: clamp(1.75rem, 5vw, 3.5rem);
}

.static-article {
  margin: auto;
  width: min(860px, 100%);
  background: color-mix(in srgb, var(--card) 96%, transparent);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: clamp(1.75rem, 4vw, 2.75rem);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  color: var(--fg);
}

.static-article__header {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.static-article__meta {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.static-article h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 2.5rem);
}

.static-article h2 {
  margin: 0;
  font-size: clamp(1.25rem, 3vw, 1.5rem);
}

.static-article p {
  margin: 0;
  line-height: 1.7;
}

.static-article ul {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.5rem;
}

.static-article li {
  margin: 0;
  line-height: 1.6;
}

.static-article a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 120ms ease;
}

.static-article a:hover,
.static-article a:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
}

.footer-credit {
  margin: 0;
}

.footer-credit a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 150ms ease;
}

.footer-credit a:hover,
.footer-credit a:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
}

.footer-links {
  display: inline-flex;
  gap: 1.25rem;
}

.footer-links a {
  color: inherit;
  text-decoration: none;
  position: relative;
}

.footer-links a::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -0.15rem;
  width: 100%;
  height: 2px;
  background: color-mix(in srgb, var(--accent) 60%, transparent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 150ms ease;
}

.footer-links a:hover::after,
.footer-links a:focus-visible::after {
  transform: scaleX(1);
}

.toast {
  position: fixed;
  inset: auto 50% 2rem 50%;
  transform: translateX(-50%) translateY(1rem);
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  color: var(--fg);
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 20;
}

.toast[data-visible="true"] {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 720px) {
  .top-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .top-bar__actions {
    width: 100%;
    justify-content: space-between;
  }

  .privacy-note {
    order: 3;
    width: 100%;
  }

  .editor-wrapper {
    min-height: clamp(320px, 70vh, 640px);
  }

  .word-counter {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
  }

  .hint {
    position: fixed;
    left: 1rem;
    bottom: 1rem;
    max-width: min(280px, 80vw);
  }

  .preview {
    inset: 1rem;
  }
}

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