:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --border: #d4d4d8;
  --text: #18181b;
  --text-dim: #71717a;
  --accent: #4f46e5;
  --accent-dim: #4f46e51a;
  --green: #16a34a;
  --orange: #ea580c;
  --red: #dc2626;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-2: #242736;
    --border: #2e3248;
    --text: #e8e9f0;
    --text-dim: #8b8fa8;
    --accent: #6c63ff;
    --accent-dim: #6c63ff33;
    --green: #22c55e;
    --orange: #f97316;
    --red: #ef4444;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
    Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  padding: 1rem;
  min-height: 100dvh;
}

@media (min-width: 640px) {
  body {
    padding: 2rem 1rem 4rem;
  }
}

.container {
  width: 100%;
  max-width: 1100px;
  margin-inline: auto;
}

.page-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

@media (min-width: 640px) {
  .page-header {
    margin-bottom: 2.5rem;
  }
}

.page-header h1 {
  font-family: Georgia, 'Times New Roman', Times, serif;
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

.page-header h1 span {
  color: var(--accent);
}

.page-header p {
  color: var(--text-dim);
  font-size: 1rem;
  max-width: 60ch;
  margin-inline: auto;
}

.badge {
  display: inline-block;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2em 0.75em;
  margin-bottom: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

footer {
  margin-top: 2rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-dim);
}

footer a {
  color: var(--accent);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* ─── Playground layout ─── */

.playground {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

.right-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

@media (min-width: 900px) {
  .playground {
    grid-template-columns: 280px 1fr;
    align-items: start;
  }

  .right-column {
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
  }
}

.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.control-group h3 {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
}

/* ─── Text input ─── */

.input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.text-input {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  padding: 0.35rem 0.6rem;
  transition: border-color 0.15s;
}

select.text-input {
  appearance: auto;
  cursor: pointer;
}

.text-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ─── Area grid ─── */

.area-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  max-width: 200px;
}

.area-cell {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  font-family: inherit;
  transition: all 0.15s;
}

.area-cell:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.area-cell.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.area-current {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.checks,
.radios {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.check,
.radio {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  cursor: pointer;
}

.check input,
.radio input {
  accent-color: var(--accent);
}

.hint {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  font-style: italic;
}

.margin-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.margin-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.margin-row output {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  color: var(--text-dim);
  min-width: 3.5em;
  text-align: right;
}

.reset-btn {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.15s;
}

.reset-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.support {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.support.supported  { border-color: var(--green); }
.support.unsupported { border-color: var(--orange); }

.support-icon {
  font-size: 1rem;
  flex-shrink: 0;
}

.support-label {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.15rem;
}

.support.supported .support-label  { color: var(--green); }
.support.unsupported .support-label { color: var(--orange); }

/* ─── Canvas ─── */

.canvas-wrap {
  position: relative;
  height: clamp(320px, 50vh, 420px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overscroll-behavior: contain;
  flex-shrink: 0;
}

@media (min-width: 900px) {
  .right-column .code-block {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .right-column .code-panel {
    flex: 1;
    min-height: 0;
    overflow: auto;
  }
}

.canvas {
  position: relative;
  width: 250%;
  height: 250%;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 32px 32px;
  background-position: 0 0;
}

.watermark {
  position: absolute;
  top: 1rem;
  left: 1rem;
  color: var(--text-dim);
  font-size: 0.8rem;
  pointer-events: none;
  background: var(--surface);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.anchor {
  position: absolute;
  width: 96px;
  height: 64px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: grab;
  user-select: none;
  touch-action: none;
  transform: translate(-50%, -50%);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1;
}

.anchor:focus-visible {
  outline: 2px solid #fff;
  outline-offset: -4px;
}

.anchor-label {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.7rem;
}

.popup {
  position: absolute;
  position-area: bottom;
  margin: 8px;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.3;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
  max-width: 240px;
  z-index: 2;
}

.popup strong {
  display: block;
  margin-bottom: 0.15rem;
}

.popup-meta {
  font-family: ui-monospace, monospace;
  font-size: 0.7rem;
  color: var(--text-dim);
}

/* ─── Code block ─── */

.code-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.85rem 0.35rem 0.5rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.code-tabs {
  display: flex;
  gap: 2px;
}

.code-tab {
  background: transparent;
  border: none;
  border-radius: 5px;
  color: var(--text-dim);
  padding: 0.25rem 0.6rem;
  font-size: 0.78rem;
  font-family: inherit;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all 0.15s;
}

.code-tab:hover {
  color: var(--text);
  background: var(--border);
}

.code-tab.is-active {
  background: var(--accent);
  color: #fff;
}

.copy-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.copy-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.code-panel {
  margin: 0;
  padding: 0.85rem 1rem;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text);
  background: transparent;
  overflow-x: auto;
  border: none;
  border-radius: 0;
}
