:root {
  color-scheme: dark;
  --sim-bg: #0f172a;
  --sim-panel: #111827;
  --sim-toolbar: #1e293b;
  --sim-line: #334155;
  --sim-text: #cbd5e1;
  --sim-muted: #64748b;
  --sim-accent: #6366f1;
  --sim-paper: #f8fafc;
  --site-paper: #f6f4ef;
  --site-ink: #24241f;
  --site-muted: #77766e;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background: var(--sim-bg);
  color: var(--sim-text);
  font-family: Arial, "Noto Sans TC", sans-serif;
}

button,
textarea {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.skip-link {
  position: fixed;
  inset-block-start: 0.5rem;
  inset-inline-start: 0.5rem;
  z-index: 20;
  padding: 0.65rem 0.85rem;
  border-radius: 0.4rem;
  background: white;
  color: #111827;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  padding: 0.75rem clamp(1rem, 3vw, 2.5rem);
  background: var(--site-paper);
  color: var(--site-ink);
  border-block-end: 1px solid #dedbd2;
}

.site-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.site-brand strong,
.site-brand small {
  display: block;
}

.site-brand strong {
  font-family: serif;
}

.site-brand small {
  margin-block-start: 0.15rem;
  color: var(--site-muted);
  font-size: 0.625rem;
}

.site-mark {
  display: grid;
  width: 2.25rem;
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid currentColor;
  font-family: serif;
}

.site-nav,
.site-footer nav {
  display: flex;
  gap: 0.55rem 1rem;
  overflow-x: auto;
  color: var(--site-muted);
  font-size: 0.75rem;
  white-space: nowrap;
}

.site-nav a[aria-current="page"],
.site-nav a:hover,
.site-nav a:focus-visible,
.site-footer a:hover,
.site-footer a:focus-visible {
  color: var(--site-ink);
  text-decoration: underline;
  text-underline-offset: 0.25rem;
}

.simulator-app {
  display: grid;
  min-height: 52rem;
  background: var(--sim-bg);
}

.editor-panel,
.preview-panel {
  display: flex;
  min-width: 0;
  min-height: 26rem;
  flex-direction: column;
}

.editor-panel {
  border-block-end: 1px solid var(--sim-line);
  background: var(--sim-panel);
}

.editor-toolbar,
.preview-toolbar {
  display: flex;
  min-height: 4rem;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
}

.editor-toolbar {
  background: var(--sim-toolbar);
  border-block-end: 1px solid var(--sim-line);
}

.editor-toolbar h1 {
  margin: 0;
  color: white;
  font-size: clamp(0.9rem, 3vw, 1rem);
}

.editor-toolbar h1 span {
  margin-inline-end: 0.35rem;
  color: #a5b4fc;
}

.run-button {
  min-height: 2.5rem;
  padding-inline: 1rem;
  border: 0;
  border-radius: 0.4rem;
  background: var(--sim-accent);
  color: white;
  cursor: pointer;
  font-weight: 700;
}

.run-button:hover {
  background: #4f46e5;
}

.run-button:focus-visible,
.device-button:focus-visible,
.site-header a:focus-visible,
.site-footer a:focus-visible {
  outline: 3px solid #fbbf24;
  outline-offset: 3px;
}

#code-editor {
  width: 100%;
  min-height: 22rem;
  flex: 1;
  resize: vertical;
  border: 0;
  background: var(--sim-panel);
  color: var(--sim-text);
  padding: 1rem;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  tab-size: 4;
}

#code-editor:focus-visible {
  outline: 2px solid var(--sim-accent);
  outline-offset: -2px;
}

.preview-panel {
  background: var(--sim-paper);
}

.preview-toolbar {
  position: relative;
  z-index: 2;
  background: white;
  color: #475569;
  border-block-end: 1px solid #e2e8f0;
  box-shadow: 0 2px 8px rgb(15 23 42 / 8%);
}

.device-switcher {
  display: flex;
  margin: 0;
  padding: 0.25rem;
  border: 0;
  border-radius: 0.55rem;
  background: #f1f5f9;
}

.device-button {
  min-height: 2.5rem;
  padding-inline: clamp(0.65rem, 3vw, 1rem);
  border: 0;
  border-radius: 0.4rem;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 700;
}

.device-button[aria-pressed="true"] {
  background: white;
  color: #4f46e5;
  box-shadow: 0 1px 3px rgb(15 23 42 / 16%);
}

#current-size {
  padding: 0.4rem 0.65rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.35rem;
  background: #f8fafc;
  font-size: 0.75rem;
  font-weight: 700;
}

.preview-stage {
  display: grid;
  min-height: 24rem;
  flex: 1;
  place-items: center;
  overflow: auto;
  padding: clamp(1rem, 3vw, 2rem);
  background-color: #f1f5f9;
  background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
  background-size: 20px 20px;
}

.device-view {
  --device-width: 100%;
  --device-height: 100%;
  position: relative;
  display: flex;
  width: var(--device-width);
  max-width: 100%;
  height: var(--device-height);
  min-height: 20rem;
  margin: auto;
  overflow: hidden;
  border: 1px solid #cbd5e1;
  border-radius: 0.25rem;
  background: white;
  box-shadow: 0 25px 50px -12px rgb(15 23 42 / 25%);
  transition: width 0.4s ease, height 0.4s ease;
}

.device-view[data-device="tablet"],
.device-view[data-device="mobile"] {
  flex: 0 0 auto;
  max-width: none;
  border: 14px solid #1e293b;
  border-block-start-width: 24px;
  border-block-end-width: 48px;
  border-radius: 2.5rem;
}

.device-view[data-device="tablet"]::before,
.device-view[data-device="mobile"]::before,
.device-view[data-device="tablet"]::after,
.device-view[data-device="mobile"]::after {
  position: absolute;
  inset-inline-start: 50%;
  z-index: 2;
  content: "";
  transform: translateX(-50%);
  border-radius: 999px;
}

.device-view[data-device="tablet"]::before,
.device-view[data-device="mobile"]::before {
  inset-block-start: -14px;
  width: 3.75rem;
  height: 0.375rem;
  background: #0f172a;
}

.device-view[data-device="tablet"]::after,
.device-view[data-device="mobile"]::after {
  inset-block-end: -30px;
  width: 5rem;
  height: 0.25rem;
  background: #475569;
}

#preview-frame {
  width: 100%;
  height: 100%;
  flex: 1;
  border: 0;
  background: white;
}

.site-footer {
  padding: 1.5rem clamp(1rem, 3vw, 2.5rem);
  background: var(--site-paper);
  color: var(--site-ink);
  border-block-start: 1px solid #dedbd2;
}

.site-footer p,
.site-footer small {
  color: var(--site-muted);
  font-size: 0.7rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 64rem) {
  .simulator-app {
    grid-template-columns: minmax(20rem, 2fr) minmax(30rem, 3fr);
    height: calc(100dvh - 5rem);
    min-height: 38rem;
  }

  .editor-panel,
  .preview-panel {
    min-height: 0;
  }

  .editor-panel {
    border-block-end: 0;
    border-inline-end: 1px solid var(--sim-line);
  }

  #code-editor {
    min-height: 0;
    resize: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .device-view,
  .skip-link {
    transition: none;
  }
}
