* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: var(--night); overflow: hidden;
  -webkit-font-smoothing: antialiased; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
[hidden] { display: none !important; }
.screen { position: fixed; inset: 0; }

/* ---------- кнопки ---------- */
.btn { min-height: 50px; padding: 0 26px; border-radius: var(--r-pill); font-weight: 650; font-size: 17px;
  transition: transform .12s ease, opacity .2s; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn-light { background: #fff; color: var(--ink); box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.btn-green { background: linear-gradient(180deg, #57c95f, var(--green-dark)); color: #fff; box-shadow: 0 6px 18px rgba(47,154,58,.35); }
.btn-ghost { background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.35); }
.btn-wide { width: 100%; }
.err { color: #ffb4a8; font-size: 14px; margin: 8px 0 0; }
.sheet .err, .view .err { color: #b33b2e; }

/* ---------- вступление ---------- */
.intro { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 24px);
  background: radial-gradient(120% 70% at 50% 0%, var(--night-2), var(--night) 70%); color: #fff; overflow-y: auto; }
.step { display: flex; flex-direction: column; align-items: center; width: 100%; max-width: 380px; }
.gem-xl { width: 64px; height: 118px; margin-bottom: 18px; }
.intro-title { font-size: 26px; letter-spacing: .14em; font-weight: 700; margin: 0 0 10px; }
.intro-h { font-size: 26px; margin: 0 0 8px; font-weight: 700; }
.intro-sub { font-size: 16px; line-height: 1.45; color: rgba(255,255,255,.75); margin: 0 0 26px; }
.step-count { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: rgba(255,255,255,.5); margin: 0 0 6px; }
.frame { position: relative; width: min(64vw, 240px); aspect-ratio: 3/4; border-radius: 20px; overflow: hidden;
  border: 1.5px dashed rgba(255,255,255,.35); margin-bottom: 14px; background: rgba(255,255,255,.04); }
.frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 25%; }
.frame img:not([src]) { display: none; }
.frame.has-img { border-style: solid; border-color: rgba(255,255,255,.6); }
.gem-frame { position: absolute; left: 50%; top: 4%; width: 20px; height: 37px; transform: translateX(-50%); }
.frame:not(.has-img) .gem-frame { display: none; }
.frame-empty { position: absolute; inset: 0; display: grid; place-items: end center; }
.frame-empty svg { width: 70%; fill: rgba(255,255,255,.1); }
.frame.has-img .frame-empty { display: none; }
.frame-busy { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 10px; align-items: center; justify-content: center;
  background: rgba(20,15,10,.55); font-size: 14px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid rgba(255,255,255,.3); border-top-color: #fff; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.tips { list-style: none; padding: 0; margin: 0 0 20px; font-size: 14px; color: rgba(255,255,255,.65); }
.tips li::before { content: "·  "; }
.privacy { font-size: 12px; line-height: 1.4; color: rgba(255,255,255,.5); margin: -8px 0 18px; }
.row-btns { display: flex; gap: 10px; }
.field { width: 100%; min-height: 52px; border-radius: 14px; border: 1px solid rgba(255,255,255,.3); background: rgba(255,255,255,.1);
  color: #fff; font: inherit; font-size: 18px; padding: 0 16px; margin-bottom: 18px; text-align: center; -webkit-user-select: text; user-select: text; }
.field::placeholder { color: rgba(255,255,255,.4); }
.field:focus { outline: 2px solid rgba(255,255,255,.6); }

/* ---------- сцена ---------- */
#game { background: var(--night); }
.backdrop { display: none; }
.stage { position: absolute; inset: 0; overflow: hidden; background: var(--night-2); }
.photo-ph, .photo { position: absolute; inset: 0; width: 100%; height: 100%; }
.photo-ph { background-size: cover; background-position: 50% 25%; filter: blur(18px); transform: scale(1.12); }
.photo { object-fit: cover; object-position: 50% 25%; opacity: 0; transition: opacity .5s ease; }
.photo.ready { opacity: 1; }
.shade-top, .shade-bottom { position: absolute; left: 0; right: 0; pointer-events: none; }
.shade-top { top: 0; height: 22%; background: linear-gradient(rgba(0,0,0,.32), transparent); }
.shade-bottom { bottom: 0; height: 30%; background: linear-gradient(transparent, rgba(0,0,0,.28)); }

/* верхняя полоса: уровень и опыт */
.topbar { position: absolute; top: calc(var(--safe-top) + 10px); left: 12px; right: 12px; display: flex; justify-content: center; }
.lvl-pill { display: flex; align-items: center; gap: 10px; width: min(100%, 330px); padding: 5px 14px 5px 5px;
  background: var(--hud); border-radius: var(--r-pill); box-shadow: var(--hud-shadow); }
.lvl-num { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 750; font-size: 16px;
  background: linear-gradient(180deg, #57c95f, var(--green-dark)); box-shadow: inset 0 -2px 0 rgba(0,0,0,.12); }
.lvl-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.lvl-name { font-size: 13px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xp-track { display: block; height: 7px; border-radius: 4px; background: var(--track); overflow: hidden; }
.xp-fill { display: block; height: 100%; width: 0; border-radius: 4px; background: linear-gradient(90deg, #7fdc77, var(--green)); transition: width .8s cubic-bezier(.2,.8,.2,1); }
.xp-txt { flex: none; font-size: 12px; font-weight: 600; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.gem-hud { position: absolute; left: 50%; top: max(calc(var(--safe-top) + 56px), var(--gem-y, 9%)); width: 36px; height: 66px; transform: translateX(-50%);
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.25)); }
.xp-pop { position: absolute; left: 50%; top: calc(var(--safe-top) + 110px); transform: translateX(-50%); pointer-events: none;
  font-weight: 800; font-size: 22px; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.45); opacity: 0; }
.xp-pop.go { animation: pop 1.4s ease-out forwards; }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, 10px) scale(.8); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.1); }
  70% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -40px) scale(1); } }

/* план дня прямо на главном */
.day-chip { position: absolute; left: 12px; top: calc(var(--safe-top) + 60px); min-height: 34px; padding: 0 12px; border-radius: 999px;
  background: var(--hud); box-shadow: var(--hud-shadow); font-size: 13px; font-weight: 650; z-index: 3; }
.day-chip b { color: var(--green-dark); }
.day-panel { position: absolute; left: 12px; top: calc(var(--safe-top) + 100px); width: min(80vw, 330px); max-height: 54%; overflow-y: auto; z-index: 3;
  background: rgba(255,253,250,.95); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border-radius: 18px; padding: 10px 12px; box-shadow: 0 10px 30px rgba(0,0,0,.25); animation: fade .2s; }
.dp-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.dp-all { display: block; margin: 8px auto 2px; }
.edit-pills { position: absolute; right: 12px; top: calc(var(--safe-top) + 60px); width: 34px; height: 34px; border-radius: 50%; background: var(--hud); box-shadow: var(--hud-shadow); font-size: 16px; z-index: 3; }
.frame-tune { position: absolute; left: 12px; right: 12px; bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px); z-index: 6; background: rgba(255,253,250,.96);
  border-radius: 18px; padding: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.frame-tune p { margin: 0 0 10px; font-size: 13px; color: var(--ink-soft); }
.frame-tune label { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.frame-tune input { flex: 1; accent-color: var(--green); }

/* мысли-облачка */
.thoughts { position: absolute; left: 14px; top: calc(var(--safe-top) + 104px); display: flex; flex-direction: column; gap: 10px; }
.thought { position: relative; width: 50px; height: 46px; border-radius: 50% 50% 46% 54%; background: var(--hud);
  box-shadow: var(--hud-shadow); display: grid; place-items: center; font-size: 24px; transition: transform .15s; }
.th-time { position: absolute; left: 50%; bottom: -7px; transform: translateX(-50%); font-size: 9.5px; font-weight: 750; background: var(--green-dark); color: #fff; padding: 1px 5px; border-radius: 6px; }
.thought-add { font-size: 26px; font-weight: 300; color: var(--green-dark); background: rgba(255,255,255,.75); }
.thought-add::before, .thought-add::after { display: none; }
.thought:active { transform: scale(.93); }
.thought::before, .thought::after { content: ""; position: absolute; border-radius: 50%; background: var(--hud); box-shadow: var(--hud-shadow); }
.thought::before { width: 10px; height: 10px; right: -12px; bottom: 6px; }
.thought::after { width: 6px; height: 6px; right: -20px; bottom: 2px; }

/* кнопки действий */
.pills { position: absolute; bottom: calc(var(--nav-h) + var(--safe-bottom) + 150px); display: flex; flex-direction: column; gap: 10px; width: min(47vw, 210px); }
.pills-left { left: 10px; }
.pills-right { right: 10px; align-items: flex-end; }
.pill { display: flex; align-items: center; gap: 8px; max-width: 100%; min-height: 42px; padding: 0 14px 0 9px;
  background: var(--hud); border-radius: var(--r-pill); box-shadow: var(--hud-shadow); font-size: 14px; font-weight: 650;
  transition: transform .15s, background .2s; animation: pill-in .45s cubic-bezier(.2,.9,.3,1.2) both; }
.pill:active { transform: scale(.95); background: #fff; }
.pill .em { font-size: 19px; line-height: 1; flex: none; }
.pill .tx { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pills-left .pill { animation-name: pill-in-l; }
@keyframes pill-in { from { opacity: 0; transform: translateX(16px); } }
@keyframes pill-in-l { from { opacity: 0; transform: translateX(-16px); } }

/* миниатюра и шкалы */
.mini { position: absolute; left: 12px; bottom: calc(var(--nav-h) + var(--safe-bottom) + 14px); width: 58px; height: 76px; border-radius: 14px;
  overflow: hidden; border: 2px solid #fff; box-shadow: var(--hud-shadow); background: var(--night-2); }
.mini img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 20%; }
.mini-bar { position: absolute; left: 5px; right: 5px; bottom: 5px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.6); overflow: hidden; }
.mini-bar span { display: block; height: 100%; width: 0; background: var(--green); transition: width .8s; }
.needs { position: absolute; right: 12px; bottom: calc(var(--nav-h) + var(--safe-bottom) + 14px); width: 206px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 7px 10px; padding: 9px 11px; border-radius: 16px;
  background: var(--hud-soft); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); box-shadow: var(--hud-shadow); }
.need { min-width: 0; }
.need-k { display: block; font-size: 10px; font-weight: 650; color: var(--ink-soft); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.need-row { display: flex; align-items: center; gap: 5px; }
.need-ic { flex: none; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.bar { flex: 1; height: 7px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 4px; transition: width .8s cubic-bezier(.2,.8,.2,1), background .4s; }
.bar .ok { background: linear-gradient(90deg, #7fdc77, var(--green)); }
.bar .mid { background: linear-gradient(90deg, #f5d36f, var(--amber)); }
.bar .low { background: linear-gradient(90deg, #f09088, var(--rose)); }

/* нижнее меню */
.nav { position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  display: flex; background: rgba(255,255,255,.92); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  box-shadow: 0 -1px 0 rgba(0,0,0,.06); z-index: 5; }
.nav button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 10.5px; font-weight: 600; color: var(--ink-soft); }
.nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav button.on { color: var(--green-dark); }

/* вкладки поверх сцены */
.view { position: absolute; left: 0; right: 0; top: 0; bottom: calc(var(--nav-h) + var(--safe-bottom)); overflow-y: auto; z-index: 4;
  background: var(--cream); padding: calc(var(--safe-top) + 20px) 16px 24px; -webkit-user-select: text; user-select: text; }
.view-h { font-size: 28px; margin: 0 0 6px; }
.view-h3 { font-size: 18px; margin: 22px 0 4px; }
.view-sub { color: var(--ink-soft); font-size: 14px; line-height: 1.45; margin: 0 0 14px; }
.soon { background: #fff; border: 1px solid var(--line); border-radius: var(--r-card); padding: 16px; line-height: 1.5; color: var(--ink-soft); }
.soon b { color: var(--ink); display: block; margin-bottom: 4px; }
.looks { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.look { position: relative; aspect-ratio: 3/4; border-radius: 14px; overflow: hidden; background: var(--line); border: 3px solid transparent; }
.look img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 20%; }
.look.on { border-color: var(--green); }
.look-del { position: absolute; top: 5px; right: 5px; width: 30px; height: 30px; border-radius: 50%; background: rgba(0,0,0,.45); color: #fff; font-size: 18px; line-height: 30px; }
.look-add { display: grid; place-items: center; border: 2px dashed #cbbfb2; background: transparent; color: var(--ink-soft); font-size: 14px; font-weight: 600; text-align: center; padding: 8px; }
.look-add b { display: block; font-size: 30px; font-weight: 400; }
.look-confirm { position: absolute; inset: 0; background: rgba(30,20,15,.75); color: #fff; display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; font-size: 13px; padding: 6px; text-align: center; }
.look-confirm button { min-height: 34px; padding: 0 12px; border-radius: 999px; background: #fff; color: var(--ink); font-weight: 650; font-size: 13px; }
.look-confirm button.yes { background: var(--rose); color: #fff; }
.me-card, .side-card { background: #fff; border: 1px solid var(--line); border-radius: var(--r-card); padding: 14px 16px; }
.big-need { margin-bottom: 12px; }
.big-need .need-k { font-size: 13px; color: var(--ink); margin-bottom: 5px; }
.big-need .bar { height: 10px; border-radius: 5px; }
.big-need .need-ic { width: 26px; height: 26px; font-size: 14px; }
.lvl-big { display: flex; align-items: center; gap: 14px; }
.lvl-big .lvl-num { width: 48px; height: 48px; font-size: 22px; }
.lvl-big .xp-track { height: 9px; margin-top: 6px; }
.lvl-big small { color: var(--ink-soft); font-size: 13px; }

/* карточка действия */
.sheet-bg { position: fixed; inset: 0; background: rgba(20,14,10,.4); z-index: 20; animation: fade .2s; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 520px; margin: 0 auto;
  background: #fffdfa; border-radius: 26px 26px 0 0; padding: 22px 20px calc(var(--safe-bottom) + 20px); text-align: center;
  box-shadow: 0 -10px 40px rgba(0,0,0,.25); animation: up .32s cubic-bezier(.2,.9,.3,1); }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
.sheet-x { position: absolute; right: 12px; top: 10px; width: 40px; height: 40px; font-size: 28px; color: var(--ink-soft); }
.sheet-emoji { font-size: 46px; line-height: 1; margin-bottom: 8px; }
.sheet-title { margin: 0 0 10px; font-size: 22px; }
.chips { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-bottom: 12px; }
.chip { font-size: 13px; font-weight: 650; padding: 5px 11px; border-radius: 999px; background: #f1ebe4; color: var(--ink); }
.chip.xp { background: #e2f5e3; color: var(--green-dark); }
.sheet-desc { font-size: 16px; line-height: 1.45; margin: 0 0 6px; }
.sheet-cond { font-size: 14px; color: var(--ink-soft); margin: 0 0 12px; }
.sheet-cond:empty { display: none; }
.effects { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 6px 0 18px; }
.effect { font-size: 13px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-soft); }

/* новый уровень и уведомления */
.levelup { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(20,14,10,.55); animation: fade .25s; }
.levelup-card { background: #fffdfa; border-radius: 26px; padding: 26px 34px; text-align: center; animation: zoom .4s cubic-bezier(.2,.9,.3,1.3); }
@keyframes zoom { from { transform: scale(.8); opacity: 0; } }
.levelup-k { margin: 0; color: var(--ink-soft); font-size: 15px; }
.levelup-n { margin: 0 0 16px; font-size: 54px; font-weight: 800; color: var(--green-dark); }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-bottom) + 14px); transform: translateX(-50%); z-index: 25;
  background: rgba(30,24,20,.88); color: #fff; padding: 10px 16px; border-radius: 14px; font-size: 14px; max-width: calc(100vw - 32px); text-align: center; animation: fade .2s; }

/* невысокий экран (Safari с панелями): 2 мысли и по 3 кнопки с каждой стороны */
@media (max-height: 760px) and (max-width: 899px) {
  .thought:not(.thought-add):nth-child(n+3) { display: none; }
  .pill:nth-child(n+4) { display: none; }
}

/* ---------- компьютер: персонаж в центре, панели по краям ---------- */
.side { display: none; }
@media (min-width: 900px) {
  #game { display: flex; justify-content: center; align-items: stretch; gap: 24px; padding: 24px; }
  .backdrop { display: block; position: absolute; inset: -40px; background-size: cover; background-position: center; filter: blur(40px) brightness(.55); }
  .stage { position: relative; inset: auto; flex: none; width: min(460px, 40vw); height: calc(100vh - 48px); border-radius: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
  .side { display: block; position: relative; flex: none; width: 280px; max-height: calc(100vh - 48px); overflow-y: auto;
    background: rgba(255,253,250,.92); border-radius: 22px; padding: 18px; -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
  .side-h { margin: 0 0 12px; font-size: 17px; }
  .side-card { margin-bottom: 12px; }
  .side-soon { color: var(--ink-soft); font-size: 14px; }
  .stage .needs { display: none; }
  .stage .pills { bottom: calc(var(--nav-h) + 110px); }
  .cat-h { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); margin: 14px 0 6px; }
  .cat-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 12px; text-align: left; }
  .cat-row:hover { background: #f1ebe4; }
  .cat-row .em { font-size: 20px; }
  .cat-row .tx { flex: 1; font-size: 14px; font-weight: 600; }
  .cat-row .xp { font-size: 12px; color: var(--green-dark); font-weight: 700; }
  .sheet { bottom: 50%; transform: translateY(50%); border-radius: 26px; animation: fade .2s; }
  .view { border-radius: 0; }
}

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