/* yti PWA. Palette and metrics follow the "yti mobile layout" canvas. */

:root {
  --bg: #0b0d0b;
  --surface: #141813;
  --border: #232a22;
  --border-2: #2c3529;
  --row-line: #1a1f19;
  --selected: #1b2219;
  --text: #d6dbcf;
  --bright: #f0f2ec;
  --desc: #c4cbbd;
  --dim: #8a9384;
  --amber: #e3a948;
  --amber-ink: #1a1406;
  --green: #8fce6a;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.green { color: var(--green); }
.amber { color: var(--amber); }
.offscreen { position: fixed; top: 0; left: -9999px; opacity: 0; }

/* ---- shell (portrait default) ---------------------------------------- */

/* Sized to the visual viewport (set from app.js) so the bottom search bar
   stays above the iOS keyboard. */
#app {
  position: fixed;
  left: 0; right: 0;
  top: var(--vv-top, 0px);
  height: var(--vv-h, 100dvh);
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#app.kb { padding-bottom: 0; }

#hdr {
  order: 1;
  padding: 6px 16px 10px;
  font-size: 12px;
  color: var(--dim);
  border-bottom: 1px solid var(--border);
}

#body { order: 2; flex: 1; min-height: 0; display: flex; }

#list {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
#sentinel { height: 1px; }

#status {
  order: 3;
  min-height: 32px;
  padding: 8px 16px;
  font-size: 11px;
  line-height: 16px;
  color: var(--dim);
  border-top: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#barrow { order: 4; display: flex; align-items: center; gap: 12px; margin: 0 12px 8px; }

#bar {
  flex: 1;
  min-width: 0;
  height: 52px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 10px;
}
#bar:focus-within { border-color: var(--dim); }
.prompt { color: var(--green); font-size: 17px; }

#q {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 16px; /* below 16px iOS zooms on focus */
  caret-color: var(--amber);
  -webkit-appearance: none;
  appearance: none;
}
#q:focus-visible { outline: 0; }

#lstatus, #colhead, #pane { display: none; }

/* ---- result rows --------------------------------------------------------- */

.row {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--row-line);
  touch-action: pan-y;
}
.fg {
  position: relative;
  background: var(--bg);
  transition: transform 0.2s ease;
}
.swiping > .fg { transition: none; }
.swiping { user-select: none; -webkit-user-select: none; }

.swipe-bg {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--amber);
  color: var(--amber-ink);
  font-size: 12px;
  font-weight: 600;
  opacity: 0.55;
  transition: opacity 0.1s;
}
.armed > .swipe-bg { opacity: 1; }

.rowbtn {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: 0;
  text-align: left;
}
.rowbtn > span { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rowbtn .t { font-size: 15px; line-height: 20px; }
.rowbtn .m { font-size: 12px; line-height: 16px; color: var(--dim); }
.rowbtn .mark, .rowbtn .c, .rowbtn .l, .rowbtn .v, .rowbtn .a { display: none; }

.row.open { border-bottom-color: var(--border-2); }
.row.open > .fg { background: var(--surface); }
.row.open .rowbtn { display: none; }

/* ---- video detail (inline in portrait, pane in landscape) --------------- */

.detail { display: flex; flex-direction: column; gap: 10px; }
.detail.inline { padding: 14px 16px 12px; }

.d-title {
  margin: 0;
  padding: 0;
  font-size: 16px;
  line-height: 22px;
  font-weight: 600;
  color: var(--bright);
  overflow-wrap: anywhere;
}
button.d-title { background: none; border: 0; text-align: left; }

.d-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
  font-size: 12px;
  line-height: 16px;
  color: var(--dim);
}
.d-meta > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-meta .val { color: var(--text); }
.d-meta .likes { color: var(--amber); }

.d-desc {
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  line-height: 19px;
  color: var(--desc);
  overflow-wrap: anywhere;
}
.d-desc .ln { min-height: 19px; white-space: pre-line; }
.d-desc .ln.has-ts { min-height: 28px; display: flex; align-items: center; }
.d-desc .chapters { display: flex; flex-direction: column; }
.d-desc .ch { display: flex; gap: 12px; min-height: 28px; align-items: center; }
.d-desc .ch .lbl { min-width: 0; white-space: pre-line; }
.d-desc .muted { color: var(--dim); }

