*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); color: var(--ink); font: 400 14px/1.45 var(--ts-font-body); }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
:focus-visible { outline: 2px solid var(--ts-sun); outline-offset: 2px; }
/* pdf.js appends helper canvases to <body>; its own CSS hides them (see TerraSun PDF, the "goes black" bug). */
.hiddenCanvasElement { position: absolute; top: 0; left: 0; width: 0; height: 0; display: none; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 14px; height: 54px; padding: 0 14px; background: var(--ts-night); color: #fff; flex: none; }
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font: 600 17px var(--ts-font-head); white-space: nowrap; }
.brand b { color: var(--ts-sun-light); }
.spacer { flex: 1; }
.actions { display: flex; gap: 6px; }
.topbar .btn { color: #fff; border-color: rgba(255, 255, 255, .2); background: transparent; }
.topbar .btn:hover { background: rgba(255, 255, 255, .1); }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px; cursor: pointer; white-space: nowrap; font-weight: 500; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.icon { width: 34px; height: 34px; padding: 0; justify-content: center; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-accent:hover { filter: brightness(1.08); background: var(--accent); }
.btn.big { height: 46px; padding: 0 26px; font: 600 16px var(--ts-font-head); border-radius: 12px; }
select { height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); padding: 0 8px; }

/* Page */
.wrap { width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 16px 40px; flex: 1; }
.hero { text-align: center; padding: 34px 0 22px; background: radial-gradient(ellipse at 50% 140%, rgba(255, 183, 3, .22), transparent 60%); }
.hero h1 { font: 700 clamp(26px, 5vw, 38px)/1.15 var(--ts-font-head); margin: 0 0 8px; }
.hero h1 span { color: var(--ts-ember); }
.pitch { font-size: 16px; color: var(--muted); margin: 0 auto; max-width: 860px; text-wrap: balance; }
.pitch b { color: var(--ink); }

.converter { display: grid; grid-template-columns: minmax(0, 1fr) 34px minmax(0, 1fr); gap: 10px; align-items: stretch; }
.arrow { display: grid; place-items: center; color: var(--muted); }
.arrow svg { width: 26px; height: 26px; }
.pane { display: flex; flex-direction: column; min-height: 520px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.pane-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.pane-head label { font: 600 15px var(--ts-font-head); }
.pane-body { flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 14px; min-height: 0; }
.pane-foot { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.pane-foot .muted { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.drop { text-align: center; padding: 22px 16px 10px; border: 2px dashed var(--line); border-radius: 14px; }
.drop p { margin: 10px 0 0; }
#paste { flex: 1; min-height: 260px; width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); padding: 10px 12px; font: 13px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; tab-size: 2; }
.files { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow: auto; }
.files li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.files li.on { border-color: var(--accent); }
.files .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.files .tag { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: var(--line); }
.files .st { font-size: 12px; color: var(--muted); }
.files .st.bad { color: var(--ts-coral); }
.files li.more { border: 0; background: none; padding: 4px 0 0; }
.files li.more .btn { font-size: 14px; color: var(--ink); padding: 0 14px; }
.files .st.ready { color: var(--accent); cursor: pointer; text-decoration: underline; }
.files button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 4px; font-size: 16px; line-height: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); cursor: pointer; font-weight: 500; }
.chips button[aria-checked="true"] { background: var(--ts-sun); border-color: var(--ts-sun); color: var(--ts-night); font-weight: 600; }
.chips .none { color: var(--muted); font-size: 13px; }
.opts { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 8px 14px; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.opts:empty, .opts.empty { display: none; }
.opts label { display: inline-flex; align-items: center; gap: 6px; }
.opts select { height: 28px; }

.result { position: relative; overflow: auto; max-height: 640px; }
.empty { margin: auto; text-align: center; }
.busy { margin: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error { padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--ts-coral) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--ts-coral) 45%, transparent); }
.warnings { margin: 0; padding: 8px 12px 8px 28px; border-radius: 10px; background: color-mix(in srgb, var(--ts-sun) 16%, var(--surface)); font-size: 13px; }
.out-text { margin: 0; flex: 1; white-space: pre-wrap; word-break: break-word; font: 13px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; }
.out-table { overflow: auto; }
.out-table table { border-collapse: collapse; font-size: 13px; }
.out-table td, .out-table th { border: 1px solid var(--line); padding: 4px 8px; text-align: left; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.out-table th { background: var(--surface-2); font-weight: 600; }
.out-doc { background: #fff; color: #111; border-radius: 6px; padding: 24px 28px; box-shadow: inset 0 0 0 1px var(--line); line-height: 1.5; }
.out-doc img { max-width: 100%; height: auto; }
.out-doc table { border-collapse: collapse; }
.out-doc td, .out-doc th { border: 1px solid #ccc; padding: 4px 8px; }
.out-doc canvas { display: block; max-width: 100%; margin: 0 auto 14px; box-shadow: 0 1px 6px rgba(0, 0, 0, .25); }
.out-doc.pages { background: var(--canvas-bg, #ddd); padding: 14px; }

.popular { margin-top: 30px; }
.popular h2 { font: 600 18px var(--ts-font-head); margin: 0 0 10px; }
.popular nav { display: flex; flex-wrap: wrap; gap: 8px; }
.popular a { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; font-size: 13px; }
.popular a:hover { border-color: var(--accent); }

.dropzone-overlay { position: fixed; inset: 10px; z-index: 50; display: grid; place-items: center; border: 3px dashed var(--ts-sun); border-radius: 18px; background: rgba(11, 37, 64, .75); color: #fff; font: 600 24px var(--ts-font-head); pointer-events: none; }
.madeby { text-align: center; padding: 14px; font-size: 13px; border-top: 1px solid var(--line); background: var(--surface); }
.madeby a { color: var(--muted); text-decoration: none; }
.madeby a:hover { color: var(--ink); }
.madeby b { color: var(--ts-ember); }

.dialog { border: 0; border-radius: 16px; padding: 22px; width: min(620px, calc(100vw - 24px)); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.dialog::backdrop { background: rgba(11, 37, 64, .55); }
.dialog h2 { font: 600 20px var(--ts-font-head); margin: 0 0 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

@media (max-width: 860px) {
  .converter { grid-template-columns: minmax(0, 1fr); }
  .arrow { transform: rotate(90deg); height: 26px; }
  .pane { min-height: 0; }
  #paste { min-height: 180px; }
  .result { min-height: 220px; }
}
