:root {
  --bg: #fff5f9;
  --panel: #ffffff;
  --panel-2: #fff2f7;
  --line: #f2bcd4;          /* decorative borders */
  --line-strong: #d06f99;    /* input / interactive borders (>=3:1 on white) */
  --text: #5a3546;
  --muted: #8f5f75;          /* AA contrast on white / panel-2 */
  --accent: #ff5fa2;
  --accent-2: #c62868;       /* deeper pink: readable as text/link/table header */
  --accent-soft: #ffe3ef;
  --danger: #bf3237;
  --ok: #1f7d52;
  --warn: #8f5606;
  --shadow: 0 10px 30px rgba(233, 122, 170, .18);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  color: var(--text);
  font: 14px/1.6 -apple-system, "Segoe UI", "Noto Sans SC", "Microsoft YaHei", Roboto, sans-serif;
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 18% 8%, rgba(255, 205, 226, .75) 0, transparent 38%),
    radial-gradient(circle at 85% 0%, rgba(255, 226, 240, .85) 0, transparent 34%),
    radial-gradient(rgba(255, 187, 215, .55) 1.2px, transparent 1.2px);
  background-size: auto, auto, 24px 24px;
  background-attachment: fixed;
}
/* falling sakura petals: decorative, never blocks clicks, sits behind content */
#sakura {
  position: fixed; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 0;
}
a { color: var(--accent-2); }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: linear-gradient(135deg, #d92e7a, #b21f5f);
  border: 0; color: #fff; padding: 9px 16px;
  border-radius: 999px; cursor: pointer; font-weight: 600;
  box-shadow: 0 4px 12px rgba(178, 31, 95, .28);
  transition: filter .15s, transform .1s;
}
button:hover { filter: brightness(1.12); }
button:active { transform: translateY(1px); }
button.ghost { background: #fff; border: 1.5px solid var(--line-strong); color: var(--accent-2); box-shadow: none; }
button.ghost:hover { background: var(--panel-2); }
button.danger { background: linear-gradient(135deg, #c9343a, #a3242a); box-shadow: 0 4px 12px rgba(163, 36, 42, .25); }
button:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
button:focus-visible, a:focus-visible, .thumb:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent-2); outline-offset: 2px;
}
input, select, textarea {
  background: #fff; border: 1.5px solid var(--line-strong); border-radius: 12px;
  padding: 9px 11px; width: 100%; color: var(--text);
}
/* keyboard focus keeps a visible outline; mouse focus just gets the soft glow */
input:focus, select:focus, textarea:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input:focus:not(:focus-visible), select:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) { outline: none; }
input[type=file] { padding: 6px; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
label { display: block; margin: 10px 0 4px; color: var(--muted); font-size: 12px; }
h1, h2, h3 { margin: 0 0 12px; letter-spacing: .3px; }
h1 { font-size: 21px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }
.pink { color: var(--accent-2); }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 12px 20px;
  background: rgba(255, 255, 255, .9);
  border-bottom: 2px dashed var(--line);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 30;
}
.brand { font-weight: 800; letter-spacing: .5px; font-size: 16px; }
a.brand { text-decoration: none; color: inherit; cursor: pointer; }
a.brand:hover { filter: brightness(1.08); }
.pill {
  background: var(--panel-2); border: 1.5px solid var(--line); border-radius: 999px;
  padding: 3px 12px; font-size: 12px; color: var(--accent-2); font-weight: 600;
}
.container { max-width: 1280px; margin: 0 auto; padding: 20px; position: relative; z-index: 1; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; position: relative; z-index: 1; }
.card {
  background: var(--panel); border: 2px solid var(--line); border-radius: 20px;
  padding: 22px; box-shadow: var(--shadow);
}
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { text-align: center; margin-bottom: 6px; }

