/* ---------------------------------------------------------------------------
   iOS-flavoured dark theme. Deliberately restrained: system font, one accent
   colour, rounded surfaces, hairline separators, no gradients or shadows.
   --------------------------------------------------------------------------- */

:root {
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-hi: #2c2c2e;
  --separator: rgba(84, 84, 88, 0.6);

  --label: #ffffff;
  --label-2: rgba(235, 235, 245, 0.6);
  --label-3: rgba(235, 235, 245, 0.32);

  --accent: #0a84ff;
  --green: #30d158;
  --red: #ff453a;
  --orange: #ff9f0a;

  --radius-card: 16px;
  --radius-inner: 12px;
  --radius-btn: 14px;

  --pad: 16px;
  --tabbar-h: 56px;

  font-synthesis-weight: none;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Author display rules beat the UA's [hidden] { display: none }, so without
   this guard .sheet-backdrop { display: flex } keeps the key sheet on screen
   even with its hidden attribute set — an empty sheet permanently dimming the
   app and eating every tap. */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--label);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
               system-ui, Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

code, pre, .mono {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

/* One icon family for the whole app: 24px grid, outline only, single stroke
   weight, round caps. Colour always inherits from text. */
svg.icon {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- Boot / fatal --------------------------------------------------------- */

.boot {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.fatal-card {
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: 20px;
  text-align: center;
  max-width: 340px;
}

.fatal-title { font-weight: 600; margin-bottom: 6px; }
.fatal-text { color: var(--label-2); font-size: 14px; }

/* --- Layout -------------------------------------------------------------- */

main {
  padding: 8px var(--pad) calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
}

.page-head { padding: 14px 4px 10px; }

h1 {
  font-size: 30px;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin: 0;
}

.page-sub { margin: 4px 0 0; color: var(--label-2); font-size: 14px; }

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--label-3);
  margin: 26px 4px 8px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: var(--pad);
  margin-bottom: 12px;
}

.hint { color: var(--label-2); font-size: 14px; margin: 0 0 12px; }
.hint.small { font-size: 12.5px; margin: 10px 0 0; }
.hint:last-child { margin-bottom: 0; }

/* The plan screen has no subtitle — two cards don't need an introduction,
   and every line above the first card delays the decision. */
.plan-head { padding-top: 6px; padding-bottom: 2px; }
.plan-head h1 { font-size: 26px; }

/* --- Status -------------------------------------------------------------- */

.status-card { padding: var(--pad); }

.status-row { display: flex; align-items: center; gap: 12px; }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--label-3);
  flex: none;
}
.status-dot.is-active {
  background: var(--green);
  animation: pulse 2.4s ease-out infinite;
}
.status-dot.is-inactive { background: var(--red); }
.status-dot.is-soon { background: var(--orange); }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(48, 209, 88, 0.35); }
  70%  { box-shadow: 0 0 0 7px rgba(48, 209, 88, 0); }
  100% { box-shadow: 0 0 0 0 rgba(48, 209, 88, 0); }
}

.status-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 17px;
  font-weight: 600;
}
.status-icon { width: 16px; height: 16px; flex: none; }
.status-meta { color: var(--label-2); font-size: 13.5px; }
.status-card .btn { margin-top: 16px; }

/* --- Stats --------------------------------------------------------------- */

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat-grid .card { margin-bottom: 12px; }

.stat { text-align: left; }
.stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.4px;
  font-variant-numeric: tabular-nums;
}
.stat-label { color: var(--label-3); font-size: 12.5px; margin-top: 3px; }

/* --- Key / value rows ---------------------------------------------------- */

.kv, .limit-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 0.5px solid var(--separator);
  font-size: 15px;
}
.kv:first-child, .limit-row:first-child { padding-top: 0; }
.kv.last, .kv:last-of-type, .limit-row:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
}
.kv span, .limit-row span { color: var(--label-3); font-size: 13.5px; }
.kv b, .limit-row b {
  font-weight: 600;
  color: var(--label);
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  font-size: 14px;
}

.limits-card { margin-top: 12px; }

/* --- Lists --------------------------------------------------------------- */

.list .row {
  padding: 12px 0;
  border-bottom: 0.5px solid var(--separator);
}
.list .row:first-child { padding-top: 0; }
.list .row:last-child { border-bottom: none; padding-bottom: 0; }

