:root {
  --page: #f7f5ef;
  --panel: #fffdf8;
  --ink: #171512;
  --muted: #686158;
  --line: #d8d0c2;
  --dark: #181715;
  --accent: #2f61e8;
  --accent-strong: #244ec4;
  --warn: #9d5200;
  --danger: #a32619;
  --ok: #1f7a43;
  --shadow: 0 18px 55px rgb(31 26 18 / 12%);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100dvh;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
}

button,
input,
textarea,
select {
  font: inherit;
}

[hidden] {
  display: none !important;
}

a {
  color: inherit;
}

.topbar {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 14px clamp(16px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  font-weight: 800;
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #f6b84b;
}

.topbar nav {
  display: flex;
  gap: 14px;
  align-items: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.upload-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 390px);
  gap: 24px;
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto;
}

.tool-surface,
.side-panel,
.admin-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.tool-surface {
  min-width: 0;
  padding: clamp(16px, 3vw, 28px);
}

.side-panel,
.admin-panel {
  padding: 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 4vw, 3.8rem);
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  font-size: 1.08rem;
}

.lede {
  max-width: 760px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
}

.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.button {
  gap: 8px;
  padding: 0 16px;
  font-weight: 720;
  text-decoration: none;
}

.button.primary:hover {
  background: var(--accent-strong);
}

.button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.input-stack {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 720;
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.field input {
  min-height: 42px;
  padding: 0 12px;
}

.field textarea {
  min-height: 280px;
  resize: vertical;
  padding: 12px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.86rem;
  line-height: 1.45;
}

.field input:focus-visible,
.field textarea:focus-visible,
.button:focus-visible,
.icon-button:focus-visible,
.text-button:focus-visible {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.source-well {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.source-well[data-dragging="true"] {
  border-color: var(--accent);
  background: #f4f7ff;
  box-shadow: inset 0 0 0 2px rgb(47 97 232 / 18%);
}

.source-well[data-busy="true"] {
  opacity: 0.92;
}

.source-well > input[type="file"] {
  display: none;
}

.source-well-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
}

.source-well h2 {
  margin-bottom: 4px;
}

.source-well-head p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.source-field textarea {
  min-height: 220px;
  background: #fffdfa;
}

.selected-source {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid #bcd1a0;
  border-radius: 8px;
  background: #f3f8ee;
  color: #314b22;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.text-button {
  min-height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-weight: 760;
}

.text-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.source-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.source-hints span {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7f5ef;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 720;
}

.upload-progress {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid #aabbea;
  border-radius: 8px;
  background: #f2f5ff;
  color: #1d367e;
}

.upload-progress p {
  margin: 3px 0 0;
  color: #52628c;
  font-size: 0.88rem;
}

.progress-spinner {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border: 3px solid rgb(47 97 232 / 20%);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.certify-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.actions,
.result-actions,
.viewer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.result {
  display: grid;
  gap: 14px;
  margin-top: 22px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.url-output {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f4f1ea;
  font-family: "SFMono-Regular", Consolas, monospace;
  overflow-wrap: anywhere;
}

.notice-list,
.stats-list {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.notice-list li,
.stats-list li {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.notice-list li[data-kind="warning"] {
  border-color: #edc37f;
  color: var(--warn);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  max-width: min(420px, calc(100% - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--dark);
  color: white;
  box-shadow: var(--shadow);
}

.viewer-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100dvh;
  background: #181715;
  color: #fbfaf6;
}

.viewer-shell .topbar {
  background: #181715;
  border-color: #302b25;
  color: #fbfaf6;
}

.viewer-topbar {
  position: relative;
  gap: 12px;
  min-height: 58px;
  padding: 8px 12px;
}

.viewer-title-group,
.viewer-toolbar,
.viewer-nav,
.view-size-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.viewer-title-group {
  min-width: 220px;
  flex: 1 1 280px;
}

.viewer-toolbar {
  flex: 2 1 620px;
  justify-content: flex-end;
}

.viewer-title {
  min-width: 0;
  color: #d8d0c2;
  font-size: 0.92rem;
  font-weight: 720;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slide-position {
  min-width: 58px;
  color: #bfb7aa;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.viewer-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid #3d372f;
  border-radius: 8px;
  background: #24211d;
  color: #fbfaf6;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 760;
  text-decoration: none;
  white-space: nowrap;
}

.viewer-tool:hover {
  border-color: #5a5146;
  background: #2e2a25;
}

.viewer-tool:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.viewer-tool[aria-pressed="true"] {
  border-color: #f6b84b;
  background: #f6b84b;
  color: #181715;
}

.viewer-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 26px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23fbfaf6' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
}

.viewer-select option {
  color: #181715;
  background: #fff;
}

.ai-polish-progress {
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 3px;
  overflow: hidden;
  background: rgb(246 184 75 / 16%);
}

.ai-polish-progress span {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -36%;
  width: 36%;
  background: #f6b84b;
  box-shadow: 0 0 18px rgb(246 184 75 / 46%);
  animation: ai-polish-indeterminate 1.1s ease-in-out infinite;
}

@keyframes ai-polish-indeterminate {
  0% {
    transform: translateX(0);
  }

  100% {
    transform: translateX(380%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-polish-progress span {
    animation-duration: 2.4s;
  }
}

.viewer-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 8px;
  overflow: auto;
}

.slide-frame-wrap {
  position: relative;
  width: min(calc(100vw - 16px), calc((100dvh - 74px) * var(--deck-ratio, 16 / 9)));
  max-width: none;
  aspect-ratio: var(--deck-ratio, 16 / 9);
  border: 1px solid #34302a;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 24px 80px rgb(0 0 0 / 32%);
}

.viewer-shell[data-view-size="fill"] .viewer-stage,
.viewer-shell[data-view-size="actual"] .viewer-stage {
  align-content: start;
  place-items: start center;
}

.viewer-shell[data-view-size="fill"] .slide-frame-wrap {
  width: calc(100vw - 16px);
}

.viewer-shell[data-view-size="actual"] .slide-frame-wrap {
  width: min(1280px, calc(100vw - 16px));
}

.slide-frame-wrap iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: white;
}

.icon-button {
  width: 34px;
  color: #fbfaf6;
  background: #24211d;
  border-color: #3d372f;
}

.report-form {
  position: fixed;
  top: 70px;
  right: 16px;
  z-index: 15;
  display: grid;
  gap: 10px;
  width: min(440px, calc(100% - 32px));
  margin: 0;
  padding: 14px;
  border: 1px solid #3d372f;
  border-radius: 8px;
  background: #24211d;
}

.admin-layout {
  display: grid;
  gap: 18px;
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.stat strong {
  display: block;
  font-size: 1.7rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
}

@media (max-width: 820px) {
  .upload-layout,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .viewer-topbar {
    align-items: center;
    flex-direction: row;
    overflow-x: auto;
  }

  .viewer-title-group {
    min-width: 180px;
    flex: 0 0 min(280px, 44vw);
  }

  .viewer-toolbar {
    flex: 0 0 auto;
    justify-content: flex-start;
  }

  .source-well-head {
    grid-template-columns: 1fr;
  }

  .source-well-head .button {
    width: 100%;
  }
}
