:root {
  color-scheme: light dark;
  --bg: #f7f8fa;
  --fg: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
  --card: #fff;
  --line: #e5e7eb;
  --warn: #b45309;
  --err: #b91c1c;
  --ok: #16a34a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --fg: #e6e9ef;
    --muted: #9aa4b2;
    --accent: #6ea8fe;
    --card: #161a20;
    --line: #262b33;
    --warn: #fbbf24;
    --err: #f87171;
    --ok: #4ade80;
  }
}

* {
  box-sizing: border-box;
}

/* The `hidden` attribute must always win. An author `display` rule (grid/flex/block on
   .overlay, .frame, .btn, .error…) otherwise overrides the UA `[hidden]{display:none}`,
   leaving "hidden" elements painted — e.g. the loading overlay covering a rendered site. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 3rem 1.25rem 4rem;
}
h1 {
  font-size: 1.6rem;
  margin: 0 0 0.35rem;
  letter-spacing: -0.01em;
}
.lede {
  color: var(--muted);
  margin: 0 0 2rem;
}
.muted {
  color: var(--muted);
}
.spacer {
  flex: 1 1 auto;
}
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
  background: color-mix(in srgb, var(--fg) 8%, transparent);
  padding: 0.1em 0.35em;
  border-radius: 0.3em;
}

/* Drop zone */
.drop {
  display: grid;
  place-items: center;
  gap: 0.35rem;
  padding: 3rem 1.5rem;
  border: 2px dashed var(--line);
  border-radius: 14px;
  background: var(--card);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.drop:hover, .drop:focus-visible {
  border-color: var(--accent);
  outline: none;
}
.drop.is-over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--card));
}
.drop__icon {
  width: 2.25rem;
  height: 2.25rem;
  color: var(--muted);
}
.drop__title {
  font-weight: 600;
  margin: 0.5rem 0 0;
}
.drop__hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}
.drop__note {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0.75rem 0 0;
  max-width: 30rem;
}
.drop__actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}
.pick {
  display: contents;
}
.pick[hidden] {
  display: none;
}

/* The file inputs stay focusable (so keyboard and AT users can reach them) but are not
   painted; the <label> is the visible control. `display:none` would make the label's
   activation behaviour unreliable and remove it from the tab order entirely. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.sr-only:focus-visible + .btn {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Status panel */
.panel {
  margin-top: 1.5rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}
.row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 1rem 0 0.4rem;
}

.dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.dot.is-live {
  background: var(--ok);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.url {
  flex: 1 1 18rem;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.55em 0.75em;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.btn svg {
  width: 1em;
  height: 1em;
  flex: none;
}

.warn, .error {
  display: flex;
  align-items: flex-start;
  gap: 0.5em;
  font-size: 0.85rem;
  margin: 1rem 0 0;
}
/* An author `display` value beats the `hidden` attribute's UA `display:none`, so restore it
   explicitly or a hidden .error/.warn would still occupy layout as an empty box. */
.warn[hidden], .error[hidden] {
  display: none;
}
.warn {
  color: var(--warn);
}
.error {
  color: var(--err);
}
.warn svg, .error svg {
  width: 1.1em;
  height: 1.1em;
  flex: none;
  margin-top: 0.15em;
}

.files {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0.75rem 0 0;
  border-top: 1px solid var(--line);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  color: var(--muted);
  max-height: 9rem;
  overflow-y: auto;
}
.files li {
  padding: 0.1rem 0;
}

/* An accessible switch: a real checkbox (role=switch) branded via appearance, per guidance —
   keep the native control, don't replace it. */
.toggle {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}
.toggle input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 2.4rem;
  height: 1.35rem;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  cursor: pointer;
  transition: background 0.15s ease;
}
.toggle input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(1.35rem - 4px);
  height: calc(1.35rem - 4px);
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}
.toggle input:checked {
  background: var(--accent);
}
.toggle input:checked::after {
  transform: translateX(calc(2.4rem - 1.35rem));
}
.toggle input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* List of persisted (re-seeded) sites shown at the top of the drop page. */
.restored {
  margin: 0 0 1.5rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-size: 0.85rem;
}
.restored h2 {
  font-size: 0.85rem;
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-weight: 600;
}
.restored ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.restored li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.3rem 0;
}
.restored li a {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.restored__remove {
  flex: none;
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
}
.restored__remove:hover {
  color: var(--err);
  background: color-mix(in srgb, var(--err) 12%, transparent);
}

.byline {
  margin-top: 2.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Upload confirmation dialog. showModal() centres it in the top layer; we only style the
   card and the backdrop. */
.confirm {
  border: 0;
  border-radius: 14px;
  padding: 0;
  max-width: 26rem;
  width: calc(100% - 2rem);
  background: var(--card);
  color: var(--fg);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}
.confirm::backdrop {
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.confirm form {
  margin: 0;
  padding: 1.5rem;
}
.confirm h2 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
}
.confirm__body {
  color: var(--muted);
  margin: 0 0 0.25rem;
}
.confirm__warn {
  display: flex;
  align-items: flex-start;
  gap: 0.5em;
  color: var(--warn);
  font-size: 0.85rem;
  margin: 0.75rem 0 1.25rem;
}
.confirm__warn svg {
  width: 1.1em;
  height: 1.1em;
  flex: none;
  margin-top: 0.15em;
}
.confirm__actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
}
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn--primary:hover {
  filter: brightness(1.1);
  color: #fff;
}
/* A gentle entrance; respects reduced-motion by not animating there. */
@media (prefers-reduced-motion: no-preference) {
  .confirm[open] {
    animation: confirm-in 0.15s ease-out;
  }
  @keyframes confirm-in {
    from {
      opacity: 0;
      transform: translateY(6px) scale(0.98);
    }
  }
}
a {
  color: var(--accent);
}

.btn--sm {
  font-size: 0.78rem;
  padding: 0.4em 0.6em;
}

/* Examples gallery */
.examples {
  margin-top: 2rem;
}
.examples__head {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}
.examples__head h2 {
  font-size: 1rem;
  margin: 0;
  margin-right: auto;
}
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}
.card {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--card);
  display: flex;
  flex-direction: column;
}
.card__thumb {
  position: relative;
  height: 150px;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: #0b0d12;
}
/* Render the example at desktop width, then scale down for a crisp thumbnail. */
.card__preview {
  position: absolute;
  top: 0;
  left: 0;
  width: 250%;
  height: 250%;
  border: 0;
  transform: scale(0.4);
  transform-origin: top left;
  pointer-events: none;
}
.card__body {
  padding: 0.85rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}