.row-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
.row-title { font-size: 15px; font-weight: 600; color: var(--label); }
.row-meta {
  color: var(--label-2);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.row-sub { color: var(--label-3); font-size: 12.5px; margin-top: 2px; }

.model-id {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  color: var(--label-3);
  margin-top: 3px;
}

/* Stars money: one filled glyph at one saturation everywhere (price, pay
   button, per-day caption) — the emoji varied with its background. */
.star {
  width: 1em;
  height: 1em;
  fill: #ffd60a;
  stroke: none;
  vertical-align: -0.12em;
}

.card-divider {
  border: none;
  border-top: 0.5px solid var(--separator);
  margin: 14px 0;
}

.bar {
  height: 4px;
  background: var(--surface-hi);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transform-origin: left;
  animation: fill-x 0.55s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}
@keyframes fill-x { from { transform: scaleX(0); } }

/* --- Connection fields ---------------------------------------------------- */

/* The two values a developer actually needs, each with its own action —
   the code example is secondary and lives folded below. */
.conn-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.conn-main { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.conn-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--label-3);
}
.conn-value {
  font-size: 13.5px;
  color: var(--label);
  word-break: break-all;
}

/* --- Folded sections ------------------------------------------------------ */

.fold { margin-bottom: 12px; }
.fold > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: 14px var(--pad);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary:active { opacity: 0.7; }
.chev {
  color: var(--label-3);
  font-size: 17px;
  line-height: 1;
  transition: transform 0.18s cubic-bezier(0.22, 0.61, 0.36, 1);
}
.fold[open] > summary .chev { transform: rotate(90deg); }
.fold[open] > summary { margin-bottom: 8px; }
/* The limits card carries its own top margin for the main-screen layout;
   inside a fold the summary's margin already provides the rhythm. */
.fold .limits-card { margin-top: 0; }

/* --- Code ---------------------------------------------------------------- */

.code-block {
  background: #0e0e10;
  border-radius: var(--radius-inner);
  overflow: hidden;
}

/* The header owns the copy button, so it visibly belongs to the whole
   fragment rather than hovering over the first line of code. */
.code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 7px 8px 7px 14px;
  border-bottom: 0.5px solid rgba(84, 84, 88, 0.35);
}
.code-lang {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--label-3);
}

pre {
  margin: 0;
  padding: 13px 14px;
  font-size: 12.5px;
  line-height: 1.55;
  color: #e6e6ea;
  overflow-x: auto;
  white-space: pre;
  display: block;
}

/* Horizontal scroll affordance: a soft edge instead of a line cut off at a
   quote mark with no explanation. */
