:root {
  --background: #f4f6f9;
  --surface: #ffffff;
  --ink: #172033;
  --muted: #697386;
  --line: #e2e7ef;
  --primary: #315efb;
  --primary-dark: #2348ca;
  --shadow: 0 18px 55px rgba(22, 32, 55, .10);
  --ease-out: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -10%, rgba(49, 94, 251, .09), transparent 34rem),
    var(--background);
  font-family: Pretendard, "Noto Sans KR", "Apple SD Gothic Neo", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { color: inherit; }

.hidden { display: none !important; }

.topbar {
  position: sticky;
  z-index: 30;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 68px;
  padding: 0 clamp(20px, 5vw, 72px);
  border-bottom: 1px solid rgba(226, 231, 239, .8);
  background: rgba(247, 248, 251, .82);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  color: var(--ink);
  font-size: 15px;
  font-weight: 760;
  letter-spacing: -.02em;
  text-decoration: none;
}

.brand-mark {
  width: 20px;
  height: 23px;
  border-radius: 5px 5px 7px 7px;
  background: linear-gradient(145deg, #6686ff, #315efb 65%);
  box-shadow: 0 5px 12px rgba(49, 94, 251, .28);
  transform: rotate(3deg);
}

.view {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  animation: view-enter 360ms var(--ease-out) both;
}

.upload-view, .progress-view, .error-view {
  display: grid;
  min-height: calc(100vh - 68px);
  place-items: center;
  padding: 48px 0 84px;
}

.drop-zone {
  position: relative;
  width: min(760px, 100%);
  padding: clamp(54px, 9vw, 92px) 28px;
  overflow: hidden;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 26px;
  outline: none;
  background: rgba(255, 255, 255, .88);
  box-shadow: var(--shadow);
  transition: transform 220ms var(--ease-out), border-color 220ms, box-shadow 220ms, background 220ms;
}

.drop-zone::before {
  position: absolute;
  inset: 12px;
  content: "";
  pointer-events: none;
  border: 1px dashed #cbd3e1;
  border-radius: 18px;
  transition: border-color 180ms, background 180ms;
}

.drop-zone:hover, .drop-zone:focus-visible, .drop-zone.dragging {
  border-color: rgba(49, 94, 251, .38);
  transform: translateY(-3px);
  box-shadow: 0 24px 70px rgba(25, 43, 84, .14);
}

.drop-zone.dragging::before {
  border-color: var(--primary);
  background: rgba(49, 94, 251, .045);
}

.upload-icon {
  display: grid;
  width: 58px;
  height: 58px;
  margin: 0 auto 26px;
  border-radius: 18px;
  color: var(--primary);
  background: #edf1ff;
  place-items: center;
}

.upload-icon svg {
  width: 27px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .15em;
}

h1 { margin: 0; font-size: clamp(29px, 4.5vw, 44px); letter-spacing: -.045em; }
.lead { margin: 17px 0 30px; color: var(--muted); font-size: 16px; line-height: 1.7; }
.limit-text { margin: 16px 0 0; color: #9099aa; font-size: 12px; }

.primary-button, .ghost-button {
  border: 0;
  cursor: pointer;
  transition: transform 150ms var(--ease-out), background 150ms, box-shadow 150ms;
}

.primary-button {
  min-width: 132px;
  padding: 13px 22px;
  border-radius: 11px;
  color: white;
  background: var(--primary);
  box-shadow: 0 8px 22px rgba(49, 94, 251, .24);
  font-weight: 720;
}

.primary-button:hover { background: var(--primary-dark); transform: translateY(-2px); }
.primary-button:active, .ghost-button:active { transform: scale(.96); }

.ghost-button {
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,.72);
  font-size: 13px;
  font-weight: 700;
}
.ghost-button:hover { background: white; border-color: #cbd3e1; }

.progress-panel, .error-panel {
  width: min(650px, 100%);
  padding: 62px 32px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255,255,255,.9);
  box-shadow: var(--shadow);
}

.processing-orbit {
  position: relative;
  width: 62px;
  height: 62px;
  margin: 0 auto 25px;
  border: 1px solid #dbe3fa;
  border-radius: 50%;
}
.processing-orbit::before { position: absolute; inset: 14px; content: ""; border-radius: 50%; background: #edf1ff; }
.processing-orbit span { position: absolute; inset: -1px; animation: orbit 1.15s linear infinite; }
.processing-orbit span::after { position: absolute; top: 1px; left: 28px; width: 7px; height: 7px; content: ""; border-radius: 50%; background: var(--primary); box-shadow: 0 0 14px rgba(49,94,251,.6); }

.document-name { margin: 16px auto 32px; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.progress-track { height: 4px; overflow: hidden; border-radius: 20px; background: #e9edf4; }
.progress-track span { display: block; width: 34%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, transparent, var(--primary), transparent); animation: progress-slide 1.45s ease-in-out infinite; }
.progress-meta { display: flex; justify-content: space-between; gap: 20px; margin-top: 14px; color: var(--muted); font-size: 13px; text-align: left; }
.progress-meta time { flex: none; color: #8a94a7; font-variant-numeric: tabular-nums; }

.result-view { padding: 76px 0 110px; }
.result-heading { margin: 0 auto 45px; text-align: center; }
.result-summary { margin: 14px 0 0; color: var(--muted); }

.gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
  align-items: center;
  justify-content: center;
}

.result-card {
  width: clamp(276px, var(--card-width, 330px), 440px);
  padding: 11px;
  cursor: zoom-in;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 5px 18px rgba(25, 34, 52, .055);
  outline: none;
  animation: card-enter 400ms var(--ease-out) backwards;
  animation-delay: min(calc(var(--card-index) * 35ms), 350ms);
  transform-origin: center;
  transition: transform 220ms var(--ease-out), box-shadow 220ms, border-color 190ms;
}

.result-card:hover, .result-card:focus-visible {
  z-index: 2;
  border-color: rgba(49, 94, 251, .28);
  transform: translateY(-6px) scale(1.025);
  box-shadow: 0 13px 28px rgba(23, 34, 61, .11), 0 4px 9px rgba(23, 34, 61, .055);
}
.result-card:active { transform: translateY(-1px) scale(.985); }

.thumbnail-frame {
  position: relative;
  display: grid;
  min-height: 120px;
  overflow: hidden;
  border-radius: 10px;
  background: #f5f6f8;
  place-items: center;
}
.thumbnail-frame img { display: block; width: 100%; height: auto; max-height: 430px; object-fit: contain; background: white; }
.card-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 1px 5px 10px;
}
.card-title {
  max-width: 100%;
  margin: 0;
  padding: 5px 10px 6px;
  color: #fff;
  border-radius: 7px;
  background: rgba(24, 126, 59, .94);
  box-shadow: 0 3px 10px rgba(17, 90, 42, .22);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -.018em;
  text-align: center;
}
.card-meta {
  display: flex;
  justify-content: center;
  width: 100%;
  font-size: 12px;
}
.card-unit {
  max-width: 100%;
  padding: 4px 8px 5px;
  overflow: hidden;
  color: #493b00;
  border-radius: 6px;
  background: rgba(255, 220, 72, .95);
  box-shadow: 0 3px 9px rgba(107, 83, 0, .16);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-page {
  position: absolute;
  right: 6px;
  bottom: 6px;
  min-width: 27px;
  padding: 3px 5px 4px;
  color: #fff;
  border-radius: 5px;
  background: rgba(18, 23, 32, .94);
  box-shadow: 0 2px 7px rgba(0, 0, 0, .2);
  font-size: 11px;
  font-weight: 400;
  line-height: 1;
  text-align: center;
}

.empty-state { padding: 90px 24px; color: var(--muted); text-align: center; border: 1px dashed #cfd6e2; border-radius: 20px; background: rgba(255,255,255,.54); }
.empty-state h2 { margin: 0 0 8px; color: var(--ink); }
.empty-state p { margin: 0; }

.error-icon { display: grid; width: 54px; height: 54px; margin: 0 auto 22px; color: #c2413b; border-radius: 17px; background: #fff0ef; place-items: center; font-size: 25px; font-weight: 800; }
.error-panel p { margin: 16px auto 28px; color: var(--muted); line-height: 1.6; }

.lightbox {
  position: fixed;
  z-index: 100;
  inset: 0;
  overscroll-behavior: contain;
}
.lightbox[hidden] { display: none; }
.lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 38, .66);
  backdrop-filter: blur(0);
  opacity: 0;
  transition: opacity 190ms ease-out, backdrop-filter 230ms ease-out;
  will-change: opacity, backdrop-filter;
}
.lightbox-scroll {
  position: relative;
  z-index: 1;
  display: flex;
  width: 100%;
  height: 100%;
  padding: 24px;
  overflow: hidden;
  outline: none;
  overscroll-behavior: contain;
}
.lightbox-content {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  width: min(1000px, calc(100vw - 48px));
  height: min(760px, calc(100vh - 48px));
  min-width: 0;
  min-height: 0;
  margin: auto;
  overflow: hidden;
  border: 1px solid rgba(189, 198, 211, .95);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 28px 90px rgba(7, 14, 28, .38), 0 6px 20px rgba(7, 14, 28, .18);
  opacity: 0;
  transform: translateY(10px) scale(.985);
  transform-origin: center 46%;
  transition:
    opacity 180ms ease-out,
    transform 240ms cubic-bezier(.22, 1, .36, 1),
    box-shadow 240ms ease-out;
  will-change: opacity, transform;
}
.lightbox.open .lightbox-backdrop { opacity: 1; backdrop-filter: blur(5px); }
.lightbox.open .lightbox-content { opacity: 1; transform: translateY(0) scale(1); }
.lightbox.closing .lightbox-content {
  opacity: 0;
  transform: translateY(5px) scale(.99);
  transition-duration: 145ms;
  transition-timing-function: ease-in;
}
.lightbox.closing .lightbox-backdrop { opacity: 0; }
.lightbox-header {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 58px;
  padding: 10px 11px 10px 18px;
  border-bottom: 1px solid #e4e8ee;
  background: linear-gradient(#fff, #fafbfc);
}
.lightbox-heading {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 7px;
  overflow: hidden;
  white-space: nowrap;
}
.lightbox-title {
  overflow: hidden;
  font-size: 14px;
  font-weight: 780;
  letter-spacing: -.02em;
  text-overflow: ellipsis;
}
.lightbox-title-separator {
  flex: none;
  color: #a1a9b5;
}
.lightbox-unit {
  flex: none;
  color: #667085;
  font-size: 12px;
  font-weight: 650;
}
.lightbox-tab-strip {
  position: relative;
  z-index: 1;
  display: flex;
  height: 43px;
  padding: 8px 16px 0;
  border-bottom: 1px solid #d9dee7;
  background: #f3f5f8;
}
.lightbox-tabs, .lightbox-toolbar {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
}
.lightbox-tab {
  position: relative;
  bottom: -1px;
  min-width: 74px;
  height: 35px;
  padding: 0 16px;
  cursor: pointer;
  color: #70798a;
  border: 1px solid transparent;
  border-bottom-color: transparent;
  border-radius: 8px 8px 0 0;
  background: transparent;
  font-size: 12px;
  font-weight: 720;
  transition: color 150ms, background 150ms, border-color 150ms;
}
.lightbox-tab:hover { color: #26334b; background: rgba(255, 255, 255, .58); }
.lightbox-tab.active {
  color: #244fdb;
  border-color: #d9dee7;
  border-bottom-color: #fff;
  background: #fff;
}
.image-action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  cursor: pointer;
  color: #344054;
  border: 1px solid #d7dde6;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .06);
  font-size: 12px;
  font-weight: 700;
  transition: transform 150ms var(--ease-out), background 150ms, border-color 150ms;
}
.image-action-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.image-action-button:hover {
  border-color: #b8c2d1;
  background: #f5f7fa;
  transform: translateY(-1px);
}
.image-action-button:active { transform: scale(.97); }
.close-button {
  width: 34px;
  padding: 0;
  color: #667085;
}
.close-button:hover {
  color: #b42318;
  border-color: #f0b9b4;
  background: #fff5f4;
}
.close-button svg { width: 17px; height: 17px; }
.lightbox-workspace {
  min-width: 0;
  min-height: 0;
  padding: 14px;
  background: #fff;
  opacity: .72;
  transform: translateY(3px);
  transition: opacity 180ms ease-out 45ms, transform 210ms var(--ease-out) 35ms;
}
.lightbox.open .lightbox-workspace {
  opacity: 1;
  transform: translateY(0);
}
.lightbox.closing .lightbox-workspace {
  opacity: .9;
  transform: none;
  transition-duration: 100ms;
  transition-delay: 0ms;
}
.lightbox-panel {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}
.image-panel {
  position: relative;
  display: flex;
  padding: 10px;
  overflow: auto;
  border: 1px solid #d9dee7;
  border-radius: 8px;
  background: #e9edf2;
  overscroll-behavior: contain;
}
.image-panel > img {
  display: block;
  flex: none;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  /* Auto margins center a fitting image on both axes. When the image is
     larger than the viewport they collapse to zero, preserving a reachable
     top-left scroll origin. */
  margin: auto;
  background: #fff;
  box-shadow: 0 3px 13px rgba(18, 27, 43, .14);
  opacity: 0;
  transition: opacity 180ms;
}
.image-panel > img.loaded { opacity: 1; }
.text-panel {
  margin: 0;
  padding: 22px;
  overflow: auto;
  color: #202634;
  border: 1px solid #d9dee7;
  border-radius: 8px;
  outline: none;
  background: #fbfcfd;
  box-shadow: inset 0 1px 2px rgba(16, 24, 40, .035);
  font-family: "Cascadia Mono", "D2Coding", Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  tab-size: 4;
  white-space: pre;
  user-select: text;
}
.lightbox-panel[hidden] { display: none; }
.image-loader { position: absolute; z-index: 1; top: calc(50% - 18px); left: calc(50% - 18px); width: 36px; height: 36px; border: 3px solid rgba(255,255,255,.46); border-top-color: #315efb; border-radius: 50%; animation: orbit .85s linear infinite; }
.image-loader.hidden { display: none; }

@keyframes view-enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes card-enter { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes orbit { to { transform: rotate(360deg); } }
@keyframes progress-slide { from { transform: translateX(-110%); } to { transform: translateX(300%); } }

@media (max-width: 640px) {
  .topbar { height: 60px; padding: 0 16px; }
  .brand { font-size: 14px; }
  .view { width: min(100% - 22px, 1480px); }
  .upload-view, .progress-view, .error-view { min-height: calc(100vh - 60px); padding: 24px 0 50px; }
  .drop-zone { padding: 64px 20px; border-radius: 20px; }
  .result-view { padding: 48px 0 80px; }
  .gallery { gap: 15px; }
  .result-card { width: 100%; }
  .lightbox-scroll { padding: 12px; }
  .lightbox-header { flex-wrap: wrap; gap: 8px; padding: 10px 10px 9px 13px; }
  .lightbox-heading { width: 100%; }
  .lightbox-toolbar { width: 100%; justify-content: flex-end; }
  .lightbox-tabs, .lightbox-toolbar { gap: 4px; }
  .lightbox-tab { height: 32px; padding: 0 9px; font-size: 11px; }
  .image-action-button { height: 32px; padding: 0 9px; font-size: 11px; }
  .close-button { width: 32px; padding: 0; }
  .lightbox-tab-strip { height: 40px; padding: 8px 12px 0; }
  .lightbox-workspace { padding: 9px; }
  .image-panel { padding: 6px; }
  .text-panel { padding: 14px; font-size: 12px; }
  .progress-meta { flex-direction: column; gap: 6px; text-align: center; }
  .progress-meta time { text-align: center; }
}

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