:root {
  --bg: #0a0a0a;
  --fg: #f4f4f4;
  --muted: #888;
  --accent: #4cc2ff;
  --bar: rgba(20, 20, 20, 0.85);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

input, button, textarea, select { touch-action: auto; }
input[type="range"] { touch-action: pan-x; }

.stage {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
body.has-host-bar .stage { bottom: 76px; }

button {
  font: inherit;
  padding: 12px 22px;
  border-radius: 999px;
  border: 1px solid #333;
  background: #1a1a1a; color: var(--fg);
  cursor: pointer;
}
button.primary { background: var(--accent); color: #001018; border-color: var(--accent); }
button:active { transform: scale(0.97); }

/* text */
.slide-text {
  width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 5vmin;
}
.slide-text h1 { margin: 0 0 0.4em; line-height: 1.1; font-weight: 700; letter-spacing: -0.02em; }
.slide-text p  { margin: 0; color: var(--muted); line-height: 1.5; max-width: 28em; font-size: 22px; }

/* title animations (titleAnim: 1 | 2 | 3) */
.title-anim-1 { animation: title-fade-up 0.9s cubic-bezier(0.16, 1, 0.3, 1) both; }
@keyframes title-fade-up {
  from { opacity: 0; transform: translateY(40px); }
  to   { opacity: 1; transform: translateY(0); }
}
.title-anim-2 span {
  display: inline-block;
  animation: title-letter-pop 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes title-letter-pop {
  from { opacity: 0; transform: translateY(0.4em) scale(0.8); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.title-anim-3 { animation: title-zoom-blur 1s cubic-bezier(0.16, 1, 0.3, 1) both; }
@keyframes title-zoom-blur {
  from { opacity: 0; transform: scale(1.6); filter: blur(14px); }
  to   { opacity: 1; transform: scale(1); filter: blur(0); }
}

/* writing — 1KB 쓰기 장치 (prototype/1kb-writing.html 팔레트) */
.slide-writing {
  --sw-paper: #F2F2EE;
  --sw-panel: #FAFAF8;
  --sw-ink: #1B1D1B;
  --sw-ink-soft: #6B6E69;
  --sw-line: #D6D7D1;
  --sw-signal: #1C5BFF;
  --sw-signal-deep: #0B3BB8;
  --sw-field: #FFFFFF;
  --sw-cell-empty: #EDEEE9;
  --sw-ok: #2F6B4F;
  --sw-danger: #C92A2A;
  --sw-mono: "IBM Plex Mono", ui-monospace, monospace;
  position: fixed; inset: 0;
  overflow-y: auto;
  background: var(--sw-paper);
  color: var(--sw-ink);
  font-size: 16px; line-height: 1.7;
  transition: background 0.05s;
  touch-action: auto;
}
body.has-host-bar .slide-writing { bottom: 76px; }
.slide-writing.over.inv {
  --sw-paper: #0D0D11;
  --sw-panel: #050507;
  --sw-line: #3F424C;
  --sw-field: #16171C;
  --sw-cell-empty: #26282F;
  --sw-ink: #F2F2EE;
  --sw-ink-soft: #A2A5AE;
}
.slide-writing.over.inv .sw-header,
.slide-writing.over.inv .sw-main { border-color: var(--sw-ink); }
.sw-frame { max-width: 1060px; margin: 0 auto; padding: 28px 20px 60px; }
.sw-header {
  border: 1px solid var(--sw-ink);
  background: var(--sw-panel);
  padding: 18px 22px 16px;
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 16px; flex-wrap: wrap;
}
.sw-nameplate h1 { margin: 0; font-size: 22px; font-weight: 500; letter-spacing: 0.02em; }
.sw-latin { font-family: var(--sw-mono); font-size: 11px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--sw-ink-soft); margin-top: 2px; }
.sw-spec { font-family: var(--sw-mono); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--sw-ink-soft); text-align: right; line-height: 1.9; }
.sw-spec b { color: var(--sw-ink); font-weight: 500; }
.sw-main {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr);
  border: 1px solid var(--sw-ink);
  border-top: none;
  background: var(--sw-panel);
}
.sw-write { padding: 22px; border-right: 1px solid var(--sw-line); display: flex; flex-direction: column; }
.sw-label { font-family: var(--sw-mono); font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--sw-ink-soft); margin-bottom: 10px; }
.sw-input, .sw-mirror {
  width: 100%; flex: 1; min-height: 380px;
  border: 1px solid var(--sw-line); border-radius: 0;
  background: var(--sw-field); color: var(--sw-ink);
  font: inherit; font-size: 34px; line-height: 1.7;
  padding: 18px;
}
.sw-input { resize: vertical; }
.sw-input:focus { outline: 2px solid var(--sw-signal); outline-offset: -1px; border-color: var(--sw-signal); }
.sw-input::placeholder { color: #B5B7B0; }
.sw-mirror { white-space: pre-wrap; word-break: break-word; overflow-y: auto; }
.sw-gauge { padding: 22px; display: flex; flex-direction: column; gap: 20px; }
.sw-readout { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.sw-bytes { font-family: var(--sw-mono); font-size: 40px; font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; transition: color 0.15s; }
.sw-of { font-family: var(--sw-mono); font-size: 13px; color: var(--sw-ink-soft); }
.sw-pct { margin-left: auto; font-family: var(--sw-mono); font-size: 13px; color: var(--sw-ink-soft); font-variant-numeric: tabular-nums; }
.sw-grid { width: 100%; image-rendering: pixelated; border: 1px solid var(--sw-line); background: var(--sw-field); display: block; }
.sw-caption { font-family: var(--sw-mono); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--sw-ink-soft); margin-top: 6px; }
.sw-status { font-size: 13px; min-height: 20px; color: var(--sw-ink-soft); margin: 0; }
.sw-status.warn { color: var(--sw-signal-deep); }
.sw-status.over { color: var(--sw-danger); }
.sw-status.exact { color: var(--sw-ok); }
.sw-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--sw-line); border: 1px solid var(--sw-line); }
.sw-stat { background: var(--sw-panel); padding: 12px 14px; }
.sw-stat .k { font-family: var(--sw-mono); font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--sw-ink-soft); }
.sw-stat .v { font-family: var(--sw-mono); font-size: 20px; font-weight: 500; font-variant-numeric: tabular-nums; margin-top: 2px; }
.sw-stat .v small { font-size: 12px; color: var(--sw-ink-soft); font-weight: 400; }
@media (max-width: 820px) {
  .sw-main { grid-template-columns: 1fr; }
  .sw-write { border-right: none; border-bottom: 1px solid var(--sw-line); }
  /* 모바일: 모든 요소가 한 화면에 들어오도록 압축 */
  .sw-frame { padding: 8px 12px 12px; }
  .sw-header { padding: 10px 14px 9px; }
  .sw-nameplate h1 { font-size: 17px; }
  .sw-latin, .sw-spec { display: none; }
  .sw-write { padding: 12px 14px; }
  .sw-label { margin-bottom: 6px; }
  .sw-input, .sw-mirror {
    min-height: 0; height: 16vh; max-height: 16vh;
    overflow-y: auto; resize: none;
    font-size: 30px; line-height: 1.7; padding: 10px 12px;
  }
  .sw-gauge { padding: 12px 14px; gap: 8px; }
  .sw-bytes { font-size: 24px; }
  .sw-caption { text-align: center; margin-top: 4px; }
  .sw-status { min-height: 14px; font-size: 12px; }
  .sw-stat { padding: 5px 8px; }
  .sw-stat .k { font-size: 9px; }
  .sw-stat .v { font-size: 13px; margin-top: 0; }
  .sw-stats { grid-template-columns: 1fr 1fr 1fr; }
}

