/* Fira Code — self-hosted (CSP font-src 'self'), shared design with fdrian.me */
@font-face {
  font-family: 'Fira Code';
  src: url('../fonts/firacode/FiraCode-VF.ttf') format('truetype-variations');
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

/* ─── Design tokens (fdrian.me source of truth) ───────────────────────── */
:root {
  --bg:             #00000a;
  --bg-surface:     rgba(0, 0, 10, 0.82);
  --bg-subtle:      #090914;
  --text-primary:   #cdd6f4;
  --text-secondary: #6c7086;
  --text-muted:     #45475a;
  --accent:         #8826f9;
  --accent-dim:     rgba(136, 38, 249, 0.12);
  --accent-hover:   #9d3eff;
  --accent-cyan:    #00d4ff;
  --accent-cyan-dim: rgba(0, 212, 255, 0.12);
  --border:         #1e2030;
  --border-strong:  rgba(0, 212, 255, 0.35);
  --border-focus:   rgba(0, 212, 255, 0.5);
  --error:          #f7768e;
  --ok:             #9ece6a;
  --font: 'Fira Code', ui-monospace, monospace;
  --control-height: 40px;
}

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

html { color-scheme: dark; scrollbar-gutter: stable; scrollbar-color: var(--accent) var(--bg); }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 3px; }
::selection { background: var(--accent-dim); color: var(--text-primary); }
[hidden] { display: none !important; }

body {
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 60% 40% at 50% 0%, rgba(136, 38, 249, 0.11) 0%, transparent 68%),
    radial-gradient(ellipse 36% 28% at 82% 12%, rgba(0, 212, 255, 0.045) 0%, transparent 70%),
    repeating-linear-gradient(0deg, transparent, transparent 39px, rgba(136, 38, 249, 0.08) 39px, rgba(136, 38, 249, 0.08) 40px),
    repeating-linear-gradient(90deg, transparent, transparent 39px, rgba(0, 212, 255, 0.035) 39px, rgba(0, 212, 255, 0.035) 40px);
  background-size: auto, auto, 40px 40px, 40px 40px;
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 16px 64px;
  position: relative;
  -webkit-tap-highlight-color: rgba(136, 38, 249, 0.2);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0, rgba(255, 255, 255, 0.018) 1px, transparent 1px, transparent 4px);
  opacity: 0.16;
}

.wrap {
  width: 100%;
  max-width: 900px;
  padding: 24px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 10, 0.74);
  box-shadow: inset 0 1px 0 rgba(0, 212, 255, 0.06), 0 0 48px rgba(136, 38, 249, 0.08);
  position: relative;
  z-index: 1;
}
.wrap::before {
  content: "";
  position: absolute;
  top: -1px;
  left: -1px;
  right: -1px;
  height: 1px;
  background: linear-gradient(90deg, var(--accent), var(--accent-cyan), transparent);
  opacity: 0.72;
  pointer-events: none;
}
.skip-link {
  position: fixed; top: 10px; left: 10px; z-index: 10;
  background: var(--accent); color: var(--bg); padding: 8px 12px;
  font-size: 12px; font-weight: 700; text-decoration: none;
  transform: translateY(-160%); transition: transform 0.15s ease;
}
.skip-link:focus { transform: translateY(0); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

header {
  margin-bottom: 28px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
header::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 96px;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-cyan));
  box-shadow: 0 0 10px rgba(136, 38, 249, 0.6), 0 0 22px rgba(0, 212, 255, 0.2);
}
.logo {
  display: inline-block;
  font-size: 26px; font-weight: 700; letter-spacing: 1px;
  color: var(--text-primary); text-decoration: none;
  text-shadow: 0 0 14px rgba(136, 38, 249, 0.35), 0 0 36px rgba(0, 212, 255, 0.1);
}
.logo b { color: var(--accent); }
.logo .cursor { color: var(--accent-cyan); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 0%,55% { opacity: 1; } 56%,100% { opacity: 0; } }
@keyframes riseIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.tagline {
  color: var(--text-secondary);
  font-size: 12px;
  letter-spacing: 1px;
  margin-top: 6px;
  text-transform: uppercase;
}
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(0, 212, 255, 0.04);
  padding: 22px;
  position: relative;
}
.panel::before {
  content: "";
  position: absolute;
  top: -1px;
  left: -1px;
  right: -1px;
  height: 1px;
  background: linear-gradient(90deg, var(--accent), var(--accent-cyan), transparent);
  opacity: 0.42;
  pointer-events: none;
}

