/* So sagt Emma — paper, not product */

:root {
  --ground: #F3EBE0;
  --paper: #FBF7F0;
  --ink: #1C1612;
  --muted: #8A7E72;
  --hair: rgba(28, 22, 18, 0.12);
  --hair-strong: rgba(28, 22, 18, 0.22);
  --accent: #B8573A;
  --accent-wash: rgba(184, 87, 58, 0.16);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --body: "Figtree", "Helvetica Neue", sans-serif;
  --shadow-rest: 0 1px 1px rgba(28, 22, 18, 0.03), 0 6px 18px rgba(28, 22, 18, 0.035);
  --shadow-lift: 0 2px 4px rgba(28, 22, 18, 0.035), 0 14px 32px rgba(28, 22, 18, 0.07);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

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

html,
body {
  margin: 0;
  padding: 0;
}

html {
  background: var(--ground);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--body);
  font-weight: 400;
  font-size: 16px;
  line-height: 1.5;
  background: var(--ground);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-kerning: normal;
}

body.sheet-open {
  overflow: hidden;
}

img,
svg {
  display: block;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  border-radius: 0;
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
}

button {
  cursor: pointer;
  padding: 0;
}

input,
textarea {
  caret-color: var(--accent);
}

textarea {
  resize: none;
}

::selection {
  background: var(--accent-wash);
  color: var(--ink);
}

:focus {
  outline: none;
}

:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 3px;
}

input:focus-visible,
textarea:focus-visible {
  outline: none;
}

button::-moz-focus-inner {
  border: 0;
}

:-webkit-autofill {
  -webkit-text-fill-color: var(--ink);
  transition: background-color 9999s ease-out;
}

html {
  -webkit-tap-highlight-color: transparent;
}

.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;
}

[hidden] {
  display: none !important;
}

/* Paper grain — tactile, almost invisible */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 80;
  opacity: 0.038;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
}

/* Stages: gate + dedication occupy the whole page */
.stage {
  min-height: 100vh;
  min-height: 100dvh;
}

.stage-center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(2.5rem, calc(var(--safe-t) + 2rem)) 1.5rem max(2.5rem, calc(var(--safe-b) + 2rem));
}

html.unlocked #gate,
html.unlocked #dedication {
  display: none !important;
}

html.unlocked #lexicon {
  display: block;
}

html.unlocked #lexicon[hidden] {
  display: block !important;
}

/* ——— Gate ——— */
.gate {
  width: min(26rem, 100%);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.gate.is-leaving {
  animation: inhale 0.62s var(--ease) forwards;
}

.gate-q {
  font-family: var(--display);
  font-size: clamp(1.85rem, 1.2rem + 3.2vw, 2.7rem);
  font-weight: 400;
  font-optical-sizing: auto;
  font-variation-settings: "SOFT" 52, "opsz" 80;
  line-height: 1.22;
  letter-spacing: -0.012em;
  max-width: 14ch;
  display: block;
  cursor: text;
}

#gate-in {
  display: block;
  width: 11.5rem;
  margin-top: 2.6rem;
  padding: 0.55rem 0.25rem 0.5rem;
  text-align: center;
  font-family: var(--display);
  font-size: 1.45rem;
  font-optical-sizing: auto;
  font-variation-settings: "SOFT" 60, "opsz" 36;
  line-height: 1.2;
  border-bottom: 1px solid var(--hair-strong);
  transition: border-color 0.4s var(--ease);
}

#gate-in:focus {
  border-bottom-color: var(--ink);
}

.gate-hint {
  margin: 0.7rem 0 0;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.gate.is-wrong #gate-in {
  animation: shake 0.46s var(--ease);
}

/* ——— Dedication ——— */
.dedication {
  width: min(28rem, 100%);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.dedication > * {
  animation: rise 0.84s var(--ease) both;
}

.ded-title {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(2.15rem, 1.4rem + 3.4vw, 3.1rem);
  font-weight: 400;
  font-optical-sizing: auto;
  font-variation-settings: "SOFT" 40, "opsz" 96;
  letter-spacing: -0.018em;
  line-height: 1.1;
  animation-delay: 0.02s;
}

.ded-rule {
  display: block;
  width: 2rem;
  height: 1px;
  margin: 1.7rem 0 1.55rem;
  background: var(--ink);
  opacity: 0.22;
  animation-delay: 0.08s;
}

.ded-for {
  margin: 0;
  font-size: 1.12rem;
  letter-spacing: 0.01em;
  animation-delay: 0.14s;
}

.ded-line {
  margin: 0.85rem 0 0;
  max-width: 24ch;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
  animation-delay: 0.20s;
}

.ded-tiny {
  margin: 2.15rem 0 0;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: var(--muted);
  animation-delay: 0.28s;
}

#herein {
  margin-top: 2.35rem;
  animation-delay: 0.36s;
}

.dedication.is-leaving {
  animation: inhale 0.55s var(--ease) forwards;
}