/* media grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }
.vcard {
  background: var(--panel); border: 2px solid var(--line); border-radius: 18px;
  overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .12s;
}
.vcard:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(233, 122, 170, .26); }
.thumb {
  position: relative; aspect-ratio: 16/9; background: #ffe6f0 center/cover no-repeat;
  cursor: pointer;
}
.thumb .play {
  position: absolute; inset: 0; display: grid; place-items: center; font-size: 34px;
  color: #fff; opacity: .95;
}
.thumb .play > span {
  display: grid; place-items: center; width: 60px; height: 60px; border-radius: 50%;
  background: rgba(120, 40, 80, .45); text-shadow: 0 2px 8px rgba(60, 15, 40, .7);
  backdrop-filter: blur(2px);
}
.vcard .body { padding: 12px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.vcard .title { font-weight: 700; word-break: break-word; }
.badge { font-size: 11px; padding: 2px 10px; border-radius: 999px; border: 1.5px solid var(--line); background: #fff; }
.pill, .badge { white-space: nowrap; }
/* media table: let it scroll horizontally instead of squeezing columns together */
#videoTable { min-width: 1040px; }
#videoTable th, #videoTable td { white-space: nowrap; }
#videoTable td:nth-child(4) { white-space: normal; min-width: 200px; max-width: 360px; overflow-wrap: anywhere; }
.badge.ready { color: var(--ok); border-color: #bfe6d3; background: #f1fbf6; }
.badge.watched { color: var(--ok); border-color: #bfe6d3; background: #f1fbf6; }
.badge.unwatched { color: var(--accent-2); border-color: var(--line-strong); background: var(--panel-2); }
.badge.processing { color: var(--warn); border-color: #f4dcae; background: #fff9ee; }
.badge.failed { color: var(--danger); border-color: #f5c3c5; background: #fff3f3; }
.progress { height: 8px; background: var(--accent-soft); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, #ffa9cc, #ff4f99); width: 0; transition: width .4s; }

/* modals */
.modal {
  position: fixed; inset: 0; background: rgba(120, 60, 90, .4); z-index: 100;
  display: grid; place-items: center; padding: 16px; backdrop-filter: blur(3px);
}
.modal-box {
  width: min(1080px, 96vw); background: var(--panel); border: 2px solid var(--line);
  border-radius: 20px; overflow: hidden; display: flex; flex-direction: column;
  max-height: 94vh; box-shadow: 0 20px 60px rgba(214, 110, 160, .35);
}
.modal-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-bottom: 2px dashed var(--line); background: var(--panel-2);
}
.stage {
  position: relative; background: #1b0f16; line-height: 0; overflow: hidden;
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
}
.stage video { width: 100%; max-height: 70vh; display: block; background: #1b0f16; }
/* photos: block long-press / drag / right-click save; download only via button */
.stage img {
  width: 100%; max-height: 74vh; display: block; background: #1b0f16; object-fit: contain;
  pointer-events: none; -webkit-user-drag: none; -webkit-touch-callout: none;
  -webkit-user-select: none; user-select: none;
}
.stage-photo { display: grid; place-items: center; min-height: 200px; }
.wm-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
/* watermark = several very transparent white texts floating upward like balloons */
.wm-float {
  position: absolute; top: 100%; left: 0; white-space: nowrap;
  color: #fff; font-weight: 700; letter-spacing: .5px;
  text-shadow: 0 0 8px rgba(255, 255, 255, .28);
  pointer-events: none; will-change: transform;
  animation-name: wmRise; animation-timing-function: linear; animation-iteration-count: infinite;
}
.wm-sway {
  display: inline-block; animation-name: wmSway; animation-timing-function: ease-in-out;
  animation-iteration-count: infinite; animation-direction: alternate;
}
@keyframes wmRise {
  from { transform: translateY(0); }
  to   { transform: translateY(calc(-1 * var(--rise, 120vh))); }
}
@keyframes wmSway {
  from { transform: translateX(-12px); }
  to   { transform: translateX(12px); }
}
.collection-head {
  display: flex; align-items: baseline; gap: 10px;
  margin: 20px 0 10px; padding-bottom: 6px; border-bottom: 2px dashed var(--line);
}
.collection-head h2 { margin: 0; font-size: 16px; color: var(--accent-2); }
.upload-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.upload-row {
  display: flex; gap: 10px; align-items: center;
  background: var(--panel-2); border: 1.5px solid var(--line); border-radius: 12px; padding: 6px 10px;
}
.upload-row .fname { flex: 0 0 34%; font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-row input { flex: 1; }
.upload-row .st { flex: 0 0 auto; font-size: 11px; color: var(--muted); min-width: 52px; text-align: right; }
.dropzone {
  position: relative; border: 2.5px dashed var(--line-strong); border-radius: 16px;
  padding: 22px; text-align: center; color: var(--muted); transition: .15s; margin-top: 8px;
  background: var(--panel-2);
}
.dropzone.drag { border-color: var(--accent-2); background: var(--accent-soft); color: var(--text); }
.dropzone input[type=file] {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer;
}
.modal-foot { padding: 12px 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; border-top: 2px dashed var(--line); }
.notice { background: #fff6e6; border: 1.5px solid #f4dcae; color: #8a6415; padding: 8px 12px; border-radius: 12px; font-size: 12px; }

/* admin */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { background: #fff; border: 1.5px solid var(--line); color: var(--muted); box-shadow: none; }
.tabs button.active { background: linear-gradient(135deg, #fb6ba6, #e02f7d); color: #fff; border-color: transparent; }
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 12px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--accent-2); font-weight: 700; font-size: 12px; background: var(--panel-2); }
tbody tr:hover { background: #fffafc; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }
/* narrow phones: let the top bar wrap instead of overflowing horizontally */
@media (max-width: 620px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .brand { font-size: 15px; }
  .container { padding: 12px; }
  .modal-box { border-radius: 16px; }
  .toast { width: max-content; max-width: 92vw; text-align: center; }
}
/* empty-state row used by the admin tables */
td.empty, .empty-row { color: var(--muted); text-align: center; padding: 18px 10px; }
.perm-list { max-height: 240px; overflow: auto; border: 1.5px solid var(--line); border-radius: 12px; padding: 8px; background: var(--panel-2); }
.perm-list label { display: flex; gap: 8px; align-items: center; margin: 4px 0; color: var(--text); }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #fff; border: 2px solid var(--line); padding: 10px 18px;
  border-radius: 999px; z-index: 200; box-shadow: var(--shadow); color: var(--accent-2); font-weight: 600;
}
.small-btn { padding: 5px 11px; font-size: 12px; border-radius: 999px; }
tbody tr:hover { background: var(--panel-2); }

/* link styled as a ghost button (avoids invalid <a><button> nesting) */
.btn-link {
  display: inline-block; background: #fff; border: 1.5px solid var(--line-strong);
  color: var(--accent-2); padding: 9px 16px; border-radius: 999px; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.btn-link:hover { background: var(--panel-2); }

/* modal header stays on one line on narrow screens */
.modal-head { flex-wrap: nowrap; }
.modal-head b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-head > button, .modal-head > a { flex: 0 0 auto; }
.collection-head { flex-wrap: wrap; }

/* lock background scrolling while a modal is open (modern browsers) */
body:has(.modal:not(.hidden)) { overflow: hidden; }

/* narrow phones: let the upload rows wrap instead of squeezing the title box */
@media (max-width: 620px) {
  .upload-row { flex-wrap: wrap; }
  .upload-row .fname { flex: 1 1 100%; }
  .upload-row input { flex: 1 1 100%; }
}

/* respect the OS "reduce motion" setting */
@media (prefers-reduced-motion: reduce) {
  #sakura { display: none; }
  .wm-float, .wm-sway { animation: none !important; }
  .vcard { transition: none; }
  body { background-attachment: scroll; }
}

/* notification bell + unread badge */
#notifBtn { position: relative; }
.dot {
  display: inline-block; background: var(--danger); color: #fff; font-size: 10px;
  line-height: 1; border-radius: 999px; padding: 2px 5px; margin-left: 4px; vertical-align: top;
}
.dot.hidden { display: none !important; }

/* message board */
.board-body { padding: 14px 16px; max-height: 74vh; overflow: auto; }
.board-compose { background: var(--panel-2); border: 1.5px solid var(--line); border-radius: 14px; padding: 10px; }
.board-compose textarea { resize: vertical; }
.board-list { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { background: #fff; border: 1.5px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.msg.reply { background: var(--panel-2); border-radius: 12px; margin-top: 8px; }
.msg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.msg-content { white-space: pre-wrap; word-break: break-word; }
.msg-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.msg-replies { margin-top: 8px; border-left: 2px dashed var(--line); padding-left: 10px; }

/* notifications list */
.notif {
  border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px;
  margin-bottom: 8px; cursor: pointer; background: #fff;
}
.notif.unread { background: var(--accent-soft); border-color: var(--line-strong); }
.notif .msg-head { margin-bottom: 4px; }

/* collection tiles on the home page */
.col-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.col-card {
  position: relative; background: var(--panel); border: 2px solid var(--line);
  border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); cursor: pointer;
  transition: transform .12s, box-shadow .12s;
}
.col-card:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(233, 122, 170, .26); }
.col-cover {
  position: relative; aspect-ratio: 16/10;
  background: linear-gradient(135deg, #ffe1ef, #ffc2dd) center/cover no-repeat;
}
.col-badge {
  position: absolute; right: 8px; bottom: 8px; background: rgba(120, 40, 80, .55);
  color: #fff; font-size: 11px; padding: 2px 9px; border-radius: 999px;
}
.col-body { padding: 10px 12px; }
.col-title { font-weight: 700; word-break: break-word; }
.col-detail { position: absolute; top: 8px; right: 8px; }


/* ---- avatars + role-coloured names (message board / topbar / admin) ---- */
.avatar {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%; overflow: hidden; flex: 0 0 auto;
  background: linear-gradient(135deg, #ffd0e4, #ff9ec4); color: #fff;
  font-weight: 700; font-size: 15px; object-fit: cover;
}
.avatar:not(.has-img)::after { content: attr(data-initial); }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.sm { width: 26px; height: 26px; font-size: 12px; }
.avatar.lg { width: 72px; height: 72px; font-size: 28px; }
.profile-btn { display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px; max-width: 46vw; }
.profile-btn b { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-name { font-weight: 700; }
.notif-to { width: auto; }
#notifTargets label { display: flex; align-items: center; gap: 8px; }
#notifTargets input { width: auto; }

/* ===================== mobile polish ===================== */
button, a, .col-card, .vcard .thumb, .dropzone, input[type=file] {
  touch-action: manipulation;
}
button, .btn-link, a { -webkit-tap-highlight-color: transparent; }
button, .btn-link { min-height: 38px; }

@media (max-width: 620px) {
  /* iOS zooms the page when a field under 16px gets focus; 16px keeps the
     layout stable while pinch-zoom still works (we never set user-scalable=no) */
  input, select, textarea { font-size: 16px; }
  button, .btn-link { min-height: 42px; padding: 10px 16px; }
  .small-btn { min-height: 34px; padding: 7px 12px; font-size: 13px; }

  /* top bar: no dangling spacer, wrap the buttons, respect the notch */
  .topbar { flex-wrap: wrap; gap: 6px; padding: 8px 10px;
            padding-top: calc(8px + env(safe-area-inset-top)); }
  .topbar .spacer { display: none; }
  .topbar button, .topbar .btn-link { padding: 8px 12px; }
  .profile-btn { padding: 4px 10px; }

  .container { padding: 10px 10px calc(16px + env(safe-area-inset-bottom)); }
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .col-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .col-cover { aspect-ratio: 4 / 3; }

  .modal { padding: 8px; }
  .modal-box { width: 100%; max-height: 92dvh; border-radius: 16px; }
  .modal-head { padding: 10px 12px; }
  .board-body { max-height: 72dvh; padding: 10px 12px; }
  .dropzone { padding: 18px 12px; }
  .toast { bottom: calc(16px + env(safe-area-inset-bottom)); }
  .stage video { max-height: 58dvh; }
  .stage img { max-height: 62dvh; }

  .tabs { gap: 6px; }
  .tabs button { padding: 8px 12px; }
  #videoTable, #userTable, #lockTable, #logTable, #roleTable, #collectionTable {
    -webkit-overflow-scrolling: touch;
  }
}
@media (max-width: 380px) {
  .brand { font-size: 14px; }
  .topbar button, .topbar .btn-link, .profile-btn { padding: 7px 10px; font-size: 13px; }
}

/* No fullscreen / PiP controls: fullscreen would hide the dynamic watermark */
.stage video::-webkit-media-controls-fullscreen-button,
.stage video::-webkit-media-controls-picture-in-picture-button { display: none !important; }

/* external player controls (native controls removed to block iOS fullscreen) */
.player-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--panel); border-top: 1.5px solid var(--line);
}
.player-bar #seek { flex: 1; min-width: 60px; accent-color: var(--accent-2); }
.player-bar .pbtn { flex: 0 0 auto; }
.player-bar span { flex: 0 0 auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
@media (max-width: 620px) {
  .player-bar { flex-wrap: wrap; row-gap: 6px; padding: 8px 10px; }
  .player-bar #seek { order: 10; flex: 1 1 100%; }
}
