:root {
  /* ---- shared tokens ---- */
  --brand: #6366f1;
  --brand-2: #8b5cf6;
  --radius: 18px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "Fira Code", Consolas, "Cascadia Code", monospace;

  /* ---- LIGHT THEME (default) ---- */
  color-scheme: light;
  --bg: #e9edf9;
  --bg-soft: #ffffff;
  --card: rgba(255, 255, 255, 0.72);
  --card-solid: #ffffff;
  --border: rgba(24, 33, 64, 0.12);
  --border-strong: rgba(24, 33, 64, 0.20);
  --text: #16203c;
  --muted: #5a6488;
  --brand-3: #0e8fae;
  --good: #059669;
  --bad: #e11d48;
  --warn: #d97706;
  --warn-text: #92400e;
  --warn-notice-bg: rgba(254, 243, 199, 0.96);
  --warn-notice-border: rgba(217, 119, 6, 0.55);
  --inset-bg: rgba(24, 33, 64, 0.045);
  --input-bg: #ffffff;
  --chip-bg: rgba(24, 33, 64, 0.05);
  --app-bg:
    radial-gradient(1100px 700px at 12% -8%, rgba(99, 102, 241, 0.16), transparent 60%),
    radial-gradient(1000px 700px at 105% 8%, rgba(34, 211, 238, 0.12), transparent 55%),
    radial-gradient(900px 800px at 50% 120%, rgba(139, 92, 246, 0.14), transparent 60%),
    var(--bg);
  --viewer-bg: #e7ebf6;
  --panel-bg: rgba(255, 255, 255, 0.94);
  --guard-overlay: rgba(228, 233, 245, 0.94);
  --watermark-color: rgba(24, 33, 64, 0.10);
  --license-color: rgba(24, 33, 64, 0.50);
  --scrollbar-thumb: rgba(24, 33, 64, 0.22);
  --shadow: 0 18px 48px -22px rgba(24, 33, 64, 0.35);
}

html[data-theme="dark"] {
  /* ---- DARK THEME ---- */
  color-scheme: dark;
  --bg: #0b1020;
  --bg-soft: #121933;
  --card: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
  --card-solid: #141b33;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #eef1fb;
  --muted: #9aa3c7;
  --brand-3: #22d3ee;
  --good: #34d399;
  --bad: #fb7185;
  --warn: #fbbf24;
  --warn-text: #fde68a;
  --warn-notice-bg: rgba(69, 49, 11, 0.96);
  --warn-notice-border: rgba(251, 191, 36, 0.55);
  --inset-bg: rgba(8, 11, 26, 0.5);
  --input-bg: rgba(8, 11, 26, 0.6);
  --chip-bg: rgba(255, 255, 255, 0.05);
  --app-bg:
    radial-gradient(1100px 700px at 12% -8%, rgba(99, 102, 241, 0.30), transparent 60%),
    radial-gradient(1000px 700px at 105% 8%, rgba(34, 211, 238, 0.18), transparent 55%),
    radial-gradient(900px 800px at 50% 120%, rgba(139, 92, 246, 0.22), transparent 60%),
    var(--bg);
  --viewer-bg: #05070f;
  --panel-bg: rgba(10, 14, 28, 0.92);
  --guard-overlay: rgba(5, 7, 15, 0.9);
  --watermark-color: rgba(255, 255, 255, 0.16);
  --license-color: rgba(255, 255, 255, 0.30);
  --scrollbar-thumb: rgba(255, 255, 255, 0.14);
  --shadow: 0 24px 60px -20px rgba(8, 11, 30, 0.75);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--app-bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color .25s ease, color .25s ease;
}

/* ---------------- theme toggle ---------------- */
.themeToggle {
  width: 42px; height: 42px; padding: 0; flex: none;
  display: inline-grid; place-items: center;
  background: var(--card-solid); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 12px;
  box-shadow: none;
}
.themeToggle:hover { filter: none; border-color: var(--brand); }
.themeToggle:active { transform: none; }
.themeToggle svg { width: 20px; height: 20px; }
.themeToggle .icon-sun, .themeToggle .icon-moon { display: none; }
html[data-theme="light"] .themeToggle .icon-moon { display: block; }
html[data-theme="dark"] .themeToggle .icon-sun { display: block; }
.themeToggle.floating { position: fixed; top: 18px; right: 18px; z-index: 50; }