.code-body { position: relative; }
.code-fade {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 30px;
  background: linear-gradient(to left, #0e0e10 55%, rgba(14, 14, 16, 0));
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}
.code-body.is-scrollable .code-fade { opacity: 1; }

/* A hairline scrollbar reinforces the fade — otherwise the clipped line reads
   as a rendering bug rather than scrollable overflow. */
pre::-webkit-scrollbar { height: 3px; }
pre::-webkit-scrollbar-thumb { background: var(--surface-hi); border-radius: 2px; }

.tok-k { color: #bf7aff; }  /* keywords */
.tok-s { color: #ff8095; }  /* strings  */

.copy-btn {
  border: none;
  background: var(--surface-hi);
  color: var(--label);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 11px;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.12s ease;
}
.copy-btn:active { opacity: 0.6; transform: scale(0.97); }

/* --- Buttons ------------------------------------------------------------- */

.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: var(--radius-btn);
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.12s ease;
}
.btn:active { opacity: 0.62; transform: scale(0.985); }
.btn[disabled] { opacity: 0.4; cursor: default; transform: none; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-danger  { background: rgba(255, 69, 58, 0.16); color: var(--red); }
.btn-danger-solid { background: var(--red); color: #fff; }
.btn-ghost   { background: transparent; color: var(--label-2); font-weight: 500; }
.btn + .btn  { margin-top: 8px; }

/* --- Chart --------------------------------------------------------------- */

.chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 108px;
}

.chart .col {
  flex: 1 1 0;
  min-width: 0;
  background: var(--surface-hi);
  border-radius: 3px 3px 2px 2px;
  position: relative;
  min-height: 3px;
  transform-origin: bottom;
  animation: grow 0.45s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}
@keyframes grow { from { transform: scaleY(0); } }
.chart .col.has-value { background: var(--accent); }

.chart-empty,
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  color: var(--label-3);
  font-size: 13.5px;
  text-align: center;
  padding: 30px 0;
}
.chart-empty svg.icon, .empty .empty-icon svg {
  width: 34px;
  height: 34px;
  opacity: 0.55;
}

/* --- Plans --------------------------------------------------------------- */

.plan-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: var(--pad);
  /* Generous gap between plans: on a fast scroll two stacked cards with pay
     buttons must not read as one column. */
  margin-bottom: 20px;
}

/* The recommended plan is unmistakable without a floating sticker: a tinted
   fill plus accent border carry the weight; the small tag rides on the title
   itself so nothing hovers over the card's edge. */
.plan-card.is-featured {
  background: rgba(10, 132, 255, 0.09);
  border: 1px solid rgba(10, 132, 255, 0.45);
}

.plan-flag {
  display: inline-block;
  vertical-align: 2px;
  margin-left: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 2.5px 8px;
  border-radius: 999px;
}

.plan-name { font-size: 17px; font-weight: 600; }
/* Extra air before the pay button — it is the card's primary action and
   needs separation from the description above. */
.plan-desc { color: var(--label-2); font-size: 13.5px; margin: 6px 0 14px; }
.plan-used { color: var(--label-3); font-size: 12.5px; margin: 10px 0 0; }

/* --- Tab bar ------------------------------------------------------------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: rgba(22, 22, 24, 0.86);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
  z-index: 40;
}

.tab {
  flex: 1;
  border: none;
  background: none;
  color: var(--label-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}
.tab.is-active { color: var(--accent); }
.tab-icon {
  line-height: 1;
  transition: transform 0.18s cubic-bezier(0.22, 0.61, 0.36, 1);
}
.tab-icon svg { width: 22px; height: 22px; display: block; }
.tab.is-active .tab-icon { transform: translateY(-1px) scale(1.1); }
.tab-label { font-size: 10.5px; font-weight: 500; }

/* --- One-time key sheet -------------------------------------------------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  z-index: 60;
  animation: fade-in 0.22s ease;
}
@keyframes fade-in { from { opacity: 0; } }

.sheet {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  background: #1c1c1e;
  border-radius: 22px 22px 0 0;
  padding: 10px var(--pad) calc(20px + env(safe-area-inset-bottom));
  animation: rise 0.26s cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes rise { from { transform: translateY(14%); } to { transform: none; } }

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--label-3);
  margin: 0 auto 14px;
}

.sheet-title { font-size: 20px; font-weight: 700; margin: 0 0 6px; }
.sheet-title.danger { color: var(--red); }

.sheet-warn {
  color: var(--orange);
  font-size: 13.5px;
  margin: 0 0 14px;
}

.key-box {
  background: #0e0e10;
  border-radius: var(--radius-inner);
  padding: 14px;
  margin-bottom: 14px;
}

.key-box code {
  font-size: 12.5px;
  line-height: 1.6;
  color: #e6e6ea;
  word-break: break-all;
}

/* The prefix-only view on the Ключ tab. Deliberately NOT the dark filled box
   used for copyable fragments like the code snippet — that pattern promises an
   action this value can never have, since only its hash survives the reveal.
   Plain centred type says "this is a fact", not "tap to copy". */
.key-view {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.key-view svg.icon { width: 15px; height: 15px; color: var(--label-3); flex: none; }
.key-view code { font-size: 16px; letter-spacing: 0.5px; color: var(--label); }
.center { text-align: center; }

/* --- Toast --------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(58, 58, 60, 0.96);
  color: #fff;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 12px;
  z-index: 80;
  max-width: 84%;
  text-align: center;
  animation: toast-in 0.2s cubic-bezier(0.22, 0.61, 0.36, 1);
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* --- Screen transitions --------------------------------------------------- */

/* Tab screens are toggled via the hidden attribute; display:none → block
   restarts these animations on every switch. Children stagger in just behind
   the page heading — one motion idea, small distances, nothing bouncy. */
.screen:not([hidden]) > * {
  animation: screen-in 0.32s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}
.screen:not([hidden]) > *:nth-child(2) { animation-delay: 30ms; }
.screen:not([hidden]) > *:nth-child(3) { animation-delay: 60ms; }
.screen:not([hidden]) > *:nth-child(4) { animation-delay: 90ms; }
.screen:not([hidden]) > *:nth-child(5) { animation-delay: 120ms; }
.screen:not([hidden]) > *:nth-child(n + 6) { animation-delay: 150ms; }

@keyframes screen-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* Sheet dismissal mirrors its rise instead of vanishing mid-tap. */
.sheet-backdrop.is-closing { animation: fade-out 0.19s ease both; }
.sheet-backdrop.is-closing .sheet { animation: sink 0.19s ease both; }
@keyframes fade-out { to { opacity: 0; } }
@keyframes sink { to { transform: translateY(100%); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}
