:root {
  --bg0: #171F35; --bg1: #0D1220; --bg2: #05070D;
  --card: rgba(26,34,53,.92);
  --line: rgba(247,238,215,.08);
  --gold: #D7B56D; --gold2: #EFD39D;
  --cream: #F7EED7; --muted: #B8B2A2; --faint: #8F93A3; --ink: #1C1710;
  --serif: ui-serif, 'Iowan Old Style', Georgia, 'Times New Roman', serif;
  --sans: -apple-system, system-ui, 'Segoe UI', Roboto, sans-serif;
  --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);
  --nav-h: calc(68px + var(--safe-bottom) + 12px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; min-height: 100%;
  overscroll-behavior: none;
  background: #0D1220;
  color: var(--cream);
  font: 17px/1.45 var(--sans);
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
body { background: transparent; min-height: 100vh; min-height: 100dvh; }
/* iOS не умеет background-attachment: fixed, поэтому градиент — на отдельном слое */
body::before { content: ""; position: fixed; inset: 0; z-index: -1; background: linear-gradient(180deg, var(--bg0) 0%, var(--bg1) 45%, var(--bg2) 100%); }
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; position: relative; }
#screen {
  padding: calc(var(--safe-top) + 20px) calc(var(--safe-left) + 18px) calc(var(--safe-bottom) + 24px) calc(var(--safe-right) + 18px);
  outline: none;
  animation: fadein .6s ease both;
}
#app.nav-on #screen { padding-bottom: calc(var(--nav-h) + 24px); }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
h1, h2, h3 { margin: 0; font-weight: 600; }
p { margin: 0; }
a { color: var(--gold2); }
button { font: inherit; color: inherit; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--gold2); outline-offset: 2px; }
input, textarea, select { font: inherit; font-size: 16px; }

.screen-title { font-family: var(--serif); font-size: 30px; line-height: 1.2; color: var(--cream); margin: 8px 0 16px; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 24px; padding: 18px;
}
.stack { display: flex; flex-direction: column; gap: 12px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 52px; padding: 12px 20px;
  border-radius: 26px; border: 1px solid var(--line);
  background: rgba(247,238,215,.08); color: var(--cream);
  font-size: 17px; font-weight: 600; text-decoration: none; text-align: center; cursor: pointer;
}
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--gold2); }
.btn[disabled] { opacity: .45; cursor: default; }

.row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px;
  padding: 12px 16px; border-radius: 18px; border: 1px solid var(--line);
  background: rgba(247,238,215,.04); color: var(--cream);
  text-align: left; text-decoration: none; cursor: pointer;
}
.row > .grow { flex: 1; min-width: 0; }
.row svg { flex: none; }
.chip {
  display: inline-block; padding: 4px 12px; border-radius: 14px;
  background: rgba(215,181,109,.14); color: var(--gold2); font-size: 15px;
}
.back {
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; margin-left: -10px;
  background: transparent; border: 0; color: var(--cream); cursor: pointer;
}
svg.icon { width: 24px; height: 24px; display: block; }

/* главная */
.home-title { font-family: var(--serif); font-size: 34px; line-height: 1.15; text-align: center; margin: 14px 0 4px; }
.home-sub { text-align: center; color: var(--muted); margin-bottom: 18px; }
.now-label { color: var(--faint); font-size: 15px; letter-spacing: .04em; text-transform: uppercase; margin-bottom: 6px; }
.now-title { font-family: var(--serif); font-size: 22px; margin-bottom: 6px; }
.now-text { color: var(--muted); margin-bottom: 16px; }
.stats { display: flex; gap: 10px; }
.stat { flex: 1; text-align: center; padding: 14px 8px; }
.stat b { display: block; font-family: var(--serif); font-size: 26px; color: var(--gold2); font-weight: 600; }
.stat span { font-size: 15px; color: var(--muted); }
.votd-text { font-family: var(--serif); font-size: 19px; line-height: 1.5; }
.votd-ref { margin-top: 8px; color: var(--gold2); font-size: 16px; }
.install-actions { display: flex; gap: 10px; margin-top: 14px; }
.install-actions .btn { min-height: 48px; }

