:root {
  color-scheme: light;
  --ink: #1E1E1E;
  --surface: #F8F8F8;
  --muted: #868686;
  --accent: #008FFF;
  --toolbar-height: 72px;
  --fade-height: 1.4rem;
  --text-size: 1.5rem;
  --line-height: calc(var(--text-size) * 1.5);
  --visible-rows: 5;
  --fade-overlay-height: calc(var(--line-height) * 2);
  --status-text: #ffffff;
  --fade-transparent-surface: rgba(248, 248, 248, 0);
  --toolbar-background: rgba(248, 248, 248, 0.95);
  --toolbar-border: #E4E4E4;
  --toolbar-icon-hover: #E4E4E4;
  --theme-preview-auto: url("settings/auto-light.svg");
  --theme-preview-light: url("settings/light-light.svg");
  --theme-preview-dark: url("settings/dark-light.svg");
  --toolbar-preview-bottom: url("settings/bottom-light.svg");
  --toolbar-preview-top: url("settings/top-light.svg");
  --font-ui-family: system-ui, sans-serif;
  --font-ui-weight: 400;
  --font-writing-sans: var(--font-ui-family);
  --font-writing-serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, serif;
  --font-writing-mono: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --font-writing-family: var(--font-writing-mono);
  --font-writing-weight: 400;
  --writing-sample-color: #707070;
  font-family: var(--font-ui-family);
  font-weight: var(--font-ui-weight);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #F8F8F8;
  --surface: #1E1E1E;
  --status-text: #d9d9d9;
  --fade-transparent-surface: rgba(30, 30, 30, 0);
  --toolbar-background: rgba(30, 30, 30, 0.9);
  --toolbar-border: #505050;
  --toolbar-icon-hover: #505050;
  --theme-preview-auto: url("settings/auto-dark.svg");
  --theme-preview-light: url("settings/light-dark.svg");
  --theme-preview-dark: url("settings/dark-dark.svg");
  --toolbar-preview-bottom: url("settings/bottom-dark.svg");
  --toolbar-preview-top: url("settings/top-dark.svg");
  --writing-sample-color: #858585;
}

:root[data-theme="light"] {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--surface);
  color: var(--ink);
  display: flex;
  flex-direction: column;
}

[data-writing-font="sans"] {
  --font-writing-family: var(--font-writing-sans);
  --font-writing-weight: 400;
}

[data-writing-font="serif"] {
  --font-writing-family: var(--font-writing-serif);
  --font-writing-weight: 400;
}

[data-writing-font="mono"] {
  --font-writing-family: var(--font-writing-mono);
  --font-writing-weight: 400;
}

.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(1.5rem, 5vw, 4rem) clamp(1rem, 5vw, 5rem);
  padding-bottom: calc(var(--toolbar-height) + 2rem);
}

.typewriter {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  position: relative;
  margin-bottom: 100px;
}

.settings {
  max-width: 920px;
  margin: 0 auto;
  padding: clamp(1.5rem, 5vw, 4rem) clamp(1rem, 5vw, 3rem);
}

.settings__layout {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 2.5rem;
  align-items: flex-start;
}

.settings__sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.settings__content {
  max-width: 820px;
}

.settings h1 {
  margin: 0;
  font-size: 2rem;
}

.settings__header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2.25rem;
}

.settings__header--wtf {
  margin-bottom: 1.5rem;
}

.settings section + section {
  margin-top: 2.5rem;
}

.settings__section-title {
  margin-bottom: 0.5rem;
  font-size: 1.75rem;
}

.wtf-copy {
  display: flex;
  flex-direction: column;
  font-size: 1.1rem;
  line-height: 1.7;
  color: var(--ink);
}

.wtf-copy h2 {
  margin-bottom: 0;
}

.wtf-copy h3 {
  margin-top: 3.25rem;
  margin-bottom: 0;
}

.wtf-copy p {
  margin-bottom: 0;
}

.wtf-copy ul {
  margin: 0;
  padding-left: 1.25rem;
}

fieldset {
  border: 0;
  padding: 0;
  margin: 0;
  min-inline-size: 0;
}

