/* Kalima Montaj: design system, shell, login, home.
   Layout variables other pages may use:
   --head-h  height of the top bar (phone and desktop)
   --tab-h   height of the bottom tab bar on phones (0 from 1000 px); a sticky bottom box on a phone sits at
             bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)) */
:root {
  --bg: #F4F3F0; --surface: #FFFFFF; --raise: #F6F4EF; --line: #ECEAE4; --fg: #1A1A1A; --muted: #6B6B66;
  --gold: #A06400; --gold-ink: #85550A; --amber: #C8860A; --on-gold: #FFFFFF; --pale: #FDF3DC;
  --ok: #1E7A3C; --warn: #B42318; --wait: #8A5A00; --radius: 16px;
  --field: #FFFFFF; --head-h: 52px; --tab-h: 58px; --side-w: 220px;
  --sb-bg: #1C1C1C; --sb-fg: #CFCCC4; --sb-on: #2B2B2B; --sb-line: #333330;
  --shadow: 0 1px 2px rgba(26, 26, 26, .04), 0 6px 18px rgba(26, 26, 26, .06);
  --font: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased; overflow-x: hidden; min-height: 100vh;
}
body.lock { overflow: hidden; }
img, video { max-width: 100%; }
a { color: var(--gold); }
h1, h2, h3, p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; border-radius: 8px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--gold); color: var(--on-gold); padding: 8px 14px; border-radius: 10px; z-index: 200; font-weight: 700; }
.skip:focus { left: 8px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* ---- type ---- */
.h1 { font-size: 22px; line-height: 1.2; font-weight: 700; letter-spacing: -.01em; }
.h2 { font-size: 17px; line-height: 1.25; font-weight: 700; }
.h3 { font-size: 14px; line-height: 1.35; font-weight: 700; }
.muted { color: var(--muted); }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 36px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--raise); color: var(--fg); font-weight: 600;
  cursor: pointer; text-decoration: none; text-align: center; line-height: 1.2; transition: background .15s, border-color .15s, transform .05s;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:hover { border-color: #D9D5CA; background: var(--raise); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--on-gold); font-weight: 700; }
.btn.primary:hover { background: #8A5400; border-color: #8A5400; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: rgba(26, 26, 26, .05); }
.btn.danger { background: transparent; border-color: var(--warn); color: var(--warn); }
.btn.danger:hover { background: rgba(180, 35, 24, .07); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
@media (pointer: coarse) { .btn.small { min-height: 40px; } }
.btn.block { width: 100%; }
.btn[disabled], .btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }

/* ---- surfaces ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 99px; font-size: 12.5px; font-weight: 600;
  background: var(--raise); border: 1px solid var(--line); color: var(--fg); white-space: nowrap;
}
.chip.gold { background: var(--pale); border-color: #F3E2B6; color: var(--gold-ink); }
.chip.ok { background: #E7F5EC; border-color: #BFE3CB; color: var(--ok); }
.chip.warn { background: #FCEBE9; border-color: #F2C4BF; color: var(--warn); }
.chip.muted { background: transparent; color: var(--muted); }

.input, .textarea {
  width: 100%; background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; color: var(--fg);
  min-height: 36px; font-size: 14px; transition: border-color .15s, box-shadow .15s;
}
.textarea { resize: vertical; min-height: 72px; line-height: 1.45; }
.input::placeholder, .textarea::placeholder { color: #8A8A85; }
.input:focus, .textarea:focus { outline: none; border-color: var(--amber); box-shadow: 0 0 0 3px rgba(200, 134, 10, .2); }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }

.empty {
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 28px 16px;
  border: 1.5px dashed var(--line); border-radius: var(--radius); background: rgba(255, 255, 255, .6);
}
.empty > p { max-width: 460px; }
.skeleton { background: linear-gradient(90deg, #EFEDE7 25%, #F8F6F1 50%, #EFEDE7 75%); background-size: 200% 100%; animation: sk 1.4s linear infinite; border-radius: 10px; }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 3px rgba(200, 134, 10, .2); flex: none; }

.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px; background: var(--raise); border: 1px solid var(--line); font-weight: 600; }
.banner.gold { background: var(--pale); border-color: #F0DAA6; color: var(--gold-ink); }
.banner.busy { background: var(--surface); border-color: var(--line); color: var(--fg); }
.banner.busy::before { content: ""; width: 14px; height: 14px; flex: none; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--amber); animation: spin .9s linear infinite; }
.banner.ok { background: #E7F5EC; border-color: #BFE3CB; color: var(--ok); }
@keyframes spin { to { transform: rotate(360deg); } }

.stepper { display: flex; list-style: none; margin: 0; padding: 0; gap: 0; }
.step { flex: 1 1 0; min-width: 0; position: relative; padding-top: 24px; text-align: center; font-size: 12px; line-height: 1.25; color: var(--muted); font-weight: 600; }
.step::before { content: ""; position: absolute; top: 2px; left: 50%; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: var(--bg); border: 2px solid #D9D5CA; z-index: 1; }
.step::after { content: ""; position: absolute; top: 8px; left: -50%; width: 100%; height: 2px; background: var(--line); }
.step:first-child::after { display: none; }
.step.done { color: var(--fg); }
.step.done::before { background: var(--amber); border-color: var(--amber); }
.step.done::after, .step.now::after { background: var(--amber); }
.step.now { color: var(--gold-ink); }
.step.now::before { background: var(--bg); border-color: var(--amber); box-shadow: 0 0 0 4px rgba(200, 134, 10, .2); }

/* ---- shell ---- */
#app { min-height: 100vh; }
.main { min-width: 0; }
.top {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 10px; padding: env(safe-area-inset-top) 12px 0 14px;
  height: calc(var(--head-h) + env(safe-area-inset-top)); background: rgba(255, 255, 255, .94);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.top-brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--fg); flex: none; }
.brand-name { font-family: "Snell Roundhand", "Brush Script MT", "Palatino Linotype", Georgia, serif; font-style: italic; font-weight: 700; font-size: 20px; letter-spacing: 0; white-space: nowrap; color: var(--gold-ink); }
.brand-mark { flex: none; }
.pill {
  margin-left: auto; min-width: 0; display: inline-flex; align-items: center; gap: 8px; height: 30px; padding: 0 12px; border-radius: 99px;
  text-decoration: none; font-size: 13px; font-weight: 600; color: var(--muted); background: var(--surface); border: 1px solid var(--line);
}
.pill-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill-dot { width: 8px; height: 8px; border-radius: 50%; background: #B5B2A8; flex: none; }
.pill.busy { color: var(--gold-ink); border-color: #F0DAA6; background: var(--pale); }
.pill.busy .pill-dot { background: var(--amber); animation: pulse 1.4s ease-in-out infinite; }
.pill.waiting { color: var(--ok); border-color: #BFE3CB; background: #E7F5EC; }
.pill.waiting .pill-dot { background: var(--ok); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(200, 134, 10, .5); } 50% { box-shadow: 0 0 0 6px rgba(200, 134, 10, 0); } }
.user-btn { width: 34px; height: 34px; flex: none; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--fg); display: grid; place-items: center; cursor: pointer; }
.user-btn:hover { background: var(--raise); }

.sb {
  position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; background: var(--sb-bg); border-top: 1px solid var(--sb-line);
  padding-bottom: env(safe-area-inset-bottom);
}
.sb-brand { display: none; }
.sb-toggle { display: none; }
.sb-links { display: flex; height: var(--tab-h); }
.nav-link {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-decoration: none;
  color: var(--sb-fg); font-size: 11.5px; font-weight: 600; position: relative; -webkit-tap-highlight-color: transparent;
}
.nav-link.on { color: #fff; }
.nav-link.on::before { content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--amber); }
#page { padding: 14px 14px calc(var(--tab-h) + env(safe-area-inset-bottom) + 28px); max-width: 1360px; margin: 0 auto; outline: none; min-width: 0; }
body.bare .sb, body.bare .top { display: none; }
body.bare #page { padding: 0; max-width: none; }

@media (min-width: 1000px) {
  :root { --tab-h: 0px; }
  .sb { top: 0; right: auto; width: var(--side-w); border-top: 0; border-right: 0; padding: 16px 10px; display: flex; flex-direction: column; gap: 18px; }
  .sb-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
  .sb-brand .brand-name { font-size: 22px; color: #C4AC5C; }
  .sb-brand .brand-mark { display: none; }
  body.sb-min .sb-brand .brand-mark { display: block; }
  .sb-links { flex-direction: column; height: auto; gap: 3px; }
  .nav-link { flex: none; flex-direction: row; justify-content: flex-start; gap: 10px; height: 40px; padding: 0 12px; border-radius: 10px; font-size: 14px; }
  .nav-link:hover { background: var(--sb-on); color: #fff; }
  .nav-link.on { background: var(--sb-on); }
  .nav-link.on::before { display: block; top: 9px; bottom: 9px; left: 0; right: auto; width: 3px; height: auto; border-radius: 3px; background: var(--amber); }
  .main { margin-left: var(--side-w); }
  .sb-toggle { display: inline-grid; place-items: center; width: 30px; height: 30px; margin-left: auto; flex: none; border-radius: 8px; border: 1px solid var(--sb-line); background: transparent; color: var(--sb-fg); cursor: pointer; }
  .sb-toggle:hover { background: var(--sb-on); color: #fff; }
  body.sb-min { --side-w: 64px; }
  body.sb-min .sb { padding: 16px 8px; align-items: center; }
  body.sb-min .sb-brand { flex-direction: column; gap: 14px; padding: 0; }
  body.sb-min .sb-brand .brand-name, body.sb-min .nav-link span { display: none; }
  body.sb-min .sb-brand .sb-toggle { margin-left: 0; }
  body.sb-min .sb-links { align-items: center; }
  body.sb-min .nav-link { width: 44px; justify-content: center; padding: 0; }
  .sb, .main { transition: width .18s, margin-left .18s; }
  .top-brand { display: none; }
  .top { padding-left: 24px; padding-right: 24px; }
  #page { padding: 18px 24px 36px; }
  .h1 { font-size: 22px; }
}

/* ---- toast ---- */
.toasts { position: fixed; z-index: 300; left: 12px; right: 12px; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; max-width: 480px; padding: 10px 16px; border-radius: 12px; background: #1C1C1C; color: #fff; border: 1px solid #1C1C1C; box-shadow: var(--shadow); font-weight: 600; animation: rise .22s ease-out; }
.toast.ok { border-color: #4CAF6B; }
.toast.warn { border-color: #E5604F; color: #FFB4A8; }
.toast.out { opacity: 0; transform: translateY(8px); transition: .22s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* ---- sheet ---- */
.sheet-overlay { position: fixed; inset: 0; z-index: 200; background: rgba(26, 26, 26, .5); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease-out; }
.sheet-overlay.out { opacity: 0; transition: opacity .15s; }
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; max-height: 92dvh; display: flex; flex-direction: column; background: var(--surface);
  border: 1px solid var(--line); border-bottom: 0; border-radius: 18px 18px 0 0; box-shadow: 0 20px 50px rgba(26,26,26,.25); animation: slide .22s ease-out;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 12px 6px 16px; }
.sheet-x { padding: 0; width: 36px; min-height: 36px; border-color: transparent; }
.sheet-body { padding: 4px 16px 16px; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.sheet-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1 1 140px; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 700px) {
  .sheet-overlay { align-items: center; padding: 24px; }
  .sheet { border-bottom: 1px solid var(--line); border-radius: 18px; }
  .sheet-foot .btn { flex: 0 0 auto; }
}

/* ---- login ---- */
.lg { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--bg); }
.lg-card { width: 100%; max-width: 380px; padding: 24px 22px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow); }
.lg-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 4px; }
.lg-sub { text-align: center; margin-bottom: 10px; }
.lg-label { font-weight: 600; font-size: 13px; color: var(--muted); }
.lg-err { color: var(--warn); min-height: 20px; font-weight: 600; font-size: 13px; }
.lg-card .btn { margin-top: 2px; }

/* ---- home ---- */
.hm { display: flex; flex-direction: column; gap: 18px; }
.hm-head { display: flex; flex-direction: column; gap: 10px; }
.hm-head .muted { margin-top: 4px; }
.hm-add { width: 100%; min-height: 40px; font-size: 14px; }
.hm-groups { display: flex; flex-direction: column; gap: 20px; }
.hm-ghead { display: flex; align-items: center; gap: 10px; }
.hm-hint { margin: 2px 0 10px; font-size: 13px; }
.hm-group .hm-ghead { margin-bottom: 0; }
.hm-list { display: grid; grid-template-columns: 1fr; gap: 10px; }
.hm-card { display: flex; gap: 12px; padding: 10px; text-decoration: none; color: var(--fg); min-width: 0; transition: border-color .15s, background .15s; }
a.hm-card:hover { border-color: #E3C88A; background: #FFFCF4; }
.hm-poster { position: relative; flex: none; width: 68px; aspect-ratio: 9 / 16; border-radius: 10px; overflow: hidden; background: linear-gradient(160deg, var(--raise), var(--surface)); display: grid; place-items: center; color: #A19E93; }
.hm-poster img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hm-poster.skeleton { display: block; }
.hm-dur { position: absolute; right: 5px; bottom: 5px; z-index: 1; padding: 1px 6px; border-radius: 6px; background: rgba(26, 26, 26, .75); font-size: 11px; font-weight: 600; color: #fff; }
.hm-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; padding: 2px 0; }
.hm-top { gap: 6px; }
.hm-title { font-size: 15px; overflow-wrap: anywhere; }
.hm-next { color: var(--fg); font-size: 13px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.hm-meta { font-size: 12px; margin-top: auto; }
.hm-new { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; font-size: 12px; font-weight: 700; color: var(--gold-ink); }
.hm-group.g-user .hm-card { border-color: #E9CF93; }
.hm-group.g-fresh .hm-card { border-color: var(--amber); border-left: 4px solid var(--amber); background: #FFFAEE; box-shadow: 0 0 0 3px rgba(200, 134, 10, .10), 0 4px 16px rgba(200, 134, 10, .18); }
a.hm-card.hm-fresh:hover { background: #FFF5DD; }
.hm-why { margin: 0; font-size: 13px; line-height: 1.4; font-weight: 600; color: var(--gold-ink); overflow-wrap: anywhere; }
.hm-empty { padding: 32px 18px; }
.hm-empty-ic { width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; background: var(--pale); color: var(--gold-ink); margin-bottom: 4px; }
.hm-msg { display: flex; flex-direction: column; gap: 10px; }
.hm-msg-act { justify-content: flex-end; }
.nv { gap: 12px; }
.nv-g { gap: 6px; }
.nv .banner { font-weight: 500; }

@media (min-width: 700px) {
  .hm-add { width: auto; min-height: 36px; font-size: 14px; }
  .hm-head { flex-direction: row; align-items: center; justify-content: space-between; }
  .hm-list { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
  .hm-poster { width: 72px; }
}
@media (min-width: 1000px) {
  .hm-msg { max-width: 640px; }
}

/* new-video sheet: ready-made choices */
.nv-cbox { gap: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.nv-ctog { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; min-height: 38px; padding: 8px 12px; text-align: left; border-radius: 0; }
.nv-choices { gap: 14px; padding: 4px 12px 12px; border-top: 1px solid var(--line); }
.nv-choices[hidden], .nv-cbox[hidden] { display: none; }
.nv-dec { gap: 8px; }
.nv-opts { display: flex; flex-direction: column; gap: 8px; }
.nv-opt { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; min-height: 38px; padding: 7px 12px; text-align: left; font: inherit; color: inherit; background: transparent; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.nv-opt.on { border-color: var(--amber); background: var(--pale); }
.nv-opt.off { opacity: .5; cursor: not-allowed; }
.nv-opt-t { font-weight: 600; }
.nv-opt-d { flex-basis: 100%; font-size: 12px; }
.nv-why { font-size: 13px; margin: 0; }
@media (min-width: 720px) { .nv-opts { flex-direction: row; flex-wrap: wrap; } .nv-opt { flex: 1 1 200px; } }

/* new-version banner */
.upd { position: sticky; top: 0; z-index: 60; background: #F5B82E; color: #1A1A1A; font-size: 12.5px; font-weight: 700; padding: calc(env(safe-area-inset-top) + 6px) 12px 6px; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 10px; box-shadow: 0 2px 8px rgba(26, 26, 26, .18); }
.upd[hidden] { display: none; }
.upd-text { text-align: center; }
.upd-info { width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(26, 26, 26, .12); cursor: pointer; font-size: 14px; line-height: 1; padding: 0; }
.upd-info:hover { background: rgba(26, 26, 26, .22); }
.upd-btn { border: 0; border-radius: 9px; background: #1A1A1A; color: #fff; font-weight: 700; padding: 5px 12px; cursor: pointer; }
.upd-pop { position: absolute; top: 100%; left: 50%; transform: translateX(-50%); margin-top: 6px; width: 340px; max-width: calc(100vw - 20px); max-height: 60vh; overflow-y: auto; background: #fff; color: #1A1A1A; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(26, 26, 26, .25); padding: 10px 12px; font-weight: 400; text-align: left; }
.upd-pop-h { font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.upd-note { display: flex; flex-direction: column; gap: 1px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 12.5px; }
.upd-note:first-of-type { border-top: 0; }
.upd-note b { font-size: 12px; }
.upd-note span { color: var(--muted); }
.top { top: var(--ban-h, 0px); }
body.has-ban { --head-h: calc(52px + var(--ban-h, 0px)); }
.sb-ver { display: none; font-size: 11px; color: var(--sb-fg); opacity: .6; padding: 0 10px; margin-top: auto; }
@media (min-width: 1000px) { .sb-ver { display: block; } body.sb-min .sb-ver { display: none; } }

.snd-btn { background: none; border: 0; cursor: pointer; font-size: 18px; line-height: 1; padding: 6px 8px; border-radius: 8px; }
.snd-btn:hover { background: rgba(0,0,0,.06); }
.toast-done { display: flex; gap: 12px; align-items: center; }
.toast-link { color: #F6DF86; text-decoration: underline; white-space: nowrap; }