a { color: inherit; }
::selection { background: rgba(99, 102, 241, 0.45); }

/* ---------------- home layout ---------------- */
.shell {
  width: min(1080px, 92vw);
  margin: 0 auto;
  padding: 48px 0 64px;
  display: grid;
  gap: 22px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 30px;
  flex-wrap: wrap;
}
.hero .brandmark { display: flex; align-items: center; gap: 14px; }
.hero .logo {
  width: 58px; height: 58px;
  display: grid; place-items: center;
  flex: none;
}
.hero .logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.tag {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--brand-3); margin: 0 0 6px;
}
.tag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.18); }
.hero h1 { margin: 0; font-size: clamp(22px, 3.4vw, 32px); letter-spacing: -0.02em; }
.hero .sub { margin: 8px 0 0; color: var(--muted); max-width: 560px; line-height: 1.55; font-size: 14.5px; }
.owner { text-align: right; font-size: 13px; color: var(--muted); }
.owner b { display: block; color: var(--text); font-size: 15px; }
.owner a { text-decoration: none; }
.owner a:hover { color: var(--brand-3); }

/* ---------------- form ---------------- */
.formcard { padding: 26px 30px 30px; }
.formhead { margin: 0 0 18px; }
.formhead h2 { margin: 0; font-size: 18px; }
.formhead p { margin: 6px 0 0; color: var(--muted); font-size: 13.5px; }

