:root {
  color-scheme: light;
  --background: #f1eee7;
  --paper: #fffcf6;
  --ink: #3e4339;
  --muted: #76786d;
  --green: #65785d;
  --green-dark: #495d43;
  --line: #deded1;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  background: var(--background);
  font-synthesis: none;
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
body { margin: 0; background: radial-gradient(ellipse at 12% 18%, #e2e6d967, transparent 48%), radial-gradient(ellipse at 94% 74%, #e5ddce80, transparent 42%); min-height: 100dvh; }
button, input { font: inherit; }
button { cursor: pointer; border: 0; }
button, input, article { touch-action: manipulation; }
button:focus-visible, article:focus-visible { outline: 2px solid var(--green); outline-offset: 5px; }
[hidden] { display: none !important; }
.page-shell { width: min(100% - 48px, 680px); margin: 0 auto; padding: 30px 0 35px; }
.site-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.brand { display: inline-flex; align-items: center; color: var(--green-dark); }
.brand svg { width: 32px; height: 32px; stroke: var(--green); stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
.brand .envelope-heart { fill: var(--background); }
.icon-button { display: grid; place-items: center; width: 44px; height: 44px; border: 1px solid #d9dacf; border-radius: 50%; color: var(--green-dark); background: transparent; transition: background .2s; flex-shrink: 0; }
.icon-button:hover { background: #e4e6da; }
.icon-button svg { width: 21px; height: 21px; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; }
.icon-button circle { fill: var(--background); }
.paper { display: flex; flex-direction: column; min-height: 375px; position: relative; overflow: hidden; padding: 30px 45px 32px; border: 1px solid #e7e1d3; border-radius: 5px 5px 24px 5px; background-color: var(--paper); background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.88' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Cpath fill='%239e9477' opacity='.055' filter='url(%23n)' d='M0 0h180v180H0z'/%3E%3C/svg%3E"); box-shadow: 0 4px 7px #605b3b03, 0 18px 48px #605b3b09; cursor: pointer; }
.paper::before { content: ""; position: absolute; top: 0; left: 45px; right: 45px; height: 2px; background: #7d8b684a; }
.letter-heading { text-align: center; padding: 10px 0 25px; }
h1 { margin: 11px 0 15px; font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: clamp(29px, 5.7vw, 40px); line-height: 1.2; letter-spacing: -.04em; color: #485240; }
.heading-flourish { width: 134px; height: 16px; stroke: #9fa786; stroke-width: 1.15; stroke-linecap: round; }
.welcome { display: flex; flex: 1; align-items: center; justify-content: center; text-align: center; padding: 8px 0 22px; }
.flower { width: 99px; height: 124px; stroke: #859573; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.letter-text { min-height: 165px; padding: 4px 0 6px; font-family: Georgia, "Times New Roman", serif; font-size: 18px; line-height: 1.85; overflow-wrap: anywhere; }
.letter-text p { margin: 0 0 23px; white-space: pre-wrap; }
.letter-text p:last-child { margin-bottom: 0; }
/* inline сохраняет естественные переносы слов; backwards скрывает букву до её очереди. */
.new-ink { animation: ink-in 640ms cubic-bezier(.22, .61, .36, 1) var(--ink-delay, 0ms) both; }
.reading-controls { padding: 22px 28px 0; }
.reveal-button { display: flex; justify-content: center; align-items: center; gap: 18px; width: 100%; min-height: 55px; border-radius: 7px; background: var(--green); color: #fffcf6; box-shadow: 0 5px 12px #65785d15; font-size: 14px; transition: background .2s, transform .15s; user-select: none; }
.reveal-button > span:last-child { font-size: 23px; line-height: 1; }
.reveal-button:hover { background: var(--green-dark); }
.reveal-button:active { transform: scale(.99); }
.reveal-button:disabled { background: #e0e4d8; color: #596950; cursor: default; box-shadow: none; }
.controls-hint { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 12px; color: var(--muted); font-size: 11px; }
.hint-dot { color: #a4a692; }
.text-button { color: var(--green-dark); padding: 9px 3px; background: none; text-decoration: underline; text-decoration-color: #a0ab90; text-underline-offset: 3px; min-height: 36px; }
.floating-heart { position: fixed; z-index: 9999; pointer-events: none; user-select: none; color: #e53945; font-family: Georgia, serif; font-size: var(--heart-size, 13px); line-height: 1; transform: translate(-50%, -50%); animation: float-heart 1s ease-out forwards; }
dialog { width: min(100% - 32px, 440px); border: 1px solid #dfdfd1; border-radius: 16px; padding: 28px; color: var(--ink); background: var(--paper); box-shadow: 0 24px 80px #33382b22; max-height: calc(100dvh - 32px); overflow-y: auto; }
dialog[open] { animation: soft-in .18s ease; }
dialog::backdrop { background: #38423150; backdrop-filter: blur(5px); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: 27px; line-height: 1.25; margin: 17px 0 13px; letter-spacing: -.025em; }
.dialog-heading h2 { margin: 0; }
.dialog-description { color: var(--muted); font-size: 13px; line-height: 1.75; margin-bottom: 23px; }
.step-options { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 25px; }
.step-options button { min-height: 48px; border: 1px solid var(--line); border-radius: 7px; background: transparent; color: var(--ink); font-size: 16px; }
.step-options button[aria-pressed="true"] { background: var(--green); color: var(--paper); border-color: var(--green); }
.number-label { display: block; font-size: 12px; margin-bottom: 10px; }
.custom-step-row { display: flex; align-items: center; gap: 13px; }
.custom-step-row input { width: 100px; height: 47px; border: 1px solid #b8c0ab; border-radius: 6px; background: #fffdf8; color: var(--ink); font-size: 16px; padding: 10px 12px; outline-color: var(--green); }
.custom-step-row span { color: var(--muted); font-size: 12px; }
.field-help { color: var(--muted); font-size: 11px; line-height: 1.6; margin: 10px 0 23px; }
.save-note { border-top: 1px solid var(--line); padding-top: 19px; font-size: 11px; line-height: 1.7; color: var(--muted); margin-bottom: 23px; }
.primary-button { width: 100%; background: var(--green); color: var(--paper); min-height: 49px; border-radius: 7px; font-size: 13px; }
.primary-button:hover { background: var(--green-dark); }
.reset-button { display: block; min-height: 44px; margin: 9px auto 0; padding: 10px; color: var(--muted); background: transparent; font-size: 12px; }
.notice { color: #815c39; font-size: 12px; line-height: 1.5; text-align: center; }
.noscript-notice { padding: 18px; text-align: center; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
@keyframes soft-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes ink-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes float-heart {
  0% { opacity: 1; transform: translate(-50%, -50%) rotate(0deg) scale(.65); }
  45% { opacity: .9; transform: translate(calc(-50% + var(--heart-mid-x, 0px)), calc(-50% + var(--heart-mid-y, -40px))) rotate(var(--heart-rotate, 0deg)) scale(1.1); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--heart-x, 0px)), calc(-50% + var(--heart-y, -70px))) rotate(var(--heart-rotate, 0deg)) scale(.7); }
}
.gate-shell { display: grid; place-items: center; min-height: 100dvh; padding: 24px 16px; }
.gate-card { width: min(100%, 420px); min-height: auto; text-align: center; cursor: default; padding: 32px; }
.gate-heart { font-family: Georgia, serif; color: #b6555f; font-size: 42px; }
.gate-card h1 { font-size: 31px; margin: 12px 0 28px; }
.code-input { display: block; width: 100%; min-height: 56px; padding: 12px; border: 1px solid #bcc4b0; border-radius: 7px; background: #fffdf8; color: var(--ink); font-size: 26px; text-align: center; letter-spacing: .4em; outline-color: var(--green); }
.code-error { min-height: 36px; margin: 12px 0; color: #b5434e; font-size: 12px; line-height: 1.5; }
.primary-button:disabled { opacity: .65; cursor: wait; }
@media (min-width: 1000px) { .page-shell { padding-top: 38px; } }
@media (max-width: 520px) {
  .page-shell { width: calc(100% - 28px); padding-top: max(15px, env(safe-area-inset-top)); padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  .site-header { margin-bottom: 18px; padding: 0 5px; }
  .paper { min-height: 330px; padding: 23px 25px 26px; border-bottom-right-radius: 19px; }
  .paper::before { left: 25px; right: 25px; }
  .letter-heading { padding: 5px 0 20px; }
  .flower { width: 87px; height: 110px; }
  .letter-text { font-size: 17px; line-height: 1.85; }
  .reading-controls { padding: 22px 10px 0; }
  dialog { padding: 24px; }
}
@media (max-width: 350px) {
  .paper { padding-left: 19px; padding-right: 19px; }
  h1 { font-size: 27px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
