/* Design system: UI UX Pro Max → "Fitness/Gym App": Vibrant & Block-based + Dark Mode (OLED). SPEC 8.5 */

@font-face {
  font-family: "Oswald"; font-style: normal; font-weight: 200 700; font-display: swap;
  src: url("/fonts/oswald-cyrillic-wght-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Oswald"; font-style: normal; font-weight: 200 700; font-display: swap;
  src: url("/fonts/oswald-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Manrope"; font-style: normal; font-weight: 200 800; font-display: swap;
  src: url("/fonts/manrope-cyrillic-wght-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Manrope"; font-style: normal; font-weight: 200 800; font-display: swap;
  src: url("/fonts/manrope-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  /* palette (D2) — contrast verified: text 18.9, muted 7.6–9.6, dark-on-primary 6.4 */
  --bg: #0A0A0B;
  --surface: #161618;
  --surface-2: #232326;
  --text: #F8FAFC;
  --muted: #B4B4BC;
  --border: #2E2E33;
  --primary: #F97316;
  --primary-hover: #FB923C;
  --on-primary: #0F172A;
  --success: #22C55E;
  --danger: #F87171;
  --meme: #A3E635;
  --warn-bg: rgba(250, 204, 21, .12);
  --warn-border: rgba(250, 204, 21, .45);
  --warn-text: #FACC15;
  --ring: #F97316;

  --font-display: "Oswald", "Arial Narrow", system-ui, sans-serif;
  --font-body: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius-lg: 24px;
  --radius: 16px;
  --radius-sm: 12px;
  --gutter: 16px;
  --ease: cubic-bezier(.2, .9, .3, 1);
  color-scheme: dark;
}
/* Telegram light theme: bg/surface/text/muted come from themeParams (telegram.js); brand orange stays */
:root[data-tg="light"] {
  --surface-2: rgba(0, 0, 0, .06);
  --border: rgba(0, 0, 0, .12);
  --warn-bg: #FEF9C3;
  --warn-border: #EAB308;
  --warn-text: #713F12;
  --danger: #B91C1C;
  --meme: #3F6212;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 500 16px/1.5 var(--font-body);
  min-height: 100dvh;
  overflow-x: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
body.locked { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button, summary, [role="button"], select { cursor: pointer; }
button:disabled { cursor: not-allowed; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; letter-spacing: .01em; line-height: 1.1; text-wrap: balance; }

/* D6: visible keyboard focus everywhere */
:focus-visible { outline: 3px solid var(--ring); outline-offset: 3px; border-radius: 6px; }

.icon { width: 20px; height: 20px; flex-shrink: 0; vertical-align: middle; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1120px; margin: 0 auto; padding: 14px var(--gutter);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; flex-shrink: 0;
  background: var(--primary); color: var(--on-primary);
}
.brand-mark .icon { width: 26px; height: 26px; }
.brand-name { margin: 0; font-size: clamp(22px, 6vw, 32px); text-transform: uppercase; }
.brand-name span { color: var(--primary); }
.account { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
  display: grid; place-items: center; background: var(--surface-2); color: var(--muted);
}
.account .name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 700; }

/* ---------- layout (D8) ---------- */
.layout {
  display: grid; gap: 16px; align-items: start;
  max-width: 1120px; margin: 0 auto; padding: 0 var(--gutter) 32px;
}
.stage { display: flex; flex-direction: column; align-items: center; gap: 14px; min-width: 0; }
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
@media (min-width: 1024px) {
  .layout { grid-template-columns: minmax(0, 1fr) 360px; gap: 32px; padding-top: 8px; }
  .side { position: sticky; top: 16px; }
}

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.chips button {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 999px; font-weight: 700; font-size: 15px;
  border: 2px solid var(--border); background: var(--surface); color: var(--text);
  transition: background-color .2s, border-color .2s, color .2s;
}
.chips button .icon { width: 18px; height: 18px; }
.chips button:hover:not(:disabled) { border-color: var(--primary); }
.chips button[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.chips button:disabled { opacity: .5; }

.combo-banner {
  margin: 0; padding: 8px 16px; border-radius: 999px; font-weight: 800;
  background: rgba(163, 230, 53, .14); color: var(--meme); border: 2px solid rgba(163, 230, 53, .4);
}

/* ---------- wheel ---------- */
.wheel-wrap { position: relative; width: 100%; max-width: 520px; aspect-ratio: 1; }
#wheel { width: 100%; height: 100%; display: block; touch-action: manipulation; }
.pointer {
  position: absolute; left: 50%; top: -6px; transform: translateX(-50%); z-index: 2;
  width: 0; height: 0;
  border-left: 17px solid transparent; border-right: 17px solid transparent; border-top: 32px solid var(--text);
  filter: drop-shadow(0 3px 0 var(--bg));
}
.spin-btn {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 27%; aspect-ratio: 1; min-width: 72px; border-radius: 50%;
  border: 5px solid var(--bg); background: var(--primary); color: var(--on-primary);
  font: 700 clamp(15px, 4.2vw, 22px)/1 var(--font-display); text-transform: uppercase; letter-spacing: .04em;
  box-shadow: 0 0 0 3px var(--primary), 0 10px 30px rgba(249, 115, 22, .35);
  transition: transform .15s var(--ease), background-color .2s;
}
.spin-btn:hover:not(:disabled) { background: var(--primary-hover); }
.spin-btn:active:not(:disabled) { transform: translate(-50%, -50%) scale(.95); }
.spin-btn:disabled { background: var(--surface-2); color: var(--muted); box-shadow: 0 0 0 3px var(--border); }
.hint { margin: 0; min-height: 1.5em; color: var(--muted); text-align: center; font-size: 15px; }

/* D7: finish card */
.finish {
  width: 100%; max-width: 520px; display: grid; grid-template-columns: auto 1fr; gap: 12px 14px; align-items: center;
  padding: 18px; border-radius: var(--radius-lg); background: var(--surface); border: 2px solid var(--success);
}
.finish-icon { width: 40px; height: 40px; color: var(--success); }
.finish h2 { margin: 0; font-size: 24px; text-transform: uppercase; }
.finish p { margin: 4px 0 0; color: var(--muted); }
.finish .primary { grid-column: 1 / -1; }

/* ---------- buttons ---------- */
.primary, .secondary, .ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 20px; border-radius: var(--radius); font-weight: 800; font-size: 16px;
  transition: background-color .2s, border-color .2s, transform .15s var(--ease);
}
.primary:active, .secondary:active, .ghost:active { transform: scale(.98); }
.primary { background: var(--primary); color: var(--on-primary); border: 0; }
.primary:hover { background: var(--primary-hover); }
.secondary { background: var(--surface); border: 2px solid var(--border); }
.secondary:hover:not(:disabled) { border-color: var(--primary); }
.ghost { background: transparent; border: 2px solid var(--border); }
.ghost:hover { border-color: var(--muted); }
.danger { color: var(--danger); }
.wide { width: 100%; }
.link-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 4px;
  background: none; border: 0; color: var(--primary); font-weight: 700; font-size: 14px;
}
.link-btn .icon { width: 16px; height: 16px; }
.link-btn:hover:not(:disabled) { color: var(--primary-hover); text-decoration: underline; }
.link-btn:disabled { opacity: .5; }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  border: 0; background: var(--surface-2); color: var(--text); transition: background-color .2s, color .2s;
}
.icon-btn:hover { background: var(--border); }
.icon-btn.danger:hover { color: var(--danger); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- panels ---------- */
.panel { width: 100%; background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel h2 { margin: 0; font-size: 20px; text-transform: uppercase; }
.panel h2 span { color: var(--muted); font-family: var(--font-body); font-size: 15px; font-weight: 700; text-transform: none; }
.progress { height: 10px; margin: 10px 0 12px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--success); transition: width .4s var(--ease); }
.used-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.used-list button {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; max-width: 100%; padding: 0 12px;
  border-radius: 999px; border: 2px dashed var(--border); background: var(--surface-2); font-size: 14px; font-weight: 600;
  transition: border-color .2s;
}
.used-list button:hover:not(:disabled) { border-color: var(--primary); }
.used-list .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: line-through; color: var(--muted); }
.used-list .icon { width: 16px; height: 16px; color: var(--primary); }
.used-list button:disabled { opacity: .5; }

.history { padding-top: 0; padding-bottom: 0; }
.history summary { display: flex; align-items: center; gap: 8px; min-height: 52px; font-weight: 800; list-style: none; }
.history summary::-webkit-details-marker { display: none; }
.history summary::after { content: "+"; margin-left: auto; font-size: 22px; color: var(--muted); }
.history[open] summary::after { content: "–"; }
.history ol { margin: 0; padding-left: 22px; font-size: 14px; }
.history li { padding: 4px 0; }
.history time { color: var(--muted); margin-right: 6px; font-variant-numeric: tabular-nums; }

/* ---------- layers: bottom sheet on phones, modal on wide screens (M4) ---------- */
.layer {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .6);
  animation: fade .2s ease;
}
.sheet {
  width: 100%; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); color: var(--text); border: 2px solid var(--border); border-bottom: 0;
  border-radius: 28px 28px 0 0; padding: 8px 20px calc(20px + env(safe-area-inset-bottom));
  animation: slide-up .3s var(--ease);
}
.sheet.editor { height: 92dvh; display: flex; flex-direction: column; }
.grabber { width: 44px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 12px; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 24px; flex: 1; text-transform: uppercase; }
.save-status { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.save-status .icon { width: 16px; height: 16px; }
.save-status.ok { color: var(--success); }
.save-status.err { color: var(--danger); }
.save-status.busy .icon { animation: spin 1s linear infinite; }
@media (min-width: 768px) {
  .layer { align-items: center; padding: 24px; }
  .sheet { max-width: 480px; border-radius: 28px; border-bottom: 2px solid var(--border); padding-bottom: 20px; }
  .sheet.editor { max-width: 620px; height: min(820px, 90dvh); }
  .grabber { display: none; }
  .sheet { padding-top: 20px; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(48px); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- result card ---------- */
.r-emoji { font-size: 72px; text-align: center; line-height: 1.1; }
.r-title { text-align: center; margin: 8px 0 10px; font-size: clamp(30px, 8vw, 38px); text-transform: uppercase; }
.badges { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em;
  background: var(--surface-2); border: 2px solid var(--border);
}
.badge .icon { width: 16px; height: 16px; }
.badge.normal { color: var(--primary); border-color: rgba(249, 115, 22, .45); }
.badge.meme { color: var(--meme); border-color: rgba(163, 230, 53, .45); }
.stat {
  display: flex; align-items: baseline; justify-content: center; gap: 8px; margin: 16px 0 0;
  padding: 14px; border-radius: var(--radius); background: var(--surface-2);
}
.stat b { font: 700 44px/1 var(--font-display); color: var(--success); }
.stat span { color: var(--muted); font-weight: 700; }
.r-desc { margin: 14px 0 0; text-align: center; font-size: 17px; }
.warning {
  display: flex; gap: 10px; align-items: flex-start; margin: 14px 0 0; padding: 12px 14px;
  border-radius: var(--radius-sm); background: var(--warn-bg); border: 2px solid var(--warn-border); color: var(--warn-text); font-weight: 700;
}
.warning .icon { margin-top: 2px; }
.combo-list { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; }
.combo-list li { display: flex; gap: 12px; align-items: center; padding: 12px 14px; background: var(--surface-2); border-radius: var(--radius-sm); font-weight: 700; }
.combo-list .e { font-size: 28px; }
.combo-list .p { margin-left: auto; color: var(--success); white-space: nowrap; font-family: var(--font-display); font-size: 18px; }
.actions { display: flex; gap: 10px; margin-top: 20px; }
.actions > * { flex: 1; }

/* ---------- editor ---------- */
#editor-body { flex: 1; overflow-y: auto; margin: 0 -20px; padding: 0 20px; }
.sector-list { list-style: none; margin: 0; padding: 0; }
.sector-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); min-height: 60px; }
.sector-row .e { font-size: 26px; width: 34px; text-align: center; flex-shrink: 0; }
.sector-row .info { flex: 1; min-width: 0; }
.sector-row .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.sector-row .meta { font-size: 13px; color: var(--muted); }
.sector-row.off .e, .sector-row.off .info { opacity: .45; }
.switch { position: relative; width: 52px; height: 32px; flex-shrink: 0; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-2); border: 2px solid var(--border); transition: background-color .2s, border-color .2s; }
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--muted); transition: transform .2s var(--ease), background-color .2s;
}
.switch input:checked + span { background: var(--primary); border-color: var(--primary); }
.switch input:checked + span::after { transform: translateX(20px); background: var(--on-primary); }
.switch input:focus-visible + span { outline: 3px solid var(--ring); outline-offset: 3px; }
.editor-actions { display: grid; gap: 10px; padding: 16px 0 4px; }
.section-title { font-size: 18px; text-transform: uppercase; margin: 12px 0 4px; }

.form { display: grid; gap: 14px; padding-bottom: 8px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 14px; font-weight: 700; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 52px; padding: 12px 14px; border-radius: var(--radius-sm);
  border: 2px solid var(--border); background: var(--surface-2); font-size: 16px; /* ≥16px: no iOS zoom */
  transition: border-color .2s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); outline: none; }
.field textarea { min-height: 88px; resize: vertical; }
.field .err { color: var(--danger); font-size: 13px; font-weight: 700; }
.field.invalid input, .field.invalid textarea { border-color: var(--danger); }
.two { display: grid; grid-template-columns: 100px minmax(0, 1fr); gap: 12px; }

.login-widget { min-height: 48px; display: flex; justify-content: center; margin: 16px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 40; max-width: calc(100% - 32px); padding: 14px 18px; border-radius: var(--radius);
  background: var(--text); color: var(--bg); font-weight: 700; box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
  animation: slide-up .25s var(--ease);
}

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