/* image */
.slide-image { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; }
.slide-image-overlay {
  position: absolute; left: 50%; top: 54%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  font-size: clamp(64px, 14vw, 180px);
  font-weight: 800; letter-spacing: -0.02em; line-height: 1.05;
  color: #fff;
  text-shadow: 0 0 24px rgba(0, 0, 0, 0.85), 0 0 4px rgba(0, 0, 0, 0.9);
  pointer-events: none;
  animation: overlay-blink 1s steps(1) infinite;
}
.slide-image-overlay .oa-arrow { font-size: 0.45em; line-height: 1; }
@keyframes overlay-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}
.slide-image img { width: 100%; height: auto; max-height: 100%; display: block; }
.slide-image-cover img { width: 100%; height: 100%; object-fit: cover; }
.slide-image-contain img { width: 100%; height: 100%; object-fit: contain; }

/* color */
.slide-color { width: 100%; height: 100%; position: relative; }
.slide-color .swatch { width: 100%; height: 100%; }
.slide-color .controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 16px 20px calc(16px + env(safe-area-inset-bottom));
  background: var(--bar);
  display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; align-items: center;
  font-size: 14px;
}
.slide-color .controls label { color: var(--muted); }
.slide-color .controls .full { grid-column: 1 / -1; color: var(--fg); }

/* ────────── bytebeat (cream / editorial theme) ────────── */

