/* =========================================================
   Dynamis APP BATTLE — 09 SELFCODE
   「このページは、いま目の前で自分自身を書いている」

   このファイルは “外枠” だけ（エディタ・固定CTA・演出用UI）。
   LP本体のスタイルは index.html の <style id="lp-css"> にあり、
   JS がそれをエディタでタイプしながら流し込む。
   ※ LP本体は body のフォント等を書き換えるので、ここでは全要素に
     フォント・色を明示して影響を受けないようにしている。
   ========================================================= */
:root {
  --ed-bg: #0e1016;
  --ed-bg2: #141821;
  --ed-line: #232938;
  --ed-fg: #c8d0e0;
  --ed-dim: #5c667c;
  --ed-acc: #d4ff3a;
  --ed-hot: #ff4f86;
  --ed-cyan: #3ad4ff;
  --cta: #e8114f;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "Zen Kaku Gothic New", system-ui, -apple-system, "Hiragino Sans", sans-serif;
  --ed-w: min(50vw, 780px);
  --bar-h: 0px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}
html { -webkit-text-size-adjust: 100%; }

/* LP本体を包むコンテナ。LP側は @container lp でレスポンシブ化している */
.preview {
  container: lp / inline-size;
  min-height: 100vh;
  padding-top: var(--bar-h);
  overflow-x: clip;
  transition: margin-left .7s var(--ease), padding-top .7s var(--ease);
}
.boot .preview { visibility: hidden; }