/* Quiet text action — never a CTA pill */
.btn-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0.55rem 0.15rem;
  font-size: 1rem;
  letter-spacing: 0.02em;
  color: var(--ink);
  background-image: linear-gradient(currentColor, currentColor);
  background-size: 100% 1px;
  background-repeat: no-repeat;
  background-position: 0 72%;
  transition: opacity 0.4s var(--ease), letter-spacing 0.5s var(--ease);
}

.btn-text:hover {
  letter-spacing: 0.06em;
}

.btn-text:focus-visible {
  outline: none;
  letter-spacing: 0.06em;
}

/* ——— Lexicon ——— */
.lexicon {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: var(--safe-b);
}

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--ground);
  padding-top: var(--safe-t);
  border-bottom: 1px solid transparent;
}

.bar.is-searching {
  border-bottom-color: var(--hair);
}

.bar-inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 56px;
  padding: 0 max(0.55rem, var(--safe-r)) 0 max(1.15rem, calc(var(--safe-l) + 1.15rem));
  max-width: 1080px;
  margin: 0 auto;
}

.bar-title {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  font-size: 1.12rem;
  font-optical-sizing: auto;
  font-variation-settings: "SOFT" 36, "opsz" 28;
  letter-spacing: -0.01em;
  line-height: 1;
}

.bar.is-searching .bar-title {
  display: none;
}

.search {
  flex: 1;
  min-width: 0;
}

#search-in {
  width: 100%;
  min-height: 44px;
  padding: 0.4rem 0;
  font-family: var(--display);
  font-size: 1.2rem;
  font-optical-sizing: auto;
  font-variation-settings: "SOFT" 50, "opsz" 28;
  border-bottom: 1px solid var(--hair-strong);
}

#search-in::placeholder {
  color: var(--muted);
  font-style: italic;
  font-family: var(--display);
  opacity: 0.7;
}

#search-in::-webkit-search-decoration,
#search-in::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.bar-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: var(--ink);
  opacity: 0.78;
  transition: opacity 0.35s var(--ease);
}

.icon-btn:hover {
  opacity: 1;
}

.bar.is-searching #btn-search,
.bar.is-searching #btn-add {
  display: none;
}

.chapters {
  display: flex;
  align-items: baseline;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0;
  padding: 0.15rem 1.25rem 1.35rem;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.ch.on {
  color: var(--ink);
}

.ch.soon {
  pointer-events: none;
}

.ch i {
  font-style: normal;
  font-size: 0.58rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-left: 0.35em;
  opacity: 0.7;
}

.ch-dot {
  margin: 0 0.8em;
  opacity: 0.45;
}

/* ——— Gallery ——— */
.gallery {
  list-style: none;
  margin: 0 auto;
  padding: 0.15rem max(1rem, var(--safe-l)) 2.5rem max(1rem, var(--safe-r));
  max-width: 1080px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.gallery > li {
  margin: 0;
  min-width: 0;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 104px;
  padding: 1.55rem 0.7rem 1.45rem;
  background: var(--paper);
  border: 1px solid var(--hair);
  box-shadow: var(--shadow-rest);
  text-align: center;
  transition: transform 0.5s var(--ease), box-shadow 0.5s var(--ease);
  animation: rise 0.7s var(--ease) both;
  animation-delay: var(--delay, 0ms);
}

.card-word {
  font-family: var(--display);
  font-size: clamp(1.7rem, 1.1rem + 2.4vw, 2.35rem);
  font-weight: 400;
  font-optical-sizing: auto;
  font-variation-settings: "SOFT" 58, "opsz" 72;
  line-height: 1.14;
  letter-spacing: -0.015em;
  max-width: 100%;
  white-space: nowrap;
}

.card-word.is-long {
  font-size: clamp(1.22rem, 0.85rem + 1.5vw, 1.7rem);
  font-variation-settings: "SOFT" 50, "opsz" 40;
  letter-spacing: -0.025em;
}

.card-word.is-xlong {
  font-size: clamp(0.98rem, 0.7rem + 1.1vw, 1.35rem);
  font-variation-settings: "SOFT" 46, "opsz" 28;
  letter-spacing: -0.035em;
}

.card-word-more {
  margin-top: 0.28em;
}

.card-neu {
  position: absolute;
  top: 0.7rem;
  left: 0.85rem;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

@media (hover: hover) and (pointer: fine) {
  .card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lift);
  }
}

.card:active {
  transform: translateY(0);
}

.empty {
  margin: 3.5rem auto 4rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 28ch;
  padding: 0 1.5rem;
}

.colophon {
  text-align: center;
  padding: 0.5rem 1.25rem calc(2.4rem + var(--safe-b));
}

.colophon p {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

/* ——— Sheets ——— */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(28, 22, 18, 0.28);
  padding: 0;
  opacity: 0;
  transition: opacity 0.45s var(--ease);
}

.scrim.is-open {
  opacity: 1;
}

.sheet {
  position: relative;
  width: 100%;
  max-height: 88dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--paper);
  border-radius: 18px 18px 0 0;
  padding: 0.2rem 1.45rem calc(1.8rem + var(--safe-b));
  transform: translateY(16%);
  transition: transform 0.58s var(--ease);
  -webkit-overflow-scrolling: touch;
}

