:root {
  --ink: #29251f;
  --muted: #71685c;
  --paper: #fffaf0;
  --sand: #e8dcc8;
  --line: rgba(41, 37, 31, 0.14);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  display: grid;
  grid-template-columns: minmax(17rem, 21rem) minmax(0, 1fr);
  color: var(--ink);
  background: #f7efe2;
  font-family: Arial, Helvetica, sans-serif;
}

/* ── Sidebar ──────────────────────────────────────────────── */

.controls {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: grid;
  align-content: start;
  gap: 1.1rem;
  padding: 1.25rem;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.92);
}

.controls-head {
  display: grid;
}

.kicker {
  margin: 0;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0.35rem 0 0;
  font-size: 2.35rem;
  line-height: 0.9;
  letter-spacing: -0.02em;
}

/* ── Slot buttons ─────────────────────────────────────────── */

.slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.slot {
  display: grid;
  gap: 0.15rem;
  min-height: 44px;
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.slot.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

.slot__label {
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.65;
}

.slot.is-active .slot__label {
  opacity: 0.75;
}

.slot__font {
  font-size: 0.84rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Sliders ──────────────────────────────────────────────── */

label {
  display: grid;
  gap: 0.45rem;
}

label span {
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

label output {
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--sand);
  padding: 0.1em 0.45em;
  border-radius: 4px;
  letter-spacing: 0;
  text-transform: none;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
  padding: 0;
  margin: 0;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: var(--sand);
  border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ink);
  margin-top: -9.5px;
  transition: transform 0.1s;
}

input[type="range"]:focus-visible::-webkit-slider-thumb {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

input[type="range"]::-moz-range-track {
  height: 3px;
  background: var(--sand);
  border-radius: 2px;
}

input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: var(--ink);
}

small {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.toggle {
  grid-template-columns: auto 1fr;
  gap: 0.7rem;
  align-items: center;
}

.toggle input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--ink);
  cursor: pointer;
}

.toggle span {
  font-size: 0.92rem;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.35;
  text-transform: none;
}

/* ── Main layout ──────────────────────────────────────────── */

main {
  min-width: 0;
  display: grid;
  gap: 1rem;
  padding: clamp(1rem, 3vw, 2rem);
  align-content: start;
}

/* ── Font picker ──────────────────────────────────────────── */

.picker {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 250, 240, 0.72);
  padding: 1.25rem;
}

.font-section + .font-section {
  margin-top: 2rem;
}

.font-section-head {
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 1rem;
}

.font-section-head > div {
  min-width: 0;
}

h2 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.4rem, 2.4vw, 2.4rem);
  line-height: 0.95;
  letter-spacing: -0.02em;
}

.font-section-head > div > p {
  max-width: 48rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.filter-btn {
  flex-shrink: 0;
  align-self: start;
  padding: 0.5rem 1rem;
  border: 1.5px solid var(--line);
  border-radius: 100px;
  background: transparent;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.filter-btn[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

.font-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(12rem, 100%), 1fr));
  gap: 0.7rem;
}

.font-card {
  position: relative;
  display: grid;
  gap: 0.55rem;
  min-height: 9rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.78);
  text-align: left;
  cursor: pointer;
  user-select: none;
}

.font-card:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.font-card.is-selected {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--ink);
}

.star-btn {
  position: absolute;
  top: 0;
  right: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--sand);
  border-radius: 0 9px 0 0;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.star-btn:active,
.star-btn.is-starred {
  color: var(--ink);
}

.star-btn::before {
  content: '☆';
}

.star-btn.is-starred::before {
  content: '★';
}

.font-card__sample {
  font-size: clamp(1.6rem, 2.8vw, 2.2rem);
  line-height: 0.95;
  text-transform: uppercase;
  overflow-wrap: anywhere;
  padding-right: 1.5rem;
}

.font-card__name {
  font-weight: 800;
  font-size: 0.84rem;
}

.font-card__note {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.3;
}

/* ── Output card ──────────────────────────────────────────── */

.output-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(135deg, #fffaf0, var(--sand));
}

.output-zone {
  padding: clamp(1.25rem, 3vw, 2.5rem);
}