/* ---------- 固定CTA ---------- */
.cta-dock {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  font-family: var(--sans);
  line-height: 1.3;
}
.cta-dock-btn {
  display: inline-flex;
  align-items: center;
  gap: .5em;
  padding: 12px 18px;
  background: var(--cta);
  color: #fff;
  font: 900 15px/1.2 var(--sans);
  text-decoration: none;
  border: 3px solid #111;
  box-shadow: 4px 4px 0 #111;
  transition: transform .15s, box-shadow .15s;
}
.cta-dock-btn::after { content: "→"; }
.cta-dock-btn:hover { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 #111; }
.cta-dock-btn:focus-visible { outline: 3px solid var(--ed-cyan); outline-offset: 3px; }
.cta-dock-note {
  padding: 3px 8px;
  background: #111;
  color: var(--ed-acc);
  font: 400 11px/1.4 var(--mono);
}

/* ---------- エディタ ---------- */
.ed, .ed-pill, .live-tag, .inspect-tag, .empty-hint { display: none; }
.js .ed {
  position: fixed;
  z-index: 70;
  display: flex;
  flex-direction: column;
  background: var(--ed-bg);
  color: var(--ed-fg);
  font: 400 13px/1.65 var(--mono);
  text-align: left;
  letter-spacing: 0;
  visibility: hidden;
  transition: transform .7s var(--ease), visibility 0s .7s;
}
.js.ed-open .ed { visibility: visible; transform: none; transition: transform .7s var(--ease), visibility 0s; }
.ed button { font: inherit; color: inherit; cursor: pointer; }
.ed p { margin: 0; }

.ed-progress { position: absolute; left: 0; right: 0; top: 0; height: 2px; z-index: 3; }
.ed-progress i {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--ed-cyan), var(--ed-acc));
  transform: scaleX(0);
  transform-origin: left;
}
.ed-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
  padding: 10px 14px;
  background: var(--ed-bg2);
  border-bottom: 1px solid var(--ed-line);
}
.ed-brand { font-weight: 700; color: #fff; white-space: nowrap; }
.ed-logo { color: var(--ed-acc); margin-right: 8px; }
.ed-proj { color: var(--ed-dim); font-weight: 400; }
.ed-ctrl { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ed-btn, .ed-speed button {
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--ed-line);
  border-radius: 4px;
  font-size: 12px !important;
  line-height: 1.5 !important;
}
.ed-btn:hover, .ed-speed button:hover { border-color: var(--ed-dim); color: #fff; }
.ed-speed { display: inline-flex; }
.ed-speed button { border-radius: 0; margin-left: -1px; }
.ed-speed button:first-child { border-radius: 4px 0 0 4px; margin-left: 0; }
.ed-speed button:last-child { border-radius: 0 4px 4px 0; }
.ed-speed button[aria-pressed="true"] { background: var(--ed-acc); border-color: var(--ed-acc); color: #111; font-weight: 800; }
.ed button:focus-visible { outline: 2px solid var(--ed-cyan); outline-offset: 2px; }

.ed-tabs {
  display: flex;
  align-items: stretch;
  background: var(--ed-bg2);
  border-bottom: 1px solid var(--ed-line);
  overflow-x: auto;
  scrollbar-width: none;
}
.ed-tab {
  position: relative;
  padding: 7px 14px;
  background: transparent;
  border: 0;
  border-right: 1px solid var(--ed-line);
  color: var(--ed-dim) !important;
  font-size: 12px !important;
  white-space: nowrap;
}
.ed-tab::before { content: "●"; margin-right: 6px; font-size: 9px; vertical-align: 1px; color: var(--ed-line); }
.ed-tab[data-f="html"]::before { color: #ff8a5c; }
.ed-tab[data-f="css"]::before { color: #5cb6ff; }
.ed-tab[data-f="js"]::before { color: #ffd84d; }
.ed-tab.is-active { background: var(--ed-bg); color: #fff !important; }
.ed-tab.is-active::after { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--ed-acc); }
.ed-ai { margin-left: auto; padding: 7px 14px; color: var(--ed-acc); font-size: 11px; white-space: nowrap; }
.building .ed-ai { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.ed-main { position: relative; flex: 1; min-height: 0; }
.ed-scroll { position: absolute; inset: 0; overflow: auto; padding: 10px 0 120px; overscroll-behavior: contain; }
.code { display: none; counter-reset: ln; }
.code.is-active { display: block; }
.ln {
  position: relative;
  min-height: 1.65em;
  padding: 0 14px 0 58px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  counter-increment: ln;
}
.ln::before {
  content: counter(ln);
  position: absolute;
  left: 0;
  width: 42px;
  text-align: right;
  color: #3a4256;
}
.ln:last-child { background: rgba(255, 255, 255, .035); }
.ln:last-child::before { color: var(--ed-fg); }
.ln.ai { box-shadow: inset 3px 0 rgba(212, 255, 58, .45); animation: ai-in .9s ease-out; }
@keyframes ai-in { from { background: rgba(212, 255, 58, .16); } }

.caret {
  display: inline-block;
  width: 2px;
  height: 1.2em;
  margin-right: -2px;
  vertical-align: -.2em;
  background: var(--ed-acc);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.ghost { color: #4d5670; font-style: italic; }
.ghost * { color: inherit !important; background: none !important; }
.ghost-hint {
  position: absolute;
  right: 12px;
  margin-top: 1px;
  padding: 0 8px;
  background: var(--ed-acc);
  color: #111;
  border-radius: 3px;
  font: 700 10.5px/1.7 var(--mono);
  font-style: normal;
}

/* シンタックスハイライト */
.t-tag { color: #ff6b9a; }
.t-attr { color: #d4ff3a; }
.t-str { color: #7ee0b8; }
.t-com { color: #5f6b85; font-style: italic; }
.t-com.todo { color: #ffcf5c; background: rgba(255, 207, 92, .1); font-style: normal; }
.t-sel { color: #ffcf5c; }
.t-prop { color: #7cc7ff; }
.t-num { color: #ff9e64; }
.t-at, .t-kw { color: #c792ea; }
.t-fn { color: #82aaff; }
.t-pun { color: #8a93a8; }
.t-ent { color: #ff9e64; }
.t-type { color: #ffcf5c; }
.sw {
  display: inline-block;
  width: .8em;
  height: .8em;
  margin: 0 4px 0 2px;
  vertical-align: -.05em;
  background: var(--c);
  border: 1px solid rgba(255, 255, 255, .35);
  border-radius: 2px;
}

/* AI 吹き出し */
.ed-bubble {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 2;
  width: min(360px, calc(100% - 28px));
  padding: 12px 14px;
  background: #1b2030;
  border: 1px solid #2f3850;
  border-radius: 10px 10px 2px 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .45);
  font-size: 12.5px;
  line-height: 1.6;
  animation: bubble-in .35s var(--ease);
}
.ed-bubble[hidden] { display: none; }
.ed-bubble p { display: flex; gap: 10px; }
.ed-bubble p + p { margin-top: 8px; }
.ed-bubble b { flex: none; width: 3.6em; color: var(--ed-dim); font-weight: 700; }
.ed-bubble .ba b { color: var(--ed-acc); }
.ed-bubble .ba span { color: #fff; }
.dots::after { content: "…"; display: inline-block; animation: dots 1s steps(4) infinite; overflow: hidden; vertical-align: bottom; width: 1em; }
@keyframes dots { from { width: 0; } to { width: 1.2em; } }
@keyframes bubble-in { from { opacity: 0; transform: translateY(10px) scale(.97); } }

/* ビルド完了 */
.ed-done {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 2;
  padding: 14px 16px;
  background: #0f1a10;
  border: 1px solid var(--ed-acc);
  border-radius: 6px;
  box-shadow: 0 0 0 4px rgba(212, 255, 58, .08), 0 14px 40px rgba(0, 0, 0, .5);
  animation: bubble-in .45s var(--ease);
}
.ed-done[hidden] { display: none; }
.ed-done-ok { color: var(--ed-acc); font-weight: 800; }
.ed-done-big { margin-top: 2px !important; color: #fff; font-size: clamp(14px, 1.6vw, 19px); font-weight: 800; }
.ed-done-sub { margin-top: 4px !important; color: var(--ed-dim); font-size: 11.5px; }

.ed-status {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 4px 14px;
  background: #1a1f2c;
  border-top: 1px solid var(--ed-line);
  color: #8a93a8;
  font-size: 11px;
  line-height: 1.6;
  white-space: nowrap;
}
#st-build { color: var(--ed-acc); }
#st-time { margin-left: auto; }

/* たたんだ状態のピル */
.js .ed-pill {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 70;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  max-width: calc(100vw - 28px);
  padding: 6px 6px 6px 14px;
  background: var(--ed-bg);
  color: var(--ed-fg);
  border: 1px solid #2a3142;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
  font: 400 12px/1.4 var(--mono);
  transform: translateY(0);
  transition: transform .5s var(--ease), opacity .3s;
}
.ed-open .ed-pill { transform: translateY(160%); opacity: 0; pointer-events: none; }
.ed-pill-txt { color: #fff; font-weight: 700; margin-right: 4px; }
.ed-pill-txt span { color: var(--ed-acc); }
.ed-pill button {
  padding: 5px 12px;
  background: #1d2332;
  color: var(--ed-fg);
  border: 1px solid #2a3142;
  border-radius: 999px;
  font: 400 12px/1.4 var(--mono);
  cursor: pointer;
}
.ed-pill button:hover { color: #fff; border-color: var(--ed-dim); }
.ed-pill button:focus-visible { outline: 2px solid var(--ed-cyan); outline-offset: 2px; }

/* ビルド中のライブ表示 */
.js.building .live-tag {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 60;
  display: block;
  margin: 0;
  padding: 5px 10px;
  background: rgba(14, 16, 22, .88);
  color: var(--ed-acc);
  border-radius: 4px;
  font: 700 11px/1.4 var(--mono);
}
.live-tag span { color: #8a93a8; font-weight: 400; margin-left: 6px; }
.js.building .inspect-tag {
  position: fixed;
  z-index: 65;
  display: block;
  margin: 0;
  padding: 1px 7px;
  background: var(--ed-cyan);
  color: #06232d;
  border-radius: 2px;
  font: 700 11px/1.6 var(--mono);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
}
.inspect-tag.is-on { opacity: 1; }
[data-js-inspect] { outline: 2px dashed var(--ed-cyan) !important; outline-offset: 2px; }
[data-js-born] { animation: born .9s ease-out; }
@keyframes born {
  from { outline: 2px solid var(--ed-cyan); outline-offset: 4px; filter: brightness(1.12); }
  to { outline: 2px solid rgba(58, 212, 255, 0); outline-offset: 0; }
}
.js.is-empty .empty-hint {
  position: fixed;
  top: 50%;
  z-index: 1;
  display: block;
  margin: 0;
  color: #b8bcc6;
  font: 400 13px/1.8 var(--mono);
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* ---------- PC: 左半分がエディタ ---------- */
@media (min-width: 900px) {
  .js .ed {
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--ed-w);
    border-right: 1px solid #000;
    box-shadow: 18px 0 60px rgba(0, 0, 0, .18);
    transform: translateX(-104%);
  }
  .ed-open .preview { margin-left: var(--ed-w); }
  .js.is-empty .empty-hint { left: calc(var(--ed-w) + (100vw - var(--ed-w)) / 2); }
  .ed-open .cta-dock { top: 16px; }
}

/* ---------- スマホ/タブレット: 上部に固定CTAバー＋折りたたみパネル ---------- */
@media (max-width: 899.98px) {
  :root { --bar-h: 58px; --ed-h: 44vh; }
  @supports (height: 1svh) { :root { --ed-h: 44svh; } }
  .cta-dock {
    top: 0;
    left: 0;
    right: 0;
    height: var(--bar-h);
    flex-direction: row-reverse;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 10px 0 12px;
    background: #111;
    border-bottom: 1px solid #000;
  }
  .cta-dock-btn { flex: none; padding: 9px 12px; font-size: 14px; border-width: 2px; box-shadow: 3px 3px 0 var(--ed-acc); border-color: #111; }
  .cta-dock-note { padding: 0; background: none; font-size: 10px; line-height: 1.35; }
  .js .ed {
    top: var(--bar-h);
    left: 0;
    right: 0;
    height: var(--ed-h);
    font-size: 11.5px;
    box-shadow: 0 14px 40px rgba(0, 0, 0, .25);
    transform: translateY(calc(-100% - var(--bar-h)));
  }
  .ed-open .preview { padding-top: calc(var(--bar-h) + var(--ed-h)); }
  .ed-head { padding: 7px 10px; }
  .ed-proj, .ed-ai { display: none; }
  .ed-btn, .ed-speed button { padding: 3px 8px; font-size: 11px !important; }
  .ed-tab { padding: 5px 10px; font-size: 11px !important; }
  .ln { padding-left: 40px; padding-right: 10px; }
  .ln::before { width: 30px; }
  .ed-status { font-size: 10px; gap: 2px 10px; padding: 3px 10px; }
  .ed-bubble { right: 10px; bottom: 10px; font-size: 11.5px; padding: 10px 12px; }
  .ed-done { left: 10px; right: 10px; bottom: 10px; padding: 10px 12px; }
  .js.is-empty .empty-hint { left: 50%; top: calc(var(--bar-h) + var(--ed-h) + 25vh); }
  .js.building .live-tag { display: none; }
  .js .ed-pill { left: 10px; bottom: 10px; max-width: calc(100vw - 20px); flex-wrap: nowrap; gap: 4px; padding: 4px 4px 4px 10px; font-size: 11px; }
  .ed-pill-txt { white-space: nowrap; }
  .ed-pill button { padding: 4px 8px; font-size: 11px; white-space: nowrap; }
}
@media (max-width: 420px) {
  .ed-brand { font-size: 12px; }
  .ed-rebuild-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .preview, .js .ed, .ed-open .ed, .js .ed-pill { transition: none !important; }
  [data-js-born], .ln.ai, .ed-bubble, .ed-done, .caret, .building .ed-ai { animation: none !important; }
}

/* ===== すぐに完成させる（ビルド中だけ） ===== */
.instant {
  display: none;
  position: fixed;
  right: 24px;
  bottom: 68px; /* 右下の LIVE PREVIEW 表示の上 */
  z-index: 60;
  align-items: center;
  gap: .5em;
  padding: 16px 26px;
  background: #e8114f;
  color: #fff;
  border: 3px solid #111;
  border-radius: 0;
  box-shadow: 6px 6px 0 #111;
  font: 900 16px/1.2 "Zen Kaku Gothic New", sans-serif;
  letter-spacing: .06em;
  cursor: pointer;
  transition: transform .15s;
}
.instant:hover { transform: translateY(-2px); }
.instant:focus-visible { outline: 3px solid currentColor; outline-offset: 3px; }
.js.building .instant { display: inline-flex; animation: instant-in .4s ease-out both; }
@keyframes instant-in { from { opacity: 0; transform: translateY(12px); } }
@media (max-width: 899px) {
  .instant { left: 50%; right: auto; bottom: 16px; translate: -50% 0; padding: 14px 22px; font-size: 15px; white-space: nowrap; }
}
@media (prefers-reduced-motion: reduce) {
  .js.building .instant { animation: none; }
}