.font-options {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.font-option {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1rem;
  padding: 0.5rem 1.25rem;
  border-radius: 16px;
  align-items: flex-start;
}

.font-option input[type="radio"] {
  margin-top: 0.4rem;
}

.font-option__label {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.font-option__name {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ink);
}

.theme-options,
.toolbar-options {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.theme-option,
.toolbar-option {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.theme-option input[type="radio"],
.toolbar-option input[type="radio"] {
  order: 2;
  margin-top: 0.25rem;
}

.theme-option__card,
.toolbar-option__card {
  order: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  text-align: center;
  cursor: pointer;
}

.theme-option__preview,
.toolbar-option__preview {
  display: block;
  width: 180px;
  height: 110px;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, border-radius 0.2s ease;
}

.theme-option__preview--auto {
  background-image: var(--theme-preview-auto);
}

.theme-option__preview--light {
  background-image: var(--theme-preview-light);
}

.theme-option__preview--dark {
  background-image: var(--theme-preview-dark);
}

.toolbar-option__preview--bottom {
  background-image: var(--toolbar-preview-bottom);
}

.toolbar-option__preview--top {
  background-image: var(--toolbar-preview-top);
}

.theme-option__name,
.toolbar-option__name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
}

.theme-option input[type="radio"]:focus-visible + .theme-option__card,
.toolbar-option input[type="radio"]:focus-visible + .toolbar-option__card {
  outline: 2px solid var(--accent);
  outline-offset: 6px;
}

.theme-option input[type="radio"]:checked + .theme-option__card .theme-option__preview,
.toolbar-option input[type="radio"]:checked + .toolbar-option__card .toolbar-option__preview {
  border-radius: 12px;
  box-shadow: 0 0 0 2px rgba(0, 143, 255, 0.25);
}

@media (max-width: 720px) {
  .settings__layout {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .settings__sidebar {
    flex-direction: row;
    gap: 1rem;
  }
}

.writing-sample {
  display: block;
  font-size: var(--text-size);
  line-height: var(--line-height);
  font-family: var(--font-writing-family, ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, "DejaVu Sans Mono", monospace);
  font-weight: var(--font-writing-weight, 400);
  color: var(--ink);
  opacity: 0.62;
}

[data-theme="dark"] .writing-sample {
  opacity: 0.47;
}

.custom-caret {
  position: absolute;
  width: 3px;
  background: var(--accent);
  height: var(--line-height);
  top: 0;
  left: 0;
  pointer-events: none;
  opacity: 0;
  border-radius: 999px;
  animation: caretBlink 1s steps(1) infinite;
}

.custom-caret.is-hidden {
  opacity: 0;
  animation-play-state: paused;
}

.custom-caret.is-visible {
  opacity: 1;
  animation-play-state: running;
}

@keyframes caretBlink {
  0%, 50% {
    opacity: 1;
  }
  50.01%, 100% {
    opacity: 0;
  }
}

.typewriter::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--fade-overlay-height);
  pointer-events: none;
  background: linear-gradient(
    180deg,
    var(--surface) 0,
    var(--surface) calc(var(--fade-overlay-height) / 2),
    var(--fade-transparent-surface) var(--fade-overlay-height)
  );
}

textarea {
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  padding-top: var(--fade-height);
  padding-bottom: 0.5rem;
  min-height: calc(var(--line-height) * var(--visible-rows) + var(--fade-height) + 0.5rem);
  max-height: calc(var(--line-height) * var(--visible-rows) + var(--fade-height) + 0.5rem);
  font-size: var(--text-size);
  line-height: var(--line-height);
  font-family: var(--font-writing-family, ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, "DejaVu Sans Mono", monospace);
  font-weight: var(--font-writing-weight, 400);
  background: transparent;
  color: var(--ink);
  caret-color: transparent;
  overflow-y: auto;
  scrollbar-width: none;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
}

textarea::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.toolbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 50px;
  padding: 1rem clamp(1rem, 4vw, 3rem) 3.5rem;
  min-height: calc(var(--toolbar-height) + 24px);
  background: var(--toolbar-background);
  border-top: 1px solid var(--toolbar-border);
  backdrop-filter: blur(8px);
  transition: opacity 0.35s ease;
}

[data-toolbar-position="top"] .toolbar {
  top: 0;
  bottom: auto;
  padding: 1rem clamp(1rem, 4vw, 3rem) 3.5rem;
  border-top: none;
  border-bottom: 1px solid var(--toolbar-border);
}

.toolbar.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.toolbar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.toolbar-item--copy {
  position: relative;
}

