:root {
  --bg: #f7f7f8;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #111827;
  --shadow: 0 10px 30px rgba(17, 24, 39, 0.06);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
}

.page-shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.hero {
  padding: 4px 0 20px;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.hero-copy {
  margin: 10px 0 0;
  max-width: 40rem;
  font-size: 0.98rem;
  line-height: 1.5;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 440px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}

.control-panel {
  padding: 20px;
}

.viewer-panel {
  padding: 16px;
  min-height: 720px;
}

.deck-form {
  display: grid;
  gap: 20px;
}

.field {
  display: grid;
  gap: 10px;
  border: 0;
  padding: 0;
  margin: 0;
}

.field-label,
legend {
  padding: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  line-height: 1.5;
}

textarea:focus {
  outline: 2px solid rgba(17, 24, 39, 0.08);
  border-color: #9ca3af;
}

.controls-fold {
  border: 0;
}

.controls-fold > summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
  color: var(--muted);
}

.controls-fold > summary::-webkit-details-marker {
  display: none;
}

.controls-fold > summary::before {
  content: "\25B6\FE0E";
  display: inline-block;
  margin-right: 6px;
  font-size: 0.7em;
  transition: transform 160ms ease;
}

.controls-fold[open] > summary::before {
  transform: rotate(90deg);
}

.controls-fold > .controls-grid {
  margin-top: 14px;
}

.controls-grid {
  display: grid;
  gap: 16px;
}

.pill-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pill-grid.compact {
  gap: 8px;
}

.pill-option {
  position: relative;
  display: inline-flex;
}

.pill-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.pill-option span {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 0.92rem;
  line-height: 1.2;
  color: var(--ink);
  transition: border-color 140ms ease, background 140ms ease;
}

.pill-option input:checked + span {
  border-color: #111827;
  background: #f3f4f6;
}

.action-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  background: var(--brand);
  color: white;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

#clear-button {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.status {
  margin: 0;
  color: var(--muted);
}

.viewer-fold {
  border: 0;
}

.viewer-fold > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.viewer-fold > summary::-webkit-details-marker {
  display: none;
}

.viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.viewer-header > span {
  font-size: 1.05rem;
  font-weight: 600;
}

.viewer-fold:not([open]) > .viewer-header {
  margin-bottom: 0;
}

.ghost-link {
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 620px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
  background: #fafafa;
}

.viewer-frame {
  width: 100%;
  min-height: 720px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
}

.hidden {
  display: none !important;
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .viewer-panel {
    min-height: auto;
  }

  .viewer-frame {
    min-height: 560px;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100vw - 18px, 1440px);
    padding-top: 16px;
  }

  .control-panel,
  .viewer-panel {
    padding: 16px;
  }

  h1 {
    font-size: clamp(1.8rem, 10vw, 2.4rem);
  }
}
