html {
  /* Не даём iOS самовольно увеличивать шрифты при смене ориентации */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

:root {
  --ink: #14161a;
  --ink-2: #3d424c;
  --muted: #8b91a0;
  --line: rgba(19, 22, 34, 0.07);
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #ffffff;
  --fill: #eceef2;
  --accent: #e2492b;
  --radius: 22px;
  --radius-sm: 14px;
  --shadow: 0 10px 30px rgba(23, 25, 45, 0.07);
  --shadow-lg: 0 18px 44px rgba(23, 25, 45, 0.1);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: #f4f5f9;
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  padding: 12px 12px calc(32px + env(safe-area-inset-bottom));
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

/* Пастельная сетка-градиент как фон всей страницы */
.mesh {
  position: fixed;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(38% 42% at 12% 8%, #fbd9e6 0%, rgba(251, 217, 230, 0) 70%),
    radial-gradient(34% 40% at 78% 4%, #e3e0fa 0%, rgba(227, 224, 250, 0) 72%),
    radial-gradient(46% 46% at 88% 62%, #d9e8fb 0%, rgba(217, 232, 251, 0) 70%),
    radial-gradient(42% 44% at 8% 78%, #f6e2f1 0%, rgba(246, 226, 241, 0) 72%),
    radial-gradient(50% 50% at 50% 42%, #eef0fb 0%, rgba(238, 240, 251, 0) 78%);
  filter: saturate(1.05);
}

.bar, main { position: relative; z-index: 1; max-width: 640px; margin: 0 auto; }

/* --- Шапка --- */

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: var(--radius);
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.logo {
  flex: none;
  display: block;
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 3px 7px rgba(210, 55, 26, 0.28));
}

h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.015em;
  white-space: nowrap;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
  padding: 4px;
  border-radius: 999px;
  background: rgba(236, 238, 242, 0.9);
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.22s ease, color 0.22s ease, box-shadow 0.22s ease;
}

.tab.is-active {
  background: var(--ink);
  color: #fff;
  box-shadow: 0 6px 16px rgba(20, 22, 26, 0.28);
}

.tab-icon { font-size: 14px; line-height: 1; }
.tab:not(.is-active) .tab-icon { filter: grayscale(0.35); }

.badge {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(19, 22, 34, 0.08);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}
.tab.is-active .badge { background: rgba(255, 255, 255, 0.22); }

.me {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--fill);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.me:empty { display: none; }

@media (max-width: 460px) {
  .bar { flex-wrap: wrap; }
  .tabs { order: 3; width: 100%; margin-left: 0; }
  .tab { flex: 1; justify-content: center; }
  .me { margin-left: auto; }
}

/* --- Переключатель категорий --- */

.segmented {
  display: flex;
  gap: 3px;
  max-width: 640px;
  margin: 14px auto 0;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  box-shadow: var(--shadow);
}

.seg {
  flex: 1;
  padding: 10px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.22s ease, color 0.22s ease, box-shadow 0.22s ease;
}

.seg.is-active {
  background: var(--ink);
  color: #fff;
  box-shadow: 0 6px 16px rgba(20, 22, 26, 0.26);
}

.form-note { margin: -4px 0 0; color: var(--muted); font-size: 13px; }

/* --- Панели --- */

.panel { display: none; padding-top: 18px; }
.panel.is-active { display: block; animation: rise 0.28s ease; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.card {
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius);
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  box-shadow: var(--shadow);
}

/* --- Рулетка --- */

.wheel-stage { display: flex; justify-content: center; padding-top: 6px; }

.wheel-wrap { position: relative; width: min(330px, 84vw); aspect-ratio: 1; }

/* Кольцо и тень живут на неподвижной подложке: если повесить их на само
   колесо, тень крутится вместе с ним и мерцает. */
.wheel-wrap::before {
  content: "";
  position: absolute;
  inset: -9px;
  z-index: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: 0 20px 46px rgba(23, 25, 45, 0.13), 0 3px 10px rgba(23, 25, 45, 0.06);
}

.wheel {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--surface-solid);
  transition: transform 4.6s cubic-bezier(0.15, 0.9, 0.2, 1);
  will-change: transform;
  /* backface + translateZ убирают дрожание краёв при вращении на iOS */
  transform-origin: 50% 50%;
  backface-visibility: hidden;
}

.pointer {
  position: absolute;
  top: -3px;
  left: 50%;
  z-index: 3;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 20px solid var(--ink);
  filter: drop-shadow(0 3px 5px rgba(23, 25, 45, 0.28));
}

.spin {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  width: 29%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 5px solid #fff;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(20, 22, 26, 0.3);
  transition: transform 0.16s ease;
}
.spin:active { transform: translate(-50%, -50%) scale(0.93); }
.spin:disabled { opacity: 0.55; cursor: default; }

.hint {
  margin: 20px auto 0;
  max-width: 330px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.result { margin-top: 20px; overflow: hidden; animation: rise 0.3s ease; }

.result-head { padding: 18px 20px 16px; border-bottom: 1px solid var(--line); }

.result-kicker {
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.result-head h2 { margin: 7px 0 4px; font-size: 25px; font-weight: 700; letter-spacing: -0.025em; }
.result-meta { margin: 0; color: var(--muted); font-size: 13px; }

.result-body { padding: 16px 20px 20px; }
.result-body h3 { margin: 0 0 10px; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; }

.ingredients { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; }

.ingredients li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  background: rgba(236, 238, 242, 0.75);
  cursor: pointer;
  transition: opacity 0.2s ease, background 0.2s ease;
}

.ingredients li::before {
  content: "";
  flex: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid rgba(19, 22, 34, 0.22);
  border-radius: 6px;
  background: #fff;
}

.ingredients li.done { opacity: 0.45; text-decoration: line-through; }
.ingredients li.done::before { border-color: var(--ink); background: var(--ink); }
.ingredients .none { color: var(--muted); cursor: default; }
.ingredients .none::before { display: none; }

.result-link {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 13px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(20, 22, 26, 0.22);
  transition: transform 0.15s ease;
}
.result-link:active { transform: scale(0.985); }

/* --- Форма и список --- */

.form { display: grid; gap: 14px; padding: 18px; }

.field { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
.field em { font-style: normal; opacity: 0.8; }

input[type="text"], input[type="url"], textarea {
  width: 100%;
  padding: 13px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--fill);
  color: var(--ink);
  font: inherit;
  /* Ровно 16px: при меньшем размере Safari на iOS зумит страницу,
     как только поле получает фокус, и обратно уже не отъезжает. */
  font-size: 16px;
  resize: vertical;
  transition: background 0.2s ease, border-color 0.2s ease;
}

input[type="text"], input[type="url"] { border-radius: 999px; }

input[type="text"]::placeholder, input[type="url"]::placeholder, textarea::placeholder { color: #a3a8b5; }

input[type="text"]:focus, input[type="url"]:focus, textarea:focus {
  outline: none;
  border-color: rgba(19, 22, 34, 0.16);
  background: #fff;
}

.form-actions { display: flex; gap: 8px; }

.btn {
  flex: 1;
  padding: 13px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease;
}
.btn:active { transform: scale(0.985); }

.btn-primary { background: var(--ink); color: #fff; box-shadow: 0 8px 20px rgba(20, 22, 26, 0.22); }
.btn-ghost { background: var(--fill); color: var(--ink-2); }

.recipes { display: grid; gap: 10px; margin-top: 12px; }

.recipe {
  padding: 15px 17px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

.recipe-top { display: flex; align-items: center; gap: 10px; }
.dot {
  flex: none;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 9px;
  font-size: 14px;
  line-height: 1;
}
.recipe-name { flex: 1; min-width: 0; font-weight: 600; }

.link-btn {
  flex: none;
  padding: 6px 11px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.link-btn:active { transform: scale(0.94); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 10px;
  background: var(--fill);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s ease;
}
.icon-btn:active { background: #dfe2e8; }

.recipe-ings { margin: 9px 0 0; color: var(--ink-2); font-size: 13px; line-height: 1.5; }
.recipe-stat { margin: 7px 0 0; color: var(--muted); font-size: 12px; }

.empty { padding: 28px 0; color: var(--muted); text-align: center; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 10;
  transform: translateX(-50%);
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  animation: rise 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
  .wheel { transition-duration: 0.8s; }
  .panel.is-active, .result, .toast { animation: none; }
}