a.ts {
  display: inline-block;
  min-width: 44px;
  color: var(--amber);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.d-actions { display: flex; gap: 8px; }
.d-actions button, .p-actions button {
  height: 44px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  font-size: 14px;
}
.d-actions button { flex: 1 1 0; }
.d-actions .open, .p-actions .open {
  background: var(--amber);
  border-color: var(--amber);
  color: var(--amber-ink);
  font-weight: 600;
}

.d-hint { display: flex; justify-content: space-between; gap: 12px; font-size: 11px; color: var(--dim); }

/* ---- login ------------------------------------------------------------- */

#login {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  background: var(--bg);
}
#login-form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; }
.login-hdr { font-size: 12px; color: var(--dim); padding-bottom: 10px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
#login-form label { font-size: 12px; color: var(--dim); }
#pw {
  height: 52px;
  padding: 0 14px;
  font-size: 16px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  caret-color: var(--amber);
}
#login-btn {
  height: 44px;
  background: var(--amber);
  color: var(--amber-ink);
  border: 0;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
}
#login-btn:disabled { opacity: 0.6; }
#login-err { min-height: 16px; margin: 0; font-size: 12px; color: var(--amber); }

/* ---- landscape ------------------------------------------------------------ */

@media (orientation: landscape) {
  #app {
    padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
             max(8px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  #app.kb { padding-bottom: 0; }
  #hdr { display: none; }

  #barrow { order: 1; margin: 0 0 8px; }
  #bar { height: 40px; padding: 0 12px; border-radius: 8px; }
  .prompt { font-size: 16px; }
  #lstatus { display: block; font-size: 11px; color: var(--dim); white-space: nowrap; }

  #colhead {
    order: 2;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 150px 72px 64px 44px;
    gap: 16px;
    padding: 6px 10px;
    font-size: 11px;
    color: var(--dim);
    border-bottom: 1px solid var(--border);
  }
  #colhead span:nth-child(n + 3) { text-align: right; }

  #body { order: 3; }

  /* Still announced to screen readers; #lstatus is the visible copy. */
  #status {
    position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); border: 0;
  }

  .rowbtn,
  .row.open .rowbtn {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 150px 72px 64px 44px;
    gap: 16px;
    align-items: center;
    height: 34px;
    padding: 0 10px;
  }
  .rowbtn .t { font-size: 14px; line-height: 18px; }
  .rowbtn .m { display: none; }
  .rowbtn .c, .rowbtn .l, .rowbtn .v, .rowbtn .a { display: block; font-size: 12px; color: var(--dim); }
  .rowbtn .l, .rowbtn .v, .rowbtn .a { text-align: right; }

  .detail.inline { display: none; }
  .row.open > .fg { background: var(--selected); }

  /* A selected video: list on the left, detail pane on the right. */
  #app.split #colhead { display: none; }
  #app.split #body { border-top: 1px solid var(--border); }
  #app.split #list { flex: 0 0 380px; border-right: 1px solid var(--border); }
  #app.split .rowbtn,
  #app.split .row.open .rowbtn { display: flex; flex-direction: row; gap: 12px; }
  #app.split .rowbtn .t { flex: 1; font-size: 13px; }
  #app.split .rowbtn .c, #app.split .rowbtn .v, #app.split .rowbtn .a { display: none; }
  #app.split .row.open .mark { display: block; color: var(--amber); }
  #app.split .row.open .t { color: var(--bright); }

  #app.split #pane {
    display: flex;
    flex: 1;
    min-width: 0;
    position: relative;
    overflow: hidden;
    touch-action: pan-y;
  }
  #pane-fg { flex: 1; min-width: 0; display: flex; padding: 12px 0 0 16px; }
  .detail.pane { flex: 1; min-width: 0; min-height: 0; }
  .pane .d-meta { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pane .d-desc {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--surface);
    font-size: 12px;
    line-height: 18px;
  }
  .pane .d-desc .ln { min-height: 18px; }
  .pane .d-desc .chapters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 16px; }
  .pane .d-desc .ch { gap: 10px; }
  .pane .d-desc .ch .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  .p-actions { display: flex; align-items: center; gap: 8px; }
  .p-actions .hint { flex: 1; min-width: 0; font-size: 11px; color: var(--dim); }
  .p-actions button { padding: 0 14px; font-size: 13px; }
  .p-actions .open { display: flex; align-items: center; gap: 8px; padding: 0 16px; }
}