body.theme-cream {
  background: #ebe8e1;
  color: #1a1a1a;
}
body.theme-cream .host-bar {
  background: rgba(255, 255, 255, 0.78);
  border-top: 1px solid #d8d4ca;
  color: #1a1a1a;
}
body.theme-cream .host-bar button {
  background: #fff;
  color: #1a1a1a;
  border-color: #d8d4ca;
}
body.theme-cream .host-bar .meta { color: #999; }

.bb {
  width: 100%;
  max-width: 720px;
  padding: 6vmin 5vmin;
  display: flex;
  flex-direction: column;
  gap: 28px;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  color: #1a1a1a;
}

.bb-title {
  font-size: 16px;
  letter-spacing: 0.06em;
  color: #4f4a3f;
  font-weight: 700;
  margin-bottom: -10px;
}

.bb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.bb-reset {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid #d8d4ca;
  background: #fff;
  color: #5b5448;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

.bb-reset:hover {
  background: #f6f3ec;
}

.bb-field { display: flex; flex-direction: column; gap: 10px; }

.bb-label {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #999;
  font-weight: 600;
}
.bb-label .bb-n {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  margin-left: 8px;
  color: #1a1a1a;
  letter-spacing: 0;
  font-weight: 700;
}

.bb-box {
  background: #fff;
  border: 1px solid #e0ddd5;
  border-radius: 6px;
  padding: 18px 20px;
  min-height: 120px;
}
.bb-box-readonly {
  display: flex;
  align-items: center;
  min-height: 80px;
}

.bb-expr {
  width: 100%;
  min-height: 84px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: #1a1a1a;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: clamp(28px, 4.8vw, 36px);
  line-height: 1.5;
}
.bb-expr-display {
  width: 100%;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: clamp(16px, 3vw, 22px);
  color: #1a1a1a;
}

.bb-row {
  display: flex;
  align-items: center;
  gap: 24px;
}

.bb-play {
  flex: 0 0 auto;
  width: 56px; height: 56px;
  padding: 0;
  border-radius: 50%;
  background: #ee7c2b;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.08s ease;
}
.bb-play:hover { background: #f08838; }
.bb-play:active { transform: scale(0.94); }
.bb-play svg { width: 22px; height: 22px; }

.bb-vol {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* minimal range (used by VOLUME and N) */
.bb-vol-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 36px;
  background: transparent;
  outline: none;
}
.bb-vol-range::-webkit-slider-runnable-track {
  height: 1px;
  background: #c9c5bb;
  border: none;
}
.bb-vol-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #1a1a1a;
  border: none;
  margin-top: -13.5px;
  cursor: pointer;
}
.bb-vol-range::-moz-range-track {
  height: 1px;
  background: #c9c5bb;
  border: none;
}
.bb-vol-range::-moz-range-thumb {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #1a1a1a;
  border: none;
  cursor: pointer;
}

.bb-counter {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 13px;
  color: #999;
  margin-top: 8px;
}
.bb-counter i {
  font-style: italic;
  font-family: "Times New Roman", Georgia, serif;
}
.bb-counter b {
  color: #1a1a1a;
  font-weight: 700;
}

.bb-editor-pad .bb-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bb-editor-pad .bb-expr {
  font-size: clamp(20px, 3.6vw, 28px);
}

body.layout-editor-top .stage {
  align-items: flex-start;
}

body.layout-editor-top .bb.bb-editor-pad {
  padding-top: clamp(8px, 2vmin, 16px);
}

.bb-pad {
  width: 100%;
}

.bb-pad-grid {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.bb-pad-key {
  min-height: 34px;
  padding: 0 8px;
  border-radius: 4px;
  border: 1px solid #dfdbd2;
  background: #f5f2ea;
  color: #1a1a1a;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 13px;
}

.bb-pad-key:active {
  transform: translateY(1px);
}

@media (max-width: 640px) {
  .bb-pad-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* mute bytebeat viewer */
.bb.bb-viewer {
  gap: 18px;
}

.bb-viewer .bb-row {
  justify-content: flex-start;
}

.bb-viz {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  border: 1px solid #e0ddd5;
  border-radius: 6px;
  background: #fff;
}

.bb-readout {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 12px;
  color: #8d8678;
}

.bb-readout b {
  color: #1a1a1a;
  font-weight: 700;
  margin-left: 6px;
}

.bb-bits {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
}

.bb-bit {
  height: clamp(22px, 3vw, 30px);
  display: grid;
  place-items: center;
  border-radius: 4px;
  border: 1px solid #ddd8ce;
  background: #f8f6f1;
  color: #6e695f;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.bb-bit.on {
  background: #ee7c2b;
  border-color: #d87027;
  color: #fff;
}

.bb-history {
  width: 100%;
  height: 112px;
  display: block;
  border: 1px solid #ddd8ce;
  border-radius: 4px;
  background: #f8f6f1;
}

.bb-history-compact {
  margin-top: 6px;
  height: 72px;
}

@media (max-width: 640px) {
  .bb-history {
    height: 96px;
  }

  .bb-history-compact {
    height: 60px;
  }
}

/* p5 */
.slide-p5 { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.slide-p5 canvas { display: block; max-width: 100%; max-height: 100%; }

/* host bar */
.host-bar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--bar);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  z-index: 10;
}
.host-bar[hidden] { display: none; }
.host-nav-edge {
  justify-self: start;
  min-width: 52px;
  padding: 12px 18px;
}
.host-bar #next.host-nav-edge {
  justify-self: end;
}
.host-center {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-self: center;
}
.host-front {
  text-transform: lowercase;
}
.host-bar .host-meta-inline {
  color: var(--fg);
}
.host-bar .meta {
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 13px; color: var(--muted);
}
.host-bar .sep { margin: 0 4px; }