/* ─── Tabs ────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; margin-bottom: -1px; border: 1px solid var(--border); }
.tab {
  flex: 1; background: transparent; border: none; border-right: 1px solid var(--border);
  color: var(--text-secondary); font-family: var(--font); font-size: 12px;
  letter-spacing: 2px; text-transform: uppercase; padding: 10px 18px; cursor: pointer;
  min-height: var(--control-height); touch-action: manipulation;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.tab:last-child { border-right: none; }
.tab:hover { color: var(--text-primary); background: rgba(255, 255, 255, 0.03); }
.tab.active {
  color: var(--accent);
  background: linear-gradient(180deg, rgba(136, 38, 249, 0.12), rgba(136, 38, 249, 0.035));
  box-shadow: inset 0 -2px 0 var(--accent), inset 0 1px 0 rgba(0, 212, 255, 0.08);
}

/* ─── Dropzone ────────────────────────────────────────────────────────── */
#dropzone {
  width: 100%; color: var(--text-primary); font-family: var(--font);
  border: 1px dashed var(--border); background: rgba(0, 0, 10, 0.58);
  min-height: 340px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: border-color 0.15s, background 0.15s; text-align: center;
}
#dropzone:hover, #dropzone.drag { border-color: var(--accent); background: var(--accent-dim); }
.dz-icon { font-size: 34px; color: var(--accent); margin-bottom: 12px; }
.dz-link { color: var(--accent-cyan); text-decoration: underline; }
.dz-types { color: var(--text-muted); font-size: 12px; margin-top: 12px; letter-spacing: 1px; }

/* ─── File card (viewer) ──────────────────────────────────────────────── */
.file-card {
  display: flex; align-items: center; gap: 16px; justify-content: space-between;
  background: var(--bg-surface); border: 1px solid var(--border); padding: 16px 18px;
}
.file-info { min-width: 0; }
.file-name { color: var(--text-primary); font-size: 14px; word-break: break-all; }
.file-meta { color: var(--text-secondary); font-size: 12px; margin-top: 4px; }
a.btn.btn-primary { text-decoration: none; display: inline-block; }
#imgPreview { width: auto; height: auto; max-width: 100%; margin-top: 14px; border: 1px solid var(--border); display: block; }

/* ─── Editor ──────────────────────────────────────────────────────────── */
textarea#content {
  width: 100%;
  min-height: 340px;
  resize: vertical;
  background: rgba(0, 0, 10, 0.58);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  padding: 16px;
  tab-size: 2;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea#content::placeholder { color: var(--text-muted); }

.controls {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: center;
  margin-top: 16px;
}
.field { display: flex; align-items: center; gap: 8px; }
.field label { color: var(--text-secondary); font-size: 12px; letter-spacing: 1px; text-transform: uppercase; }

select, .btn {
  background: rgba(0, 0, 10, 0.72);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 13px;
  min-height: var(--control-height);
  padding: 9px 14px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
select { color-scheme: dark; }
select option { background: var(--bg-surface); color: var(--text-primary); }

.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; color: var(--text-secondary); font-size: 13px; }
.check input { accent-color: var(--accent); width: 17px; height: 17px; cursor: pointer; }

.btn-primary {
  margin-left: auto;
  border-color: var(--accent);
  color: var(--accent);
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 700;
}
.btn-primary:hover:not(:disabled) { background: var(--accent); color: var(--bg); box-shadow: 0 0 18px var(--accent-dim); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:active:not(:disabled), .tab:active { transform: translateY(1px); }

:where(a, button, select, textarea, input):focus-visible {
  outline: 2px solid var(--accent-cyan);
  outline-offset: 3px;
}
textarea#content:focus-visible, input#shareLink:focus-visible {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 1px var(--border-focus), 0 0 16px rgba(0, 212, 255, 0.08) inset;
}