/* журнал */
.note-item { padding: 14px 0; border-top: 1px solid var(--line); }
.note-item:first-child { border-top: 0; }
.note-date { font-size: 15px; color: var(--faint); }
.note-title { font-family: var(--serif); font-size: 18px; margin: 2px 0; }
.note-body { color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }

/* нижняя панель */
#nav {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 12px);
  width: min(calc(100% - 28px), 360px);
  display: none; gap: 6px; padding: 6px;
  background: #121A2C; border: 1px solid var(--line); border-radius: 36px;
  z-index: 10;
}
#app.nav-on #nav { display: flex; }
#nav a {
  flex: 0 0 auto; min-width: 56px; height: 52px; padding: 0 16px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 28px; color: var(--muted); text-decoration: none; font-size: 16px; font-weight: 600;
  transition: background .5s ease, color .5s ease;
}
#nav a.on { flex: 1 1 auto; background: var(--gold); color: var(--ink); }
#nav a span { display: none; }
#nav a.on span { display: inline; }

/* диалог и сообщение */
.dialog-back {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  padding: calc(var(--safe-top) + 24px) calc(var(--safe-right) + 24px) calc(var(--safe-bottom) + 24px) calc(var(--safe-left) + 24px);
  background: rgba(5,7,13,.72);
  animation: fadein .3s ease both;
}
.dialog {
  width: 100%; max-width: 420px; background: #1A2235; border: 1px solid var(--line);
  border-radius: 26px; padding: 22px;
  max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px); overflow-y: auto;
}
.dialog h2 { font-family: var(--serif); font-size: 22px; margin-bottom: 10px; }
.dialog p { color: var(--muted); margin-bottom: 18px; }
.dialog .dialog-btns { display: flex; flex-direction: column; gap: 8px; }
#toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(10px);
  bottom: calc(var(--nav-h) + 8px); z-index: 40;
  max-width: calc(100% - 36px); padding: 12px 20px; border-radius: 22px;
  background: #1A2235; border: 1px solid var(--line); color: var(--cream);
  text-align: center; opacity: 0; pointer-events: none; transition: opacity .4s ease, transform .4s ease;
}
#app:not(.nav-on) #toast { bottom: calc(var(--safe-bottom) + 16px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

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

/* Широкие экраны */
@media (min-width: 700px) {
  html, body { font-size: 19px; }
  #app { max-width: 720px; }
  #screen {
    padding: calc(var(--safe-top) + 28px) calc(var(--safe-left) + 28px) calc(var(--safe-bottom) + 28px) calc(var(--safe-right) + 28px);
  }
  #app.nav-on #screen { padding-bottom: calc(var(--nav-h) + 28px); }
  .screen-title { font-size: 34px; }
  .home-title { font-size: 40px; }
  .now-title { font-size: 25px; }
  .btn { font-size: 19px; }
  .stats { gap: 14px; }
  .stat { padding: 20px 12px; }
  .stat b { font-size: 32px; }
  .stat span { font-size: 17px; }
  .votd-text { font-size: 21px; }
  #nav { width: min(calc(100% - 56px), 520px); }
  .dialog { max-width: 480px; }
}
@media (min-width: 1000px) {
  #app { max-width: 820px; }
}
@media (orientation: landscape) and (max-height: 520px) {
  :root { --nav-h: calc(56px + var(--safe-bottom) + 8px); }
  #screen {
    padding-top: calc(var(--safe-top) + 10px);
    padding-bottom: calc(var(--safe-bottom) + 12px);
  }
  #app.nav-on #screen { padding-bottom: calc(var(--nav-h) + 12px); }
  .screen-title { margin: 4px 0 10px; }
  .home-title { margin: 6px 0 2px; }
  .home-sub { margin-bottom: 10px; }
  #nav { bottom: calc(var(--safe-bottom) + 8px); height: 56px; align-items: center; padding: 4px; }
  #nav a { height: 44px; }
}
