:root {
  --paper: #fffef8;
  --grid: rgba(225, 6, 0, 0.08);
  --ink: #111111;
  --accent: #e10600;
  --cover-red: #e10600;
  --marker: #111111;
  --shadow: rgba(0, 0, 0, 0.14);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 22px 22px;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.hidden {
  display: none !important;
}

.main-content {
  max-width: 640px;
  margin: 0 auto;
}

.boot-error {
  position: fixed;
  top: max(0.5rem, var(--safe-top));
  left: 0.875rem;
  right: 0.875rem;
  z-index: 200;
  margin: 0;
}

.site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  padding: 0.5rem max(0.75rem, var(--safe-left)) calc(0.5rem + var(--safe-bottom)) max(0.75rem, var(--safe-right));
  background: rgba(255, 254, 248, 0.96);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(8px);
}

.site-nav {
  display: flex;
  justify-content: space-around;
  gap: 0.25rem;
  max-width: 640px;
  margin: 0 auto;
}

.site-nav a {
  flex: 1;
  text-align: center;
  text-decoration: none;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.65rem 0.35rem;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}

.site-nav a:hover,
.site-nav a.site-nav-active {
  color: var(--accent);
  background: rgba(225, 6, 0, 0.1);
}

body.has-footer {
  padding-bottom: calc(8.5rem + var(--safe-bottom));
}

body.has-footer.footer-projects-collapsed {
  padding-bottom: calc(5rem + var(--safe-bottom));
}

.author-projects {
  max-width: 640px;
  margin: 0 auto 0.5rem;
  padding: 0 0.25rem;
}

.author-projects-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  margin: 0 0 0.45rem;
  padding: 0.35rem 0.5rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: #666;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.author-projects-toggle:hover {
  background: rgba(0, 0, 0, 0.04);
}

.author-projects-title {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
  color: inherit;
}

.author-projects-chevron {
  flex-shrink: 0;
  font-size: 0.55rem;
  line-height: 1;
  transition: transform 0.2s ease;
}

.author-projects.is-collapsed .author-projects-chevron {
  transform: rotate(-90deg);
}

.author-projects.is-collapsed .author-projects-body {
  display: none;
}

.author-projects:not(.is-collapsed) .author-projects-body {
  margin-bottom: 0.1rem;
}

.project-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  background: #fff;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.project-card:hover {
  border-color: rgba(192, 57, 43, 0.35);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.project-card img {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  background: #f0f0f0;
}

.project-card-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.project-card-text strong {
  font-size: 0.95rem;
  color: var(--accent);
}

.project-card-text span {
  font-size: 0.8rem;
  line-height: 1.35;
  color: #555;
}

/* ——— Intro / блокнот ——— */
.intro {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding: max(1rem, var(--safe-top)) 1rem max(1rem, var(--safe-bottom));
  background: radial-gradient(ellipse at 50% 30%, #3a0505 0%, #140202 55%, #0a0000 100%);
  z-index: 100;
  transition: opacity 0.55s ease;
}

.intro.fade-out {
  opacity: 0;
  pointer-events: none;
}

.intro-loading {
  position: absolute;
  z-index: 10;
  color: #f5e6d3;
  font-size: 1rem;
  margin: 0 0 1rem;
  text-align: center;
}

.intro.is-loading .notebook {
  visibility: hidden;
}

.intro-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  width: min(86vw, 360px);
  z-index: 5;
}

.intro-btn {
  width: 100%;
  max-width: 320px;
  min-height: 52px;
  font-size: 1.05rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.notebook {
  position: relative;
  width: min(86vw, 360px);
  aspect-ratio: 5 / 7;
  flex-shrink: 0;
  perspective: 2200px;
}

.notebook-back {
  position: absolute;
  inset: 0;
  background: var(--cover-red);
  border-radius: 10px 16px 16px 10px;
  box-shadow: 4px 8px 24px rgba(0, 0, 0, 0.4);
}

.notebook-pages {
  position: absolute;
  inset: 12px 12px 12px 20px;
  z-index: 1;
  background: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 18px 18px;
  border-radius: 4px 12px 12px 4px;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.05);
}