.toss-animation {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toss-animation svg {
  width: 32px;
  height: 32px;
  display: block;
  color: var(--ink);
}

.toss-animation svg path {
  opacity: 0;
}

@keyframes toss-frame-one {
  0% { opacity: 1; }
  10% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes toss-frame-two {
  0% { opacity: 0; }
  10% { opacity: 1; }
  20% { opacity: 0; }
  90% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes toss-frame-three {
  0% { opacity: 0; }
  20% { opacity: 1; }
  30% { opacity: 0; }
  100% { opacity: 0; }
}

@keyframes toss-frame-four {
  0% { opacity: 0; }
  30% { opacity: 1; }
  40% { opacity: 0; }
  100% { opacity: 0; }
}

@keyframes toss-frame-five {
  0% { opacity: 0; }
  40% { opacity: 1; }
  50% { opacity: 0; }
  100% { opacity: 0; }
}

@keyframes toss-frame-six {
  0% { opacity: 0; }
  50% { opacity: 1; }
  60% { opacity: 0; }
  100% { opacity: 0; }
}

@keyframes toss-frame-seven {
  0% { opacity: 0; }
  60% { opacity: 1; }
  70% { opacity: 0; }
  100% { opacity: 0; }
}

@keyframes toss-frame-eight {
  0% { opacity: 0; }
  70% { opacity: 1; }
  80% { opacity: 0; }
  100% { opacity: 0; }
}

@keyframes toss-frame-nine {
  0% { opacity: 0; }
  80% { opacity: 1; }
  90% { opacity: 0; }
  100% { opacity: 0; }
}

.toss-animation svg #one { animation: 1s steps(1, end) forwards toss-frame-one; }
.toss-animation svg #two { animation: 1s steps(1, end) forwards toss-frame-two; }
.toss-animation svg #three { animation: 1s steps(1, end) forwards toss-frame-three; }
.toss-animation svg #four { animation: 1s steps(1, end) forwards toss-frame-four; }
.toss-animation svg #five { animation: 1s steps(1, end) forwards toss-frame-five; }
.toss-animation svg #six { animation: 1s steps(1, end) forwards toss-frame-six; }
.toss-animation svg #seven { animation: 1s steps(1, end) forwards toss-frame-seven; }
.toss-animation svg #eight { animation: 1s steps(1, end) forwards toss-frame-eight; }
.toss-animation svg #nine { animation: 1s steps(1, end) forwards toss-frame-nine; }

.toss-animation.is-visible {
  opacity: 1;
}

.toolbar-item--wtf {
  position: relative;
}

.onboarding-hint {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  padding: 1rem;
  border-radius: 6px;
  background: #006cd1;
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.onboarding-hint::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-width: 8px 7px 0 7px;
  border-style: solid;
  border-color: #006cd1 transparent transparent transparent;
}

.onboarding-hint.is-visible {
  opacity: 1;
}

.status {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translate(-50%, -20px);
  padding: 0.35rem 0.9rem;
  background: var(--ink);
  color: var(--status-text);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 999px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.status.is-visible {
  opacity: 1;
}

.toolbar-action {
  border: none;
  border-radius: 999px;
  padding: 0;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
  background: none;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  text-decoration: none;
}

.toolbar-action:disabled {
  opacity: 0.62;
  cursor: default;
  pointer-events: none;
  background: none;
  color: var(--ink);
}

[data-theme="dark"] .toolbar-action:disabled {
  opacity: 0.47;
}

.toolbar-action:not(:disabled):active {
  transform: translateY(1px);
}

.toolbar-action__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 4px;
  transition: background 0.2s ease, opacity 0.3s ease;
  position: relative;
}

.toolbar-action__icon svg {
  width: 32px;
  height: 33px;
  display: block;
  fill: currentColor;
}

.toolbar-action__icon[hidden] {
  display: none;
}

.toolbar-action__icon.is-animating {
  opacity: 1;
}

.toolbar-action__icon.is-animating > svg {
  opacity: 0;
}

.toolbar-action:not(:disabled):hover .toolbar-action__icon,
.toolbar-action:not(:disabled):focus-visible .toolbar-action__icon,
.toolbar-action:not(:disabled):active .toolbar-action__icon {
  background: var(--toolbar-icon-hover);
}

.toolbar-label,
.toolbar-label[data-fullscreen-label] {
  position: absolute;
  top: calc(100% + 0.6rem);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  color: var(--ink);
  white-space: nowrap;
  pointer-events: none;
}

@media (max-width: 768px) {
  .toolbar {
    gap: clamp(22px, 6vw, 50px);
  }
}

@media (max-width: 560px) {
  .toolbar {
    flex-wrap: wrap;
    height: auto;
    padding-bottom: 1.5rem;
  }

  .workspace {
    padding-bottom: calc(var(--toolbar-height) + 3.5rem);
  }

  [data-toolbar-position="top"] .workspace {
    padding-top: calc(clamp(1.5rem, 5vw, 4rem) + var(--toolbar-height) + 3.5rem);
    padding-bottom: clamp(1.5rem, 5vw, 4rem);
  }
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ink: #F8F8F8;
    --surface: #1E1E1E;
    --status-text: #d9d9d9;
    --fade-transparent-surface: rgba(30, 30, 30, 0);
    --toolbar-background: rgba(30, 30, 30, 0.9);
    --toolbar-border: #505050;
    --toolbar-icon-hover: #505050;
    --theme-preview-auto: url("settings/auto-dark.svg");
    --theme-preview-light: url("settings/light-dark.svg");
    --theme-preview-dark: url("settings/dark-dark.svg");
    --toolbar-preview-bottom: url("settings/bottom-dark.svg");
    --toolbar-preview-top: url("settings/top-dark.svg");
    --writing-sample-color: #858585;
  }

  :root:not([data-theme="light"]) body .writing-sample {
    opacity: 0.47;
  }

  :root:not([data-theme="light"]) body .toolbar-action:disabled {
    opacity: 0.47;
  }
}
[data-toolbar-position="top"] .toolbar-item--wtf .onboarding-hint {
  top: calc(100% + 0.5rem);
  bottom: auto;
  transform: translate(-50%, 0);
}

[data-toolbar-position="top"] .toolbar-item--wtf .onboarding-hint::after {
  top: auto;
  bottom: 100%;
  border-width: 0 7px 8px 7px;
  border-color: transparent transparent var(--accent) transparent;
}