.card__body h3 {
  font-size: 0.95rem;
  margin: 0;
}
.card__body p {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0;
  flex: 1;
}
.card__actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* Inline IDE overlay */
.ide {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #0b0d12;
  color: #e8ecf6;
  display: flex;
  flex-direction: column;
}
.ide__bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid #1b2130;
  background: #10131b;
}
.ide__title {
  font-size: 0.95rem;
}
.ide .spacer {
  flex: 1;
}
.ide__grid {
  flex: 1;
  display: grid;
  grid-template-columns: 180px 1fr 1fr;
  min-height: 0;
}
.ide__files {
  border-right: 1px solid #1b2130;
  overflow-y: auto;
  background: #0d1017;
}
.ide__filelist {
  list-style: none;
  margin: 0;
  padding: 0.4rem;
}
.ide__file {
  display: flex;
  align-items: center;
  border-radius: 7px;
  padding: 0.05rem 0.1rem 0.05rem 0.2rem;
}
.ide__file.is-active {
  background: #1b2130;
}
.ide__filename {
  flex: 1;
  min-width: 0;
  text-align: left;
  font: inherit;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.8rem;
  color: #cdd6e6;
  background: none;
  border: 0;
  padding: 0.35rem 0.4rem;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ide__filedel {
  flex: none;
  background: none;
  border: 0;
  color: #6b7690;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.2rem 0.4rem;
  border-radius: 5px;
}
.ide__filedel:hover {
  color: #f87171;
}
.ide__rename {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.8rem;
  padding: 0.3rem 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: #06070c;
  color: #e8ecf6;
}
.ide__editwrap {
  min-width: 0;
  display: flex;
}
.ide__code {
  flex: 1;
  resize: none;
  border: 0;
  outline: none;
  padding: 1rem;
  background: #0b0d12;
  color: #e8ecf6;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  line-height: 1.55;
  tab-size: 2;
  white-space: pre;
}
.ide__previewwrap {
  border-left: 1px solid #1b2130;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.ide__previewbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.7rem;
  border-bottom: 1px solid #1b2130;
  font-size: 0.8rem;
}
.ide__preview {
  flex: 1;
  border: 0;
  width: 100%;
  background: #fff;
}
.ide__note {
  margin: 0;
  padding: 0.6rem 0.9rem;
  border-top: 1px solid #1b2130;
  background: #10131b;
  color: #9aa4bb;
  font-size: 0.8rem;
}
.ide__note em {
  color: #cdd6e6;
  font-style: normal;
  font-weight: 600;
}
.ide__dropzone {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: rgba(11, 13, 18, 0.85);
  border: 2px dashed var(--accent);
  color: #e8ecf6;
  font-weight: 600;
  font-size: 1.1rem;
  pointer-events: none;
}

@media (max-width: 720px) {
  .ide__grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr 1fr;
  }
  .ide__files {
    border-right: 0;
    border-bottom: 1px solid #1b2130;
    max-height: 8rem;
  }
  .ide__previewwrap {
    border-left: 0;
    border-top: 1px solid #1b2130;
  }
}

/* Viewer */
body.viewer {
  height: 100dvh;
  overflow: hidden;
}
.frame {
  border: 0;
  width: 100%;
  height: 100dvh;
  display: block;
  background: #fff;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: var(--bg);
}
.overlay__box {
  max-width: 26rem;
  text-align: center;
}
.overlay__icon {
  width: 3rem;
  height: 3rem;
  color: var(--accent);
}
.overlay__state {
  font-weight: 600;
  margin: 1rem 0 0.75rem;
}
.overlay__stats {
  font-size: 0.85rem;
  margin: 0.6rem 0 0;
}
.overlay__hint {
  font-size: 0.8rem;
  margin: 1.25rem 0 0;
}
.overlay .error {
  justify-content: center;
}

.bar {
  height: 0.4rem;
  background: color-mix(in srgb, var(--fg) 10%, transparent);
  border-radius: 999px;
  overflow: hidden;
}
.bar__fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease;
}