.notebook-cover {
  position: absolute;
  inset: 0;
  z-index: 2;
  transform-style: preserve-3d;
  transform-origin: 0% 50%;
  transition: transform 1.35s cubic-bezier(0.33, 0, 0.2, 1);
  filter: drop-shadow(4px 8px 16px rgba(0, 0, 0, 0.35));
}

.cover-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 10px 16px 16px 10px;
  overflow: hidden;
}

.cover-front img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cover-inside {
  background: var(--cover-red);
  transform: rotateY(180deg);
}

.notebook.open .notebook-cover {
  transform: rotateY(-172deg);
}

/* ——— Екрани ——— */
.screen {
  padding: max(0.75rem, var(--safe-top)) 0.875rem 1rem;
}

.paper-panel {
  background: rgba(255, 254, 248, 0.95);
  border: 1px solid rgba(225, 6, 0, 0.12);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 2px 10px var(--shadow);
  margin-bottom: 0.75rem;
}

.auth-panel {
  text-align: center;
  margin-top: 0.5rem;
}

.auth-panel h1 {
  margin: 0;
  font-family: "Marck Script", "Caveat", cursive;
  font-size: clamp(1.8rem, 7vw, 2.4rem);
  font-weight: 700;
  line-height: 1.1;
  color: var(--accent);
  text-transform: lowercase;
}

.auth-year {
  margin: 0.15rem 0 0.65rem;
  font-family: "Marck Script", "Caveat", cursive;
  font-size: clamp(2rem, 9vw, 2.75rem);
  font-weight: 700;
  line-height: 1;
  color: var(--marker);
  letter-spacing: 0.04em;
}

.auth-buttons {
  margin: 1rem 0;
}

.dev-hint {
  font-size: 0.875rem;
  color: #666;
  margin: 0 0 0.75rem;
}

.page-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 1.25rem;
  margin-top: 1rem;
}

.page-links a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.95rem;
  padding: 0.35rem 0;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.page-links a:hover {
  text-decoration: underline;
}

.banner-error {
  background: #fdecea;
  color: #922;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  font-size: 0.9rem;
  margin: 0.5rem 0;
}

/* ——— Хедер апки ——— */
.app-header {
  margin-bottom: 0.75rem;
}

.app-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem 0.75rem;
  margin-bottom: 0.5rem;
}

.app-header h1 {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-family: "Marck Script", "Caveat", cursive;
  font-size: clamp(1.5rem, 5.5vw, 2.1rem);
  font-weight: 700;
  line-height: 1.1;
  color: var(--marker);
}

.header-actions {
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  margin: 0;
}

.list-stats {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.45;
  color: #444;
}

.list-stats strong {
  color: var(--accent);
  font-weight: 700;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(5.5rem + var(--safe-bottom));
  z-index: 300;
  max-width: min(92vw, 360px);
  padding: 0.65rem 1rem;
  background: #1a1a2e;
  color: #fffef8;
  border-radius: 12px;
  font-size: 0.92rem;
  text-align: center;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  transform: translateX(-50%) translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.list-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.65rem 0.75rem;
}

.page-info {
  font-size: 0.88rem;
  color: #555;
  text-align: center;
  flex: 1;
}

.app-header .page-links {
  justify-content: flex-start;
  margin-top: 0;
}

/* ——— Кнопки ——— */
.btn {
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  min-height: 44px;
  font-size: 1rem;
  cursor: pointer;
  font-family: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

.btn.ghost {
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.18);
  color: var(--ink);
}

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

.btn.ghost.small {
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  min-height: 40px;
  width: auto;
}

.btn.danger {
  background: #922;
  color: #fff;
  flex: 1;
}