.hint { color: var(--text-muted); font-size: 12px; margin-top: 14px; line-height: 1.7; }
.hint b { color: var(--text-secondary); font-weight: 400; }
kbd {
  background: var(--bg-subtle); border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 3px; padding: 1px 6px; font-size: 11px; color: var(--accent-cyan);
}

#status { margin-top: 14px; font-size: 13px; color: var(--accent-cyan); min-height: 18px; }
#status.err { color: var(--error); }

/* ─── Result ──────────────────────────────────────────────────────────── */
#result { margin-top: 8px; }
.result-title { color: var(--ok); font-size: 14px; letter-spacing: 1px; margin-bottom: 14px; }
.share-result {
  display: grid; grid-template-columns: minmax(0, 1fr) 206px; gap: 22px;
  align-items: stretch;
}
.share-details {
  display: flex; min-width: 0; flex-direction: column; justify-content: center;
}
.link-row { display: flex; gap: 8px; }
input#shareLink {
  flex: 1; background: var(--bg-surface); border: 1px solid var(--border);
  color: var(--text-primary); font-family: var(--font); font-size: 13px;
  min-width: 0; min-height: var(--control-height); padding: 11px 14px;
}
#resultMeta { color: var(--text-secondary); font-size: 12px; margin-top: 12px; }
.result-note { color: var(--text-muted); font-size: 12px; margin-top: 16px; line-height: 1.7; }
.qr-panel {
  align-self: center; background: var(--bg-surface); border: 1px solid var(--border-strong);
  box-shadow: inset 0 0 0 1px rgba(136, 38, 249, 0.06); padding: 10px 10px 8px;
  text-align: center;
}
#shareQr {
  display: block; width: 184px; height: 184px; image-rendering: pixelated;
  background: #fff;
}
.qr-panel span {
  display: block; color: var(--text-secondary); font-size: 10px; font-weight: 600;
  letter-spacing: 2px; padding: 8px 0 1px; text-transform: uppercase;
}
.qr-panel span.err { color: var(--error); letter-spacing: 0; text-transform: none; }

/* ─── Viewer (/p/<id>) ────────────────────────────────────────────────── */
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.view-head .meta { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 12px; }
.status-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 10px rgba(158, 206, 106, 0.55);
}
pre#content.viewer-pre {
  background: var(--bg-surface); border: 1px solid var(--border);
  padding: 18px; overflow-x: auto; white-space: pre-wrap; word-break: break-word;
  font-family: var(--font); font-size: 13.5px; line-height: 1.6; color: var(--text-primary);
  max-height: 70vh; overflow-y: auto;
}
#burnNotice {
  background: rgba(247, 118, 142, 0.08); border: 1px solid rgba(247, 118, 142, 0.2);
  color: var(--error); font-size: 12px; margin-top: 14px; padding: 10px 12px;
}
.state-panel { color: var(--text-secondary); font-size: 14px; }
#error { color: var(--error); }

footer {
  margin-top: 32px; padding-top: 14px; border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: 10px; letter-spacing: 1.5px;
  display: flex; gap: 16px; flex-wrap: wrap;
  text-transform: uppercase;
}
footer a { color: var(--text-muted); text-decoration: none; }
footer a:hover { color: var(--accent); }

@media (prefers-reduced-motion: no-preference) {
  header { animation: riseIn 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
  main { animation: riseIn 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) 0.08s both; }
  footer { animation: riseIn 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) 0.16s both; }
}

@media (max-width: 560px) {
  body {
    padding: calc(28px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right))
      calc(48px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  }
  .wrap { padding: 16px; }
  .panel { padding: 16px; }
  .logo { font-size: 21px; }
  .tagline { font-size: 10px; letter-spacing: 0.6px; }
  .btn-primary { margin-left: 0; width: 100%; }
  .controls { gap: 10px; }
  .share-result { grid-template-columns: 1fr; }
  .qr-panel { justify-self: center; }
  #shareQr { width: min(184px, 64vw); height: min(184px, 64vw); }
  .link-row { align-items: stretch; flex-direction: column; }
  .link-row .btn { width: 100%; }
  .file-card { align-items: flex-start; flex-direction: column; }
  .file-card .btn-primary { width: 100%; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
