:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --text: #1b2421;
  --muted: #5e6a65;
  --line: #e5e5df;
  --soft: #eef3f1;
  --brand: #0f6e62;
  --brand-dark: #0b574e;
  --danger: #b4321f;
  --radius: 10px;
  --font: "Manrope", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 500 15px/1.5 var(--font); display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
h1 { font-size: 22px; font-weight: 700; margin: 0; }

.top { height: 60px; flex: none; display: flex; align-items: center; gap: 28px; padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.mark { width: 24px; height: 24px; background: url(/icon.svg) center / contain no-repeat; }
.nav { display: flex; gap: 4px; }
.nav-btn { background: none; border: 0; padding: 8px 14px; border-radius: 8px; color: var(--muted); font-weight: 600; min-height: 40px; transition: background .15s, color .15s; }
.nav-btn:hover { background: var(--soft); color: var(--text); }
.nav-btn.on { background: var(--soft); color: var(--brand-dark); }
.badge { background: var(--brand); color: #fff; font-size: 12px; border-radius: 10px; padding: 1px 7px; margin-left: 4px; }

.studio { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(380px, 460px) 1fr; }
.panel { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; gap: 2px; padding: 10px 12px 0; border-bottom: 1px solid var(--line); flex: none; }
.tab { flex: 1; background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 4px; color: var(--muted); font-weight: 600; min-height: 44px; transition: color .15s; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--brand-dark); border-bottom-color: var(--brand); }
.tab-body { flex: 1; overflow-y: auto; padding: 18px 20px 28px; display: flex; flex-direction: column; gap: 22px; }

.group { display: flex; flex-direction: column; gap: 10px; }
.group-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 0; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label, .row-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.input, .select, textarea { width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; min-height: 42px; transition: border-color .15s; }
.input:hover, .select:hover, textarea:hover { border-color: #c9cdc8; }
textarea { resize: vertical; }
textarea.arabic { font-family: "Amiri", serif; font-size: 26px; line-height: 1.6; direction: rtl; text-align: right; }

.slider { display: grid; grid-template-columns: 1fr 60px; gap: 2px 10px; align-items: center; }
.slider label { grid-column: 1 / 2; font-size: 13px; font-weight: 600; color: var(--muted); }
.slider output { grid-column: 2; grid-row: 1; text-align: right; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.slider input { grid-column: 1 / 3; }
input[type=range] { accent-color: var(--brand); width: 100%; height: 26px; margin: 0; cursor: pointer; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 18px; padding: 6px 12px; font-size: 13px; font-weight: 600; min-height: 36px; transition: border-color .15s, background .15s; }
.chip:hover { border-color: var(--brand); }
.chip.on { background: var(--soft); border-color: var(--brand); color: var(--brand-dark); }

.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; font-size: 13px; font-weight: 700; color: var(--muted); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.total { background: var(--soft); border-radius: var(--radius); padding: 12px 14px; display: flex; justify-content: space-between; font-weight: 600; }
.total b { font-weight: 800; font-variant-numeric: tabular-nums; }

.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumb { position: relative; aspect-ratio: 9 / 13; padding: 0; border: 2px solid transparent; border-radius: 9px; overflow: hidden; background: #dfe3e0; transition: border-color .15s; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb:hover { border-color: #b5c9c3; }
.thumb.on { border-color: var(--brand); }
.thumb .cap { position: absolute; inset: auto 0 0 0; padding: 12px 6px 5px; color: #fff; font-size: 12px; font-weight: 600; text-align: left; background: linear-gradient(transparent, rgba(0,0,0,.65)); }
.upload-tile { display: flex; flex-direction: column; gap: 4px; align-items: center; justify-content: center; color: var(--muted); background: var(--surface); border: 1.5px dashed #c5cbc6; font-size: 13px; font-weight: 600; }
.upload-tile:hover { color: var(--brand-dark); border-color: var(--brand); }

.tracks { display: flex; flex-direction: column; gap: 4px; }
.track { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px 5px 5px; min-height: 48px; transition: border-color .15s, background .15s; }
.track.on { border-color: var(--brand); background: var(--soft); }
.track { background-image: linear-gradient(var(--brand), var(--brand)); background-repeat: no-repeat; background-position: left bottom; background-size: var(--played, 0%) 3px; }
.sample-btn svg { width: 18px; height: 18px; }
.sample-btn.playing { background: var(--brand); color: #fff; border-radius: 50%; }
.sample-btn.playing:hover { background: var(--brand-dark); color: #fff; }
.track .pick { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 4px; min-height: 36px; font-weight: 600; }
.track .pick small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upload-line { display: flex; align-items: center; justify-content: center; gap: 6px; background: none; border: 1.5px dashed #c5cbc6; border-radius: 8px; padding: 9px; color: var(--muted); font-weight: 600; min-height: 44px; }
.upload-line:hover { color: var(--brand-dark); border-color: var(--brand); }

.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.theme { border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: 0 0 7px; overflow: hidden; font-size: 13px; font-weight: 600; transition: border-color .15s; }
.theme:hover { border-color: var(--brand); }
.theme i { display: block; height: 42px; margin-bottom: 6px; }
.looks { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.looks.two-col { grid-template-columns: repeat(2, 1fr); }
.look { display: flex; flex-direction: column; align-items: stretch; gap: 5px; padding: 0 0 7px; text-align: center; background: var(--surface); border: 2px solid var(--line); border-radius: 9px; overflow: hidden; font-size: 12px; font-weight: 600; line-height: 1.25; transition: border-color .15s; }
.look:hover { border-color: #b5c9c3; }
.look.on { border-color: var(--brand); color: var(--brand-dark); }
.look-sample { width: 100%; height: 58px; display: grid; place-items: center; background: linear-gradient(135deg, #2b3a4a, #4a3a3e); color: #fff; font-size: 30px; line-height: 1.3; }
.look-sample.font { font-size: 25px; white-space: nowrap; overflow: hidden; }
.colors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.color { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
.color input { width: 100%; height: 40px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; }
.switch { display: flex; align-items: center; justify-content: space-between; min-height: 40px; font-weight: 600; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--brand); cursor: pointer; }

.icon-btn { width: 40px; height: 40px; flex: none; display: grid; place-items: center; background: none; border: 0; border-radius: 8px; color: var(--muted); transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--soft); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); background: #fbeeeb; }
.icon-btn svg, .primary svg, .secondary svg, .upload-tile svg, .upload-line svg { width: 20px; height: 20px; }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }

.stage { min-width: 0; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 16px 20px; }
.screen-wrap { flex: 1; min-height: 0; width: 100%; display: flex; justify-content: center; align-items: center; }
#screen { display: block; max-width: 100%; max-height: 100%; border-radius: 14px; background: #101820; box-shadow: 0 8px 26px rgba(20,30,28,.18); cursor: pointer; }
.player, .create { width: min(560px, 100%); display: flex; align-items: center; gap: 10px; flex: none; }
.player .play { background: var(--brand); color: #fff; border-radius: 50%; }
.player .play:hover { background: var(--brand-dark); color: #fff; }
.time { font-size: 13px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.title-input { flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 0 12px; height: 46px; }
.primary, .secondary { display: inline-flex; align-items: center; justify-content: center; gap: 7px; border-radius: 9px; padding: 0 18px; min-height: 46px; font-weight: 700; transition: background .15s, border-color .15s; text-decoration: none; }
.primary { background: var(--brand); color: #fff; border: 0; white-space: nowrap; }
.primary:hover { background: var(--brand-dark); }
.primary:disabled { opacity: .6; cursor: progress; }
.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.secondary:hover { border-color: var(--brand); }

.videos { flex: 1; overflow-y: auto; padding: 24px; }
.videos-head { max-width: 1200px; margin: 0 auto 18px; display: flex; align-items: center; justify-content: space-between; }
.link-btn { background: none; border: 0; color: var(--muted); font-weight: 600; min-height: 40px; padding: 0 8px; border-radius: 8px; }
.link-btn:hover { background: var(--soft); color: var(--text); }
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.login .brand { margin-bottom: 4px; display: flex; }
.login .input { font-size: 16px; }
.login-error { color: var(--danger); font-size: 14px; margin: 0; }
.grid { max-width: 1200px; margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.video { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.video-cover { position: relative; aspect-ratio: 9 / 13; background: #18222a; border: 0; padding: 0; display: block; width: 100%; color: #fff; }
.video-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-state { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 10px; align-items: center; justify-content: center; padding: 16px; text-align: center; font-weight: 600; font-size: 14px; }
.bar { width: 100%; height: 6px; border-radius: 3px; background: rgba(255,255,255,.2); overflow: hidden; }
.bar i { display: block; height: 100%; background: #5fd3a8; transition: width .4s; }
.video-meta { padding: 10px 12px 4px; }
.video-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.video-sub { font-size: 13px; color: var(--muted); }
.video-actions { display: flex; padding: 2px 6px 6px; }
.empty { text-align: center; color: var(--muted); padding: 60px 0; }

.dialog { border: 0; border-radius: 14px; padding: 0; width: min(920px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: hidden; }
.dialog::backdrop { background: rgba(15,22,20,.6); }
.dialog-in { display: grid; grid-template-columns: minmax(0, 1fr) 300px; height: min(calc(100dvh - 32px), 820px); }
.dialog-actions { display: flex; flex-direction: column; gap: 8px; }
.dialog.confirm { width: min(400px, calc(100vw - 32px)); }
.confirm-in { padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.confirm-in h2 { margin: 0; font-size: 18px; }
.confirm-in p { margin: 0 0 8px; color: var(--muted); }
.confirm-in .dialog-actions { flex-direction: row; justify-content: flex-end; }
.primary.danger { background: var(--danger); }
.primary.danger:hover { background: #952817; }

.vp { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #000; color: #fff; outline: 0; }
.vp-stage { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden; }
.vp video { display: block; position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; cursor: pointer; }
.vp-big { position: relative; width: 68px; height: 68px; display: grid; place-items: center; border-radius: 50%; background: rgba(0,0,0,.55); cursor: pointer; }
.vp-big svg { width: 28px; height: 28px; margin-left: 3px; }
.vp-bar { flex: none; display: flex; align-items: center; gap: 2px; padding: 4px 6px; background: #0d1215; }
.vp-bar .icon-btn { color: #fff; }
.vp-bar .icon-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.vp-bar input[type=range] { flex: 1; min-width: 0; accent-color: #5fd3a8; margin: 0 6px; }
.vp-time { font-size: 12px; font-weight: 600; color: rgba(255,255,255,.8); font-variant-numeric: tabular-nums; white-space: nowrap; }
.vp:fullscreen .vp-stage { height: 100%; }
.dialog-side { min-width: 0; padding: 18px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.dialog-side h2 { margin: 0 34px 0 0; font-size: 18px; }
.attrib { background: var(--soft); border-radius: 8px; padding: 10px; font-size: 13px; word-break: break-word; }
.close { position: absolute; right: 8px; top: 8px; }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--text); color: #fff; padding: 11px 16px; border-radius: 9px; font-weight: 600; z-index: 20; max-width: calc(100vw - 32px); }

.file-picker { position: fixed; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.bottom-nav, .mobile-only { display: none; }

@media (max-width: 900px) {
  /* экран приложения: сверху полоса действий, дальше предпросмотр, панель и нижнее меню */
  html, body { height: 100dvh; overflow: hidden; overscroll-behavior: none; }
  body { font-size: 15px; -webkit-tap-highlight-color: transparent; }
  .mobile-only { display: grid; }
  .wide-only { display: none; }

  .top { height: auto; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; }
  .top .brand, .nav { display: none; }
  body[data-view="videos"] .top { display: none; }
  .create { width: 100%; gap: 8px; flex-wrap: nowrap; }
  .title-input { height: 42px; padding: 0 12px; background: var(--bg); border-color: transparent; border-radius: 10px; font-size: 16px; font-weight: 600; }
  .create .primary { min-height: 42px; padding: 0 16px; border-radius: 10px; font-size: 15px; }

  .studio { display: flex; flex-direction: column; }
  .stage { order: -1; flex: none; gap: 6px; padding: 10px 12px 4px; }
  .screen-wrap { flex: none; height: 33dvh; }
  #screen { border-radius: 10px; box-shadow: 0 4px 14px rgba(20,30,28,.16); }
  .player { width: 100%; gap: 4px; }
  .player .play { width: 40px; height: 40px; margin-right: 6px; }
  .player .icon-btn svg { width: 19px; height: 19px; }
  .player .play svg { width: 16px; height: 16px; }
  .time { font-size: 12px; margin-left: 6px; }

  .panel { flex: 1; min-height: 0; border-right: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; box-shadow: 0 -2px 10px rgba(20,30,28,.05); }
  .tabs { display: none; }
  .tab-body { padding: 14px 14px 20px; gap: 18px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }

  .segment { position: sticky; top: -14px; z-index: 2; display: flex; gap: 4px; flex: none; margin: -14px -14px 0; padding: 10px 14px 8px; background: var(--surface); }
  .segment-btn { flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: var(--bg); color: var(--muted); font-size: 14px; font-weight: 700; }
  .segment-btn[aria-selected="true"] { background: var(--soft); color: var(--brand-dark); box-shadow: inset 0 0 0 1.5px var(--brand); }

  .group { gap: 8px; }
  .group-title { font-size: 12px; letter-spacing: .01em; }
  .field > label, .slider label, .color { font-size: 13px; }
  .input, .select, textarea { font-size: 16px; min-height: 44px; } /* меньше 16px iOS приближает страницу при вводе */
  textarea.arabic { font-size: 24px; line-height: 1.5; }
  input[type=range] { height: 32px; }
  .chip { min-height: 40px; padding: 7px 13px; font-size: 14px; }
  .scroll-row { flex-wrap: nowrap; overflow-x: auto; margin: 0 -14px; padding: 0 14px; scrollbar-width: none; }
  .scroll-row::-webkit-scrollbar { display: none; }
  .scroll-row .chip { flex: none; }
  .card { padding: 10px; gap: 8px; }
  .gallery { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .thumb { aspect-ratio: 3 / 4; border-radius: 8px; }
  .thumb .cap { display: none; }
  .upload-tile { font-size: 12px; text-align: center; }
  .track { min-height: 52px; }
  .track .pick { font-size: 15px; }
  .looks { gap: 6px; }
  .look-sample { height: 52px; font-size: 26px; }
  .look-sample.font { font-size: 23px; }
  .look { font-size: 12px; padding-bottom: 6px; }
  .themes { gap: 6px; }

  .bottom-nav { display: flex; flex: none; z-index: 6; background: var(--surface); border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .bottom-item { position: relative; flex: 1; min-width: 0; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: none; border: 0; color: var(--muted); font-size: 11px; font-weight: 600; line-height: 1.2; }
  .bottom-icon { display: grid; place-items: center; width: 52px; height: 28px; border-radius: 14px; transition: background .15s; }
  .bottom-icon svg { width: 21px; height: 21px; }
  .bottom-item.on { color: var(--brand-dark); font-weight: 700; }
  .bottom-item.on .bottom-icon { background: var(--soft); }
  .bottom-badge { position: absolute; top: 2px; left: calc(50% + 8px); min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--brand); color: #fff; font-size: 11px; line-height: 17px; text-align: center; }

  .preview-full .panel, .preview-full .bottom-nav { display: none; }
  .preview-full .studio { background: var(--bg); }
  .preview-full .stage { flex: 1; min-height: 0; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .preview-full .screen-wrap { flex: 1; height: auto; }
  .typing .bottom-nav { display: none; }
  .typing .screen-wrap { height: 20dvh; }

  .videos { min-height: 0; padding: calc(14px + env(safe-area-inset-top)) 14px 16px; overscroll-behavior: contain; }
  .videos-head { margin-bottom: 12px; }
  .videos-head h1 { font-size: 20px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .video-meta { padding: 8px 10px 2px; }
  .video-title { font-size: 14px; }
  .video-actions { justify-content: space-between; padding: 0 4px 4px; }

  .dialog { width: 100%; max-width: none; height: 90dvh; max-height: 90dvh; margin: auto 0 0; border-radius: 18px 18px 0 0; transition: transform .2s ease-out; }
  .dialog[open] { display: flex; flex-direction: column; animation: sheet-up .26s cubic-bezier(.2,.8,.2,1); }
  .dialog[open]::backdrop { animation: fade-in .2s ease-out; }
  .dialog.confirm { width: 100%; height: fit-content; }
  .sheet-handle { flex: none; height: 44px; place-items: center; touch-action: none; }
  .sheet-handle span { width: 40px; height: 4px; border-radius: 2px; background: #cfd3cf; }
  .dialog-in { flex: 1; min-height: 0; height: auto; grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .dialog-side { gap: 8px; padding: 12px 14px calc(14px + env(safe-area-inset-bottom)); max-height: 34dvh; }
  .dialog-side h2 { margin: 0; font-size: 17px; }
  .dialog-side .dialog-actions, .confirm-in .dialog-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .attrib { font-size: 12px; }
  .confirm-in { padding: 0 16px calc(16px + env(safe-area-inset-bottom)); }
  .close { top: 2px; right: 6px; }
  .vp-bar { padding: 4px; }
  .vp-bar input[type=range] { margin: 0 4px; }

  .toast { bottom: calc(72px + env(safe-area-inset-bottom)); width: max-content; font-size: 14px; }
}
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes fade-in { from { opacity: 0; } }
@media (max-width: 900px) and (max-height: 700px) {
  .screen-wrap { height: 27dvh; }
  .bottom-item { min-height: 48px; }
}
@media (prefers-reduced-motion: reduce) { *, *::backdrop { transition: none !important; animation: none !important; } }