/* ——— Форма додавання ——— */
.add-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.add-form input,
.add-form textarea {
  width: 100%;
  padding: 0.75rem 0.85rem;
  min-height: 48px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 10px;
  font-family: inherit;
  font-size: 16px;
  background: #fff;
}

.add-form input:focus,
.add-form textarea:focus {
  outline: 2px solid rgba(225, 6, 0, 0.35);
  outline-offset: 1px;
}

.add-reason {
  resize: vertical;
  min-height: 3.5rem;
  max-height: 8rem;
}

.add-reason-counter {
  margin: -0.35rem 0 0.5rem;
  font-size: 0.8rem;
  color: #777;
  text-align: right;
}

.entry-reason {
  margin: 0.2rem 0 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 0.95rem;
  font-weight: 400;
  line-height: 1.4;
  color: #333;
  word-break: break-word;
}

.add-form-hint {
  margin: -0.15rem 0 0.85rem;
  padding: 0 0.15rem;
  font-size: 0.85rem;
  line-height: 1.45;
  color: #666;
}

/* ——— Список ——— */
.entries {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.entry {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.entry-body {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.entry-view {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.entry-handwriting {
  margin: 0;
  font-family: "Marck Script", "Caveat", "Segoe Script", cursive;
  color: var(--marker);
  font-weight: 700;
  line-height: 1.15;
  word-break: break-word;
  letter-spacing: 0.01em;
}

.entry-handwriting-name {
  font-size: clamp(1.5rem, 5.5vw, 1.95rem);
}

.entry-handwriting-telegram {
  font-size: clamp(1.25rem, 4.8vw, 1.6rem);
  color: var(--accent);
}

.entry-handwriting-email {
  font-size: clamp(1.2rem, 4.5vw, 1.55rem);
  font-weight: 500;
}

.telegram-auth-slot {
  display: flex;
  justify-content: center;
  min-height: 52px;
}

.telegram-bot-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-top: 0.35rem;
  text-decoration: none;
  font-weight: 600;
}

.telegram-bot-nav {
  color: var(--accent) !important;
  font-weight: 600;
}

.telegram-bot-nav:hover {
  text-decoration: underline;
}

.telegram-bot-header {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.entry-handwriting-empty {
  font-size: 1rem;
  font-family: inherit;
  font-weight: 400;
  color: #999;
  font-style: italic;
}

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

.entry-edit.hidden {
  display: none !important;
}

.entry-edit input,
.entry-edit textarea {
  width: 100%;
  padding: 0.7rem 0.8rem;
  min-height: 48px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 10px;
  font-family: inherit;
  font-size: 16px;
  background: #fff;
}

.entry-edit textarea {
  min-height: 3.5rem;
  resize: vertical;
}

.entry-edit input:focus,
.entry-edit textarea:focus {
  outline: 2px solid rgba(225, 6, 0, 0.35);
  outline-offset: 1px;
}

.entry-meta {
  font-size: 0.8rem;
  color: #666;
  line-height: 1.35;
}

.entry-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.entry-actions-view,
.entry-actions-edit {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  width: 100%;
}

.entry-actions-edit.hidden {
  display: none !important;
}

.entry-actions .btn.ghost {
  flex: 1;
  min-width: 7rem;
}

.empty {
  text-align: center;
  color: #666;
  padding: 1.25rem;
}

/* ——— Статистика ——— */
.stats-page,
.support-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: max(1rem, var(--safe-top)) 0.875rem calc(5rem + var(--safe-bottom));
}

.stats-panel,
.support-panel {
  width: 100%;
  max-width: 480px;
  text-align: center;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.85rem 1rem;
  text-align: left;
  margin: 1.25rem 0;
}

.stats-grid dt {
  font-weight: 600;
}

.stats-grid dd {
  margin: 0;
  font-size: 1.4rem;
  color: var(--accent);
  text-align: right;
}

.stats-reasons {
  margin-top: 1.25rem;
  text-align: left;
}

.stats-reasons h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.stats-reasons-hint {
  margin: 0;
  font-size: 0.9rem;
  color: #666;
}

.reasons-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.reasons-list li {
  padding: 0.75rem 0.85rem;
  border: 1px solid rgba(225, 6, 0, 0.12);
  border-radius: 10px;
  background: rgba(255, 254, 248, 0.9);
}

.reasons-list .reason-text {
  margin: 0 0 0.35rem;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 0.95rem;
  font-weight: 400;
  line-height: 1.4;
  color: #333;
  word-break: break-word;
}

.reasons-list .reason-date {
  font-size: 0.8rem;
  color: #666;
}

.page-nav {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.page-nav a {
  color: var(--accent);
  text-decoration: none;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.fund-description {
  line-height: 1.55;
  margin: 1rem 0 1.25rem;
  text-align: left;
}

.fund-description p {
  margin: 0 0 0.75rem;
}

.fund-updated {
  font-size: 0.8rem;
  color: #666;
  margin: 0 0 1rem;
}

.btn.monobank {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  text-decoration: none;
  background: #000;
  color: #fff;
  padding: 0.9rem 1.25rem;
  font-weight: 600;
  font-size: 1rem;
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

.fund-inactive,
.fund-error {
  color: #666;
  font-size: 0.95rem;
}

.fund-error {
  color: var(--accent);
}

#audio-budda,
#audio-fail {
  position: fixed;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.fail-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.fail-modal.hidden {
  display: none;
}

.fail-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.fail-modal-panel {
  position: relative;
  z-index: 1;
  max-width: 22rem;
  width: 100%;
  padding: 1.25rem 1.35rem 1.1rem;
  text-align: center;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
}

.fail-modal-text {
  margin: 0 0 1.1rem;
  font-size: 1.05rem;
  line-height: 1.45;
  color: var(--ink);
}

.fail-modal-panel .btn {
  width: 100%;
}

/* Mortal Kombat–style: вилізання з нижнього правого кута під 45° */
.budanov-cameo {
  position: fixed;
  right: 0;
  bottom: 0;
  z-index: 200;
  pointer-events: none;
  line-height: 0;
}

.budanov-cameo img {
  display: block;
  width: min(58vw, 340px);
  height: auto;
  transform-origin: 100% 100%;
  transform: rotate(-45deg) translate(115%, 115%);
  opacity: 0;
  filter: drop-shadow(-6px 8px 22px rgba(0, 0, 0, 0.65));
  will-change: transform, opacity;
}

.budanov-cameo.is-active img {
  animation: budanov-mk-corner 1.2s cubic-bezier(0.22, 0.85, 0.3, 1) forwards;
}

@keyframes budanov-mk-corner {
  0% {
    transform: rotate(-45deg) translate(115%, 115%);
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  28% {
    transform: rotate(-45deg) translate(50%, 50%);
    opacity: 1;
  }
  72% {
    transform: rotate(-45deg) translate(50%, 50%);
    opacity: 1;
  }
  100% {
    transform: rotate(-45deg) translate(115%, 115%);
    opacity: 0;
  }
}

/* ——— Планшет+ ——— */
@media (min-width: 600px) {
  .notebook {
    width: min(400px, 42vw);
  }

  .screen {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
  }

  .add-form {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
  }

  .add-form input {
    flex: 1 1 160px;
    width: auto;
  }

  .add-form .btn.primary {
    width: auto;
    min-width: 120px;
  }

  .entry {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: start;
  }

  .entry-body {
    grid-column: 1;
  }

  .entry-actions {
    grid-column: 2;
    grid-row: 1;
  }

  .entry-actions {
    flex-direction: column;
    min-width: 110px;
  }

  .entry-actions .btn {
    width: 100%;
  }

  .app-header .page-links {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (min-width: 900px) {
  .screen {
    max-width: 720px;
  }
}