.output-zone--arch {
  background:
    repeating-linear-gradient(0deg, rgba(41, 37, 31, 0.035) 0 1px, transparent 1px 13px);
  border-bottom: 1px solid var(--line);
}

.output-zone-label {
  margin: 0 0 0.75rem;
}

.arch-output,
.hand-output {
  max-width: 60rem;
  color: var(--ink);
}

.line {
  display: block;
  margin: 0 0 0.5rem;
  font-size: clamp(3rem, 9vw, 8.5rem);
  line-height: 0.95;
}

.sentence {
  display: block;
  max-width: 52rem;
  margin: 0 0 0.85rem;
  font-size: clamp(1.7rem, 4.4vw, 4.4rem);
  line-height: 1.05;
}

.char {
  display: inline-block;
  font-size: calc(1em * var(--size));
  font-weight: var(--weight);
  text-shadow:
    var(--thicken) 0 0 currentColor,
    calc(var(--thicken) * -1) 0 0 currentColor,
    0 var(--thicken) 0 currentColor;
  transform:
    translateY(calc(var(--y) * 1px))
    rotate(calc(var(--r) * 1deg))
    scaleX(var(--sx));
  transform-origin: 50% 70%;
}

.word {
  display: inline-block;
  white-space: nowrap;
}

.space {
  display: inline-block;
  width: 0.45em;
}

/* ── Selections ───────────────────────────────────────────── */

.selections {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 250, 240, 0.72);
  padding: 1.25rem;
}

.selections-row {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.selection-item {
  flex: 1;
  min-width: 0;
}

.selection-label {
  margin: 0 0 0.2rem;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.selection-name {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selection-details {
  margin: 0.3rem 0 0;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  line-height: 1.5;
}

.copy-btn {
  flex-shrink: 0;
  padding: 0.7rem 1.5rem;
  border: 1.5px solid var(--ink);
  border-radius: 100px;
  background: transparent;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.copy-btn:active {
  background: var(--ink);
  color: var(--paper);
}

@media (hover: hover) {
  .copy-btn:hover {
    background: var(--ink);
    color: var(--paper);
  }

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

/* ── Password gate ─────────────────────────────────────────── */

html[data-authed] #gate {
  display: none;
}

#gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f7efe2;
}

.gate-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3rem;
  padding: 2rem;
  text-align: center;
}

.gate-title {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  font-size: clamp(3.5rem, 11vw, 9rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 0.88;
  text-transform: uppercase;
  color: var(--ink);
}

.gate-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

#gateInput {
  width: 20rem;
  max-width: 80vw;
  padding: 1rem 1.75rem;
  border: 1.5px solid var(--sand);
  border-radius: 100px;
  background: var(--paper);
  font-family: inherit;
  font-size: 1rem;
  letter-spacing: 0.14em;
  text-align: center;
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s;
}

#gateInput::placeholder {
  color: var(--muted);
  letter-spacing: 0.1em;
}

#gateInput:focus {
  border-color: var(--ink);
}

#gateInput.shake {
  border-color: #b85c5c;
  animation: gate-shake 0.38s ease;
}

.gate-error {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #b85c5c;
}

@keyframes gate-shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-10px); }
  45%       { transform: translateX(9px); }
  65%       { transform: translateX(-6px); }
  85%       { transform: translateX(4px); }
}

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 960px) {
  body {
    grid-template-columns: 1fr;
  }

  .controls {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .font-section-head {
    flex-direction: column;
    gap: 0.75rem;
  }

  .filter-btn {
    align-self: auto;
    width: fit-content;
  }

  .selections-row {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  .selection-item {
    flex: none;
  }

  .copy-btn {
    width: 100%;
    text-align: center;
    padding: 0.9rem 1.5rem;
  }
}

@media (max-width: 480px) {
  .slots {
    grid-template-columns: 1fr 1fr;
  }

  .font-picker {
    grid-template-columns: repeat(auto-fill, minmax(min(10rem, 100%), 1fr));
  }

  .line {
    font-size: clamp(2.5rem, 12vw, 5rem);
  }

  .sentence {
    font-size: clamp(1.4rem, 6vw, 3rem);
  }
}