.scrim.is-open .sheet {
  transform: translateY(0);
}

.sheet-chrome {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}

.sheet-handle {
  width: 2.15rem;
  height: 3px;
  border-radius: 99px;
  background: var(--hair-strong);
}

.sheet-close {
  position: absolute;
  right: -0.45rem;
  top: 0;
}

.entry-body {
  padding: 1.6rem 0.4rem 1.4rem;
  text-align: center;
  min-height: 28vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.entry-word {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(2.5rem, 1.4rem + 6vw, 4.1rem);
  font-weight: 400;
  font-optical-sizing: auto;
  font-variation-settings: "SOFT" 56, "opsz" 144;
  line-height: 1.1;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.entry-adult {
  margin: 1.05rem 0 0;
  font-size: 0.68rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.entry-note {
  margin: 1.7rem auto 0;
  max-width: 28ch;
  font-style: italic;
  font-size: 1.02rem;
  line-height: 1.55;
}

.entry-from {
  margin: 2.15rem 0 0;
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ——— Neues Wort ——— */
.add-form {
  padding: 0.4rem 0.15rem 0.6rem;
  text-align: center;
}

.add-form .field {
  text-align: left;
}

.add-heading {
  margin: 0 0 1.8rem;
  text-align: center;
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  font-size: 1.55rem;
  font-optical-sizing: auto;
  font-variation-settings: "SOFT" 48, "opsz" 36;
}

.field {
  display: block;
  margin-top: 1.45rem;
}

.field:first-of-type {
  margin-top: 0;
}

.field span {
  display: block;
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.15rem;
}

.field input,
.field textarea {
  width: 100%;
  padding: 0.55rem 0 0.5rem;
  font-family: var(--display);
  font-size: 1.28rem;
  font-optical-sizing: auto;
  font-variation-settings: "SOFT" 50, "opsz" 28;
  line-height: 1.25;
  border-bottom: 1px solid var(--hair);
  transition: border-color 0.35s var(--ease);
}

.field textarea {
  font-family: var(--body);
  font-style: italic;
  font-size: 1.02rem;
  line-height: 1.45;
}

.field input:focus,
.field textarea:focus {
  border-bottom-color: var(--ink);
}

.field.is-wrong input {
  animation: shake 0.46s var(--ease);
}

.add-save {
  display: inline-flex;
  width: auto;
  margin: 2.35rem auto 0;
}

/* ——— Motion ——— */
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes inhale {
  to {
    opacity: 0;
    transform: scale(1.03);
  }
}

@keyframes shake {
  0%,
  100% { transform: translateX(0); }
  22% { transform: translateX(-7px); }
  44% { transform: translateX(7px); }
  66% { transform: translateX(-4px); }
  84% { transform: translateX(4px); }
}

.noscript {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Desktop: editorial grid + paper panel */
@media (min-width: 680px) {
  .gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    padding-left: 2.1rem;
    padding-right: 2.1rem;
    padding-top: 0.4rem;
  }

  .card {
    min-height: 148px;
    padding: 2.6rem 1.7rem 2.4rem;
  }

  .bar-inner {
    padding-left: 2.1rem;
    padding-right: 1.5rem;
  }

  .chapters {
    padding-bottom: 1.7rem;
  }
}

@media (min-width: 980px) {
  .gallery {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px 20px;
    padding-left: 2.4rem;
    padding-right: 2.4rem;
    padding-bottom: 3.5rem;
  }

  .card {
    min-height: 158px;
  }

  .bar-inner {
    padding-left: 2.4rem;
    padding-right: 1.8rem;
    min-height: 64px;
  }

  .bar-title {
    font-size: 1.22rem;
  }
}

@media (min-width: 720px) {
  .scrim {
    align-items: center;
    padding: 2.5rem 1.5rem;
  }

  .sheet {
    width: min(32rem, 100%);
    max-height: min(80vh, 80dvh);
    border-radius: 2px;
    border: 1px solid var(--hair);
    box-shadow: var(--shadow-lift);
    padding: 1.4rem 2.8rem 2.8rem;
    transform: translateY(10px);
  }

  .scrim.is-open .sheet {
    transform: translateY(0);
  }

  .sheet-handle {
    display: none;
  }

  .sheet-chrome {
    justify-content: flex-end;
    min-height: 40px;
  }

  .sheet-close {
    position: static;
  }

  .entry-body {
    padding: 0.6rem 0.4rem 0.8rem 0.4rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .card:hover {
    transform: none;
  }
}
