:root {
  --bg: #ececec;
  --fg: #1a1a1a;
  --muted: rgba(0, 0, 0, 0.4);
  --border: rgba(0, 0, 0, 0.1);
  --accent: #1a1a1a;
  --accent-fg: #ffffff;
  --textarea-bg: #ffffff;
  --textarea-fg: #1a1a1a;
  --letter-height: 200px;
  --letter-gap: calc(var(--letter-height) * 0.04);
  --space-width: calc(var(--letter-height) * 0.35);
  --line-gap: calc(var(--letter-height) * 0.08);
}

body.dark {
  --fg: #ffffff;
  --muted: rgba(255, 255, 255, 0.6);
  --border: rgba(255, 255, 255, 0.3);
  --accent: #ffffff;
  --accent-fg: #000000;
  --textarea-bg: #1a1a1a;
  --textarea-fg: #ffffff;
}

html,
body {
  transition: background-color 180ms ease, color 180ms ease;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica,
    Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
}

.topbar {
  flex: 0 0 auto;
  padding: 20px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.byline {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-decoration: none;
}

.byline:hover {
  color: var(--fg);
  text-decoration: underline;
}

.wordmark {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.wordmark strong {
  font-weight: 800;
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: safe center;
  align-items: safe center;
  padding: 32px 24px;
  overflow: auto;
}

.line {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  width: 100%;
  margin-bottom: var(--line-gap);
}

.line:last-child {
  margin-bottom: 0;
}

.word {
  display: inline-flex;
  align-items: flex-end;
  justify-content: center;
  flex-wrap: wrap;
  max-width: 100%;
  transform-origin: center bottom;
}

.space {
  display: inline-block;
  height: var(--letter-height);
  flex: 0 0 auto;
}

.letter {
  height: var(--letter-height);
  width: auto;
  margin-right: var(--letter-gap);
  user-select: none;
  -webkit-user-drag: none;
  display: block;
}

.word .letter:last-child {
  margin-right: 0;
}

.controls {
  flex: 0 0 auto;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 16px 24px 20px;
}

.controls-inner {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--textarea-bg);
  color: var(--textarea-fg);
  font: inherit;
  font-size: 16px;
  resize: vertical;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.row {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.slider-field {
  flex: 1 1 240px;
  min-width: 0;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.reset-link {
  margin-left: 8px;
  padding: 0;
  background: none;
  border: none;
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg);
  text-decoration: underline;
  cursor: pointer;
}

.reset-link[hidden] {
  display: none;
}

.bg-picker {
  position: relative;
  flex: 0 0 auto;
}

.icon-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--textarea-bg);
  color: var(--textarea-fg);
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.icon-btn:hover {
  border-color: var(--accent);
}

.theme-icon {
  display: block;
  width: 22px;
  height: 22px;
  background-color: currentColor;
  -webkit-mask: url("images/theme-tool.svg") center / contain no-repeat;
  mask: url("images/theme-tool.svg") center / contain no-repeat;
}

.bg-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  display: flex;
  gap: 8px;
  padding: 10px;
  background: var(--textarea-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  z-index: 10;
}

.bg-menu[hidden] {
  display: none;
}

.swatch {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  background: var(--swatch);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 120ms ease;
}

.swatch:hover {
  transform: scale(1.08);
}

.swatch.active {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

.download-btn {
  padding: 12px 18px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-fg);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.download-btn:hover {
  opacity: 0.9;
}

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