form { display: grid; gap: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

label { display: grid; gap: 7px; font-size: 13px; font-weight: 600; color: #cdd4f3; }
label small { font-weight: 500; color: var(--muted); font-size: 11.5px; line-height: 1.4; }

input, select {
  font-family: inherit; font-size: 14.5px; color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px; outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
  width: 100%;
}
input::placeholder { color: var(--muted); }
input:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.22);
  background: var(--input-bg);
}
select { appearance: none; cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%239aa3c7' stroke-width='2' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

.settingsGrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.settingBox { background: var(--inset-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; }

.filebox {
  position: relative;
  border: 1.8px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 26px 18px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
  background: var(--inset-bg);
}
.filebox:hover { border-color: var(--brand); background: rgba(99, 102, 241, 0.07); }
.filebox.dragover { border-color: var(--brand-3); background: rgba(34, 211, 238, 0.10); transform: scale(1.005); }
.filebox.selected { border-style: solid; border-color: var(--good); background: rgba(52, 211, 153, 0.08); }
.filebox input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.filebox .fileIcon { width: 40px; height: 40px; margin: 0 auto 8px; color: var(--muted); }
.filebox.selected .fileIcon { color: var(--good); }
.filebox #fileText { display: block; font-weight: 700; font-size: 14.5px; }
.filebox #fileHint { display: block; color: var(--muted); margin-top: 4px; font-size: 12.5px; word-break: break-all; }

button {
  font-family: inherit; font-weight: 700; font-size: 15px; color: #fff; cursor: pointer;
  border: none; border-radius: var(--radius-sm); padding: 14px 18px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 14px 30px -12px rgba(99, 102, 241, 0.9);
  transition: transform .08s, box-shadow .15s, filter .15s;
}
button:hover { filter: brightness(1.07); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .6; cursor: progress; }

/* ---------------- result ---------------- */
.result { margin-top: 22px; }
.result.hidden { display: none; }
.result .panel { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 22px; background: var(--inset-bg); display: grid; gap: 16px; }
.result h2 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.linkrow { display: flex; gap: 10px; }
.linkrow input { font-family: var(--mono); font-size: 14px; }
.linkrow button { padding: 0 18px; background: linear-gradient(135deg, #1f2747, #283157); box-shadow: none; border: 1px solid var(--border-strong); flex: none; }
.qrwrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.qr { width: 150px; height: 150px; border-radius: 14px; background: #fff; padding: 8px; }
.qrmeta { display: grid; gap: 10px; }
.downloadQr { display: inline-flex; align-items: center; gap: 8px; width: max-content; text-decoration: none; font-weight: 600; font-size: 13.5px; color: var(--brand-3); border: 1px solid var(--border-strong); border-radius: 10px; padding: 9px 13px; transition: background .15s; }
.downloadQr:hover { background: rgba(34, 211, 238, 0.1); }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--chip-bg); border: 1px solid var(--border); padding: 5px 10px; border-radius: 999px; }
.note { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 0; }
.copyStatus { color: var(--good); font-weight: 700; font-size: 13.5px; opacity: 0; transform: translateY(-4px); transition: opacity .2s, transform .2s; }
.copyStatus.show { opacity: 1; transform: translateY(0); }
.loading { color: var(--muted); display: flex; align-items: center; gap: 10px; font-weight: 600; }
.loading::before { content: ""; width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,0.2); border-top-color: var(--brand-3); border-radius: 50%; animation: spin .7s linear infinite; }
.error { color: var(--bad); font-weight: 600; background: rgba(251, 113, 133, 0.1); border: 1px solid rgba(251, 113, 133, 0.3); border-radius: var(--radius-sm); padding: 12px 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

footer { text-align: center; color: var(--muted); font-size: 12.5px; padding-top: 6px; }
footer a { text-decoration: none; color: var(--text); }
.hidden { display: none !important; }

/* ===================================================================
   VIEWER
   =================================================================== */
body.viewer { background: var(--viewer-bg); display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 12px 18px;
  background: var(--panel-bg); border-bottom: 1px solid var(--border);
  /* Above the guard overlay (z 60) so the theme toggle / timer / filename
     stay tappable even while the file area is locked. The header isn't
     protected content — only the .stage below it is covered. */
  backdrop-filter: blur(10px); position: relative; z-index: 70;
}
.topbar .themeToggle { width: 38px; height: 38px; }
.topbar .themeToggle svg { width: 18px; height: 18px; }
.topbar .vlogo { width: 38px; height: 38px; display: grid; place-items: center; flex: none; }
.topbar .vlogo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.fileinfo { min-width: 0; flex: 1; }
.fileinfo .fname { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fileinfo .fmeta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fileinfo .accessInfo:not(:empty) { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px; background: var(--chip-bg); border: 1px solid var(--border); color: var(--text); font-weight: 600; font-size: 11px; }
.timerpill { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; font-size: 13.5px; font-variant-numeric: tabular-nums; color: var(--text); background: rgba(99, 102, 241, 0.18); border: 1px solid rgba(99, 102, 241, 0.4); padding: 8px 13px; border-radius: 999px; flex: none; }
.timerpill svg { width: 15px; height: 15px; }
.timerpill.danger { background: rgba(251, 113, 133, 0.22); border-color: rgba(251, 113, 133, 0.5); }

.stage { position: relative; flex: 1; overflow: auto; padding: 20px 14px 60px; -webkit-overflow-scrolling: touch; }
.stage::-webkit-scrollbar { width: 10px; }
.stage::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 8px; }

.imagewrap { display: grid; place-items: center; min-height: 100%; }
.imagewrap img { max-width: min(1100px, 100%); height: auto; border-radius: 12px; box-shadow: var(--shadow); -webkit-user-drag: none; user-select: none; }

.pdfStack { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.pdfPage { width: 100%; max-width: 1180px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.pdfPageLabel { font-size: 11.5px; color: var(--muted); font-weight: 600; letter-spacing: .03em; }
.pdfPage canvas { max-width: 100%; height: auto; border-radius: 8px; box-shadow: var(--shadow); background: #fff; }
.pdfPlaceholder { width: min(900px, 92%); aspect-ratio: 1 / 1.414; display: grid; place-items: center; color: var(--muted); font-size: 13px; background: rgba(255,255,255,0.03); border: 1px dashed var(--border); border-radius: 8px; }

.docx { max-width: 820px; margin: 0 auto; background: #fff; color: #1a1a1a; border-radius: 12px; padding: 48px 56px; box-shadow: var(--shadow); line-height: 1.7; user-select: none; }
.docx h1 { font-size: 26px; } .docx h2 { font-size: 21px; } .docx img { max-width: 100%; }

.codeview { max-width: 1100px; margin: 0 auto; background: #0a0e1c; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.codeview .codehead { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: rgba(255,255,255,0.03); border-bottom: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.codeview pre { margin: 0; padding: 16px 18px; overflow: auto; font-family: var(--mono); font-size: 13px; line-height: 1.6; color: #d6deff; tab-size: 2; }
.codeview pre code { white-space: pre; }

.mediawrap { display: grid; place-items: center; min-height: 100%; gap: 14px; }
.mediawrap video { max-width: min(1100px, 100%); max-height: 78vh; border-radius: 12px; box-shadow: var(--shadow); background: #000; }
.audiocard { width: min(560px, 92%); background: var(--card-solid); border: 1px solid var(--border); border-radius: 16px; padding: 30px; text-align: center; box-shadow: var(--shadow); }
.audiocard .acdisc { width: 90px; height: 90px; margin: 0 auto 16px; border-radius: 50%; background: linear-gradient(140deg, var(--brand), var(--brand-2)); display: grid; place-items: center; color: #fff; }
.audiocard audio { width: 100%; margin-top: 12px; }

.genericcard { max-width: 480px; margin: 6vh auto; background: var(--card-solid); border: 1px solid var(--border); border-radius: 18px; padding: 36px; text-align: center; box-shadow: var(--shadow); }
.genericcard .gicon { width: 76px; height: 76px; margin: 0 auto 18px; border-radius: 18px; background: linear-gradient(140deg, var(--brand), var(--brand-2)); display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 20px; letter-spacing: .02em; text-transform: uppercase; }
.genericcard h2 { margin: 0 0 6px; font-size: 18px; }
.genericcard p { margin: 6px 0; color: var(--muted); font-size: 13.5px; line-height: 1.55; }
.genericcard .gmeta { margin-top: 14px; font-family: var(--mono); font-size: 12.5px; color: var(--text); background: var(--inset-bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px; word-break: break-all; }

#watermark { position: fixed; z-index: 5; pointer-events: none; font-weight: 800; font-size: 18px; color: var(--watermark-color); text-shadow: 0 1px 2px rgba(0,0,0,0.18); white-space: nowrap; user-select: none; animation: drift 17s linear infinite; }
@keyframes drift {
  0%   { top: 12%; left: -10%; transform: rotate(-18deg); }
  25%  { top: 70%; left: 60%; }
  50%  { top: 30%; left: 80%; }
  75%  { top: 80%; left: 10%; }
  100% { top: 12%; left: -10%; transform: rotate(-18deg); }
}

.license { flex: none; text-align: center; font-size: 11px; line-height: 1.45; color: var(--license-color); padding: 8px 16px; background: var(--panel-bg); border-top: 1px solid var(--border); backdrop-filter: blur(10px); z-index: 30; }

.pageHud { position: fixed; bottom: 52px; left: 50%; transform: translateX(-50%); background: var(--panel-bg); border: 1px solid var(--border-strong); color: var(--text); font-size: 12.5px; font-weight: 600; padding: 7px 14px; border-radius: 999px; z-index: 90; backdrop-filter: blur(8px); box-shadow: var(--shadow); pointer-events: none; }
.pageHud.hidden { display: none; }

/* Notice sits ABOVE the blur/guard overlay (z 60) and lets touches pass
   through (pointer-events:none) so press-and-hold still works underneath. */
.leaveWarning { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); max-width: min(560px, 92%); background: var(--warn-notice-bg); border: 1px solid var(--warn-notice-border); color: var(--warn-text); font-size: 12.5px; font-weight: 600; line-height: 1.5; padding: 11px 16px; border-radius: 12px; z-index: 100; text-align: center; box-shadow: var(--shadow); backdrop-filter: blur(8px); pointer-events: none; }
.leaveWarning.hidden { display: none; }

body.blurred .stage { filter: blur(22px); }
#guard { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--guard-overlay); backdrop-filter: blur(6px); padding: 24px; text-align: center; }
#guard.hidden { display: none; }
.guardPanel { display: flex; flex-direction: column; align-items: center; gap: 16px; width: min(440px, 92vw); background: var(--panel-bg); border: 1px solid var(--border-strong); border-radius: 18px; padding: 28px 26px; box-shadow: var(--shadow); }
#guard .shieldIcon { width: 56px; height: 56px; color: var(--warn); flex: none; }
#guardText { color: var(--warn-text); font-weight: 600; line-height: 1.55; font-size: 14.5px; }
#guardOk { background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
#guardOk.hidden { display: none; }
/* Mobile "press & hold the whole screen" mode: the full-screen #guard overlay
   is the hold surface; disable native gestures/selection so dragging scrolls
   the content cleanly instead of panning the page. */
body.mobileHoldMode { touch-action: none; -webkit-tap-highlight-color: transparent; }
body.mobileHoldMode #guard { cursor: pointer; user-select: none; touch-action: none; }
body.mobileHoldMode.holding #guard { display: none; }

/* ---------------- terminal pages ---------------- */
body.center-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.statuscard { width: min(420px, 92vw); text-align: center; padding: 40px 32px; }
.statuscard .sicon { width: 76px; height: 76px; margin: 0 auto 20px; border-radius: 20px; display: grid; place-items: center; }
.statuscard.expired .sicon { background: rgba(251, 113, 133, 0.16); color: var(--bad); }
.statuscard.used .sicon { background: rgba(251, 191, 36, 0.16); color: var(--warn); }
.statuscard .sicon svg { width: 40px; height: 40px; }
.statuscard h1 { margin: 0 0 10px; font-size: 22px; }
.statuscard p { margin: 0; color: var(--muted); line-height: 1.6; font-size: 14px; }
.statuscard .owner-line { margin-top: 22px; font-size: 12px; color: var(--muted); }

/* ---------------- responsive ---------------- */
@media (max-width: 760px) {
  .shell { padding: 28px 0 48px; }
  .hero { padding: 22px; }
  .owner { text-align: left; }
  .formcard { padding: 22px; }
  .grid2 { grid-template-columns: 1fr; }
  .settingsGrid { grid-template-columns: 1fr; }
  .docx { padding: 28px 22px; }
  .stage { padding: 14px 10px 60px; }
  #watermark { font-size: 15px; }
  .linkrow { flex-direction: column; }
}

/* ---- viewer on small / touch screens ---- */
@media (max-width: 820px) {
  /* Page number + notice float at the bottom, in front of the blur/guard. */
  .pageHud { top: auto; bottom: calc(18px + env(safe-area-inset-bottom)); }
  .leaveWarning { top: auto; bottom: calc(58px + env(safe-area-inset-bottom)); left: 12px; right: 12px; transform: none; max-width: none; }
  /* Let the access chip wrap under the meta line instead of overlapping. */
  .fileinfo .fmeta { white-space: normal; }
  .fileinfo .accessInfo:not(:empty) { margin-left: 0; margin-top: 4px; }
}
@media (max-width: 600px) {
  .topbar { padding: 10px 14px; gap: 10px; }
  .topbar .vlogo { width: 32px; height: 32px; }
  .fileinfo .fname { font-size: 13.5px; }
  .fileinfo .fmeta { font-size: 11px; }
  .timerpill { padding: 6px 10px; font-size: 12.5px; gap: 5px; }
  .timerpill svg { width: 13px; height: 13px; }
  .pageHud { font-size: 12px; padding: 6px 12px; }
  .leaveWarning { font-size: 11.5px; padding: 10px 14px; }
  .guardPanel { padding: 22px 18px; gap: 13px; }
  #guard .shieldIcon { width: 48px; height: 48px; }
  #guardText { font-size: 13.5px; }
  .docx { padding: 22px 16px; }
  .audiocard, .genericcard { padding: 24px 20px; }
}
