:root {
  --bg: #2d2d2d;
  --bg-deep: #232323;
  --ink: #f2f2f2;
  --muted: #b3b3b3;
  --accent: #2a82da;
  --accent-dark: #1f6cb8;
  --success: #2e7d32;
  --success-dark: #256628;
  --card: #303030;
  --border: #444444;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --radius: 10px;
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top right, #3b3b3b, #2a2a2a 45%, #202020 100%);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.preview-shell {
  width: 100%;
  margin: 0 auto;
  padding: 0 12px;
}

@media (min-width: 576px) {
  .preview-shell {
    max-width: 540px;
  }
}

@media (min-width: 768px) {
  .preview-shell {
    max-width: 720px;
  }
}

@media (min-width: 992px) {
  .preview-shell {
    max-width: 960px;
  }
}

@media (min-width: 1200px) {
  .preview-shell {
    max-width: 1140px;
  }
}

@media (min-width: 1400px) {
  .preview-shell {
    max-width: 1320px;
  }
}

.preview-header {
  border-bottom: 1px solid var(--border);
  background: rgba(45, 45, 45, 0.9);
  color: var(--ink);
}

.preview-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 0;
}

.preview-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  align-items: baseline;
}

.preview-logo {
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 2rem;
  color: var(--ink);
}

.preview-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--accent);
}

.preview-actions {
  display: flex;
  gap: 12px;
}

.preview-link {
  text-decoration: none;
  color: #111111;
  border: 1px solid #d0d0d0;
  padding: 8px 14px;
  border-radius: var(--radius);
  background: transparent;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.preview-link--primary {
  background: var(--success);
  border-color: var(--success);
  color: #ffffff;
}

.preview-link--primary:hover {
  background: var(--success-dark);
  border-color: var(--success-dark);
}

.preview-link--ghost {
  color: var(--ink);
  border-color: var(--border);
}

.preview-link--ghost:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: #5a5a5a;
}

.preview-link:not(.preview-link--primary):not(.preview-link--ghost):hover {
  background: rgba(17, 17, 17, 0.08);
  border-color: #c2c2c2;
}

.preview-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 32px 0 48px;
}

.preview-main__inner {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.preview-card {
  background: var(--card);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.preview-card h2,
.preview-card h3 {
  margin-top: 0;
}

.preview-button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

@media (hover: hover) and (pointer: fine) {
  .preview-button:hover {
    background: var(--accent-dark);
    transform: translateY(-1px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
  }
}

.preview-button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
}

.upload-zone {
  margin-top: 16px;
  padding: 24px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: #2a2a2a;
}

.upload-zone.is-drag {
  border-color: var(--accent);
  background: #1f2b3a;
}

.upload-zone input[type="file"] {
  display: none;
}

.upload-copy {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.upload-main {
  color: var(--muted);
  font-weight: 600;
}

.upload-status {
  margin-top: 12px;
  color: var(--muted);
}

.preview-info ul {
  padding-left: 20px;
  margin: 0;
}

.preview-toolbar {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.preview-share {
  flex: 0 0 auto;
  background: var(--card);
  padding: 16px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.preview-file {
  flex: 0 0 auto;
  background: var(--card);
  padding: 16px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.preview-file__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.preview-file__label {
  font-weight: 600;
  line-height: 1.2;
}

.preview-file__name {
  display: block;
  color: var(--ink);
  word-break: break-all;
}

.preview-stats {
  flex: 0 0 auto;
  background: var(--card);
  padding: 16px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.preview-stats__content {
  margin-top: 0;
  overflow: hidden;
  transition: max-height 0.25s ease;
}

.preview-stats__section {
  border-top: 1px solid var(--border);
  margin-top: 10px;
  padding-top: 10px;
}

.preview-stats__label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.preview-stats__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  line-height: 1.35;
}

.preview-stats__row--total {
  font-weight: 600;
  color: var(--accent);
}

.preview-stats__row + .preview-stats__row {
  margin-top: 4px;
}

.preview-stats--inline {
  margin-top: 0;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  box-shadow: none;
  padding: 12px 14px;
  overflow: hidden;
  transition: margin 0.25s ease, padding 0.25s ease, opacity 0.2s ease, border-color 0.25s ease;
}

.preview-stats.is-collapsed .preview-stats__content {
  max-height: 0;
}

.preview-stats--inline.is-collapsed {
  margin-top: -26px;
  padding-top: 0;
  padding-bottom: 0;
  border-color: transparent;
  opacity: 0;
}

@media (min-width: 900px) {
  .preview-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .preview-share,
  .preview-file,
  .preview-stats {
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
  }
}

.preview-share label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
}

.preview-hint {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}

.share-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.share-row input {
  flex: 1 1 280px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-deep);
  color: var(--ink);
}

.preview-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.panel-thumb {
  text-align: left;
  padding: 0;
  color: inherit;
  appearance: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #2b2b2b;
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.panel-thumb:hover {
  transform: translateY(-2px);
}

.panel-thumb__label {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #353535;
}

.panel-thumb__preview {
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #262626;
}

.panel-thumb__preview svg {
  width: 100%;
  height: 100%;
}

.preview-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.preview-modal.is-open {
  display: flex;
}

.preview-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.preview-modal__panel {
  position: relative;
  background: #2d2d2d;
  border-radius: var(--radius);
  width: min(680px, 92vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 40px 80px rgba(0, 0, 0, 0.3);
  z-index: 1;
}

.preview-modal--viewer .preview-modal__panel {
  width: min(1400px, 98vw);
  height: min(92vh, 1000px);
}

.preview-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.preview-modal__header h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.preview-modal__body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  overflow: auto;
}

#qrModal .preview-modal__panel {
  overflow: hidden;
  width: min(420px, 90vw);
}

#qrModal .preview-modal__body {
  background: #ffffff;
  color: #111111;
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
  gap: 32px;
  padding: 18px 20px 24px;
}

#qrModal .preview-button.ghost {
  background: #2d2d2d;
  color: #ffffff;
  border: 1px solid #444444;
}

.preview-modal--viewer .preview-modal__body {
  flex: 1;
  padding: 12px;
}

.preview-modal__footer {
  padding: 12px 20px 18px;
  color: var(--muted);
  font-size: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.preview-modal__close {
  border: none;
  background: transparent;
  font-size: 24px;
  color: var(--ink);
  cursor: pointer;
}

.viewer-reset {
  border: none;
  background: transparent;
  color: var(--ink);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.viewer-reset:hover {
  background: rgba(255, 255, 255, 0.08);
}

#qrCode {
  width: 180px;
  height: 180px;
  background: #ffffff;
  padding: 8px;
  border-radius: var(--radius);
}

.preview-modal--viewer.is-mobile-viewer {
  align-items: stretch;
  justify-content: stretch;
}

.preview-modal--viewer.is-mobile-viewer .preview-modal__backdrop {
  display: none;
}

.preview-modal--viewer.is-mobile-viewer .preview-modal__panel {
  width: 100vw;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  max-height: none;
  border-radius: 0;
}

.preview-modal--viewer.is-mobile-viewer .preview-modal__header,
.preview-modal--viewer.is-mobile-viewer .preview-modal__footer {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 2;
  background: rgba(45, 45, 45, 0.45);
  backdrop-filter: blur(8px);
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.preview-modal--viewer.is-mobile-viewer .preview-modal__header {
  top: 0;
}

.preview-modal--viewer.is-mobile-viewer .preview-modal__footer {
  bottom: 0;
}

.preview-modal--viewer.is-mobile-viewer.chrome-hidden .preview-modal__header {
  transform: translateY(-100%);
  opacity: 0;
}

.preview-modal--viewer.is-mobile-viewer.chrome-hidden .preview-modal__footer {
  transform: translateY(100%);
  opacity: 0;
}

.preview-modal--viewer.is-mobile-viewer .preview-modal__body {
  padding: 0;
}

.preview-modal--viewer.is-mobile-viewer .viewer-stage {
  border-radius: 0;
}

.viewer-stage {
  width: 100%;
  height: 100%;
  background: #202020;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  touch-action: none;
  cursor: grab;
}

.viewer-stage svg {
  width: 100%;
  height: 100%;
}

.viewer-stage.is-dragging {
  cursor: grabbing;
}

.viewer-stage,
.viewer-stage * {
  -webkit-user-select: none;
  user-select: none;
}

.viewer-layer {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: center center;
}

.preview-empty {
  color: var(--muted);
}

@media (max-width: 900px) {
  .preview-header__inner {
    min-height: 56px;
  }

  .preview-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .preview-share {
    flex: 1 1 auto;
  }

  .panel-thumb__preview {
    height: 200px;
  }

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

@media (max-width: 900px) and (orientation: portrait) {
  .preview-header__inner {
    flex-direction: column;
    align-items: center;
    min-height: auto;
    gap: 10px;
  }

  .preview-brand {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .preview-actions {
    width: 100%;
    justify-content: center;
    padding-bottom: 12px;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  .preview-shell {
    max-width: none;
    padding: 0 12px;
  }
}

@media (max-width: 600px) {
  .preview-header {
    flex-direction: column;
    gap: 12px;
  }

  .preview-actions {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
  }

  .share-row {
    flex-direction: column;
    align-items: stretch;
  }

  .share-row input {
    flex: 0 0 auto;
    width: 100%;
  }

  .preview-modal--viewer .preview-modal__panel {
    width: 100vw;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
  }

  .preview-modal--viewer .preview-modal__header,
  .preview-modal--viewer .preview-modal__footer {
    position: absolute;
    left: 0;
    right: 0;
    z-index: 2;
    background: rgba(45, 45, 45, 0.45);
    backdrop-filter: blur(8px);
    transition: transform 0.25s ease, opacity 0.25s ease;
  }

  .preview-modal--viewer .preview-modal__header {
    top: 0;
  }

  .preview-modal--viewer .preview-modal__footer {
    bottom: 0;
  }

  .preview-modal--viewer.chrome-hidden .preview-modal__header {
    transform: translateY(-100%);
    opacity: 0;
  }

  .preview-modal--viewer.chrome-hidden .preview-modal__footer {
    transform: translateY(100%);
    opacity: 0;
  }
}

@media (max-width: 900px), (max-height: 500px) {
  .preview-modal--viewer {
    align-items: stretch;
    justify-content: stretch;
  }

  .preview-modal--viewer .preview-modal__backdrop {
    display: none;
  }

  .preview-modal--viewer .preview-modal__panel {
    width: 100vw;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
  }

  .preview-modal--viewer .preview-modal__header,
  .preview-modal--viewer .preview-modal__footer {
    position: absolute;
    left: 0;
    right: 0;
    z-index: 2;
    background: rgba(45, 45, 45, 0.45);
    backdrop-filter: blur(8px);
    transition: transform 0.25s ease, opacity 0.25s ease;
  }

  .preview-modal--viewer .preview-modal__header {
    top: 0;
  }

  .preview-modal--viewer .preview-modal__footer {
    bottom: 0;
  }

  .preview-modal--viewer.chrome-hidden .preview-modal__header {
    transform: translateY(-100%);
    opacity: 0;
  }

  .preview-modal--viewer.chrome-hidden .preview-modal__footer {
    transform: translateY(100%);
    opacity: 0;
  }

  .preview-modal--viewer .preview-modal__body {
    padding: 0;
  }

  .preview-modal--viewer .viewer-stage {
    border-radius: 0;
  }
}
