/* PHASe web — strictly black & white */

:root {
  /* dark — ash black, not pure black */
  --bg: #161616;
  --bg1: #1b1b1b;
  --bg2: #222;
  --fg: #efefec;
  --fg2: #bcbcb8;
  --mid: #83837f;
  --dim: #555553;
  --ln: #262626;
  --ln2: #3a3a3a;
  --scrim: rgba(22, 22, 22, .84);
  --font: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --side: 320px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #efeeea;
  --bg1: #e8e7e3;
  --bg2: #e0dfda;
  --fg: #111;
  --fg2: #3a3a38;
  --mid: #6c6c68;
  --dim: #9b9a95;
  --ln: #d6d5d0;
  --ln2: #bdbcb7;
  --scrim: rgba(239, 238, 234, .86);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 400 12px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
::selection { background: var(--fg); color: var(--bg); }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.dim { color: var(--mid); }
.fg { color: var(--fg); }
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

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

#app {
  display: grid;
  grid-template-columns: var(--side) 1fr;
  grid-template-rows: 44px minmax(0, 1fr) 26px;
  height: 100vh;
  height: 100dvh;
}
#top { grid-column: 1 / -1; }
#side { grid-row: 2; grid-column: 1; }
#stage { grid-row: 2; grid-column: 2; }
#status { grid-column: 1 / -1; }

/* ── controls ───────────────────────────── */

button {
  font: inherit;
  font-size: 11px;
  letter-spacing: .06em;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--ln2);
  border-radius: 0;
  height: 28px;
  padding: 0 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .12s;
}
button:hover { border-color: var(--fg); position: relative; z-index: 1; }
button:active { background: var(--bg2); }
button.on, button[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
button:disabled { opacity: .3; cursor: default; border-color: var(--ln2); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 1px solid var(--fg); outline-offset: 2px; }

.seg { display: inline-flex; }
.seg > button + button { margin-left: -1px; }
.seg.full { display: flex; width: 100%; }
.seg.full > button { flex: 1; }
.k { opacity: .45; margin-right: 7px; font-weight: 500; }
button.on .k { opacity: .6; }

input[type="text"], select {
  font: inherit;
  font-size: 12px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--ln2);
  border-radius: 0;
  height: 28px;
  padding: 0 8px;
  width: 100%;
  min-width: 0;
  user-select: text;
  -webkit-user-select: text;
}
input[type="text"]:hover { border-color: var(--mid); }
input[type="text"]:focus { outline: none; border-color: var(--fg); }
input[type="text"]:disabled { color: var(--dim); border-color: var(--ln); }
input.bad { border-style: dashed; border-color: var(--fg); }
input::placeholder { color: var(--dim); }

.selwrap { position: relative; margin-bottom: 8px; }
.selwrap::after { content: "▾"; position: absolute; right: 9px; top: 5px; pointer-events: none; color: var(--mid); }
select { appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 24px; }
select:hover { border-color: var(--mid); }
option, optgroup { background: var(--bg); color: var(--fg); }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 22px; margin: 0;
  background: transparent; cursor: ew-resize;
}
input[type="range"]::-webkit-slider-runnable-track { height: 1px; background: var(--ln2); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 7px; height: 15px; margin-top: -7px;
  background: var(--fg); border: 0; border-radius: 0;
}
input[type="range"]::-moz-range-track { height: 1px; background: var(--ln2); }
input[type="range"]::-moz-range-progress { height: 1px; background: var(--fg); }
input[type="range"]::-moz-range-thumb { width: 7px; height: 15px; background: var(--fg); border: 0; border-radius: 0; }
input[type="range"]:hover::-webkit-slider-runnable-track { background: var(--mid); }

/* ── header ─────────────────────────────── */

#top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--ln);
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 10px; flex: 0 1 280px; min-width: 0; }
.logo { font-weight: 600; font-size: 14px; letter-spacing: .02em; }
.slash { color: var(--dim); }
#wsName {
  border-color: transparent; background: transparent; height: 26px; padding: 0 6px; font-size: 12px; color: var(--fg2);
}
#wsName:hover { border-color: var(--ln2); }
#wsName:focus { color: var(--fg); border-color: var(--fg); }
.tools { margin: 0 auto; }
.actions { display: flex; gap: 8px; align-items: center; }
#helpBtn { width: 28px; padding: 0; }
.theme { min-width: 78px; }
body { transition: background-color .2s, color .2s; }
#undoBtn, #redoBtn { width: 30px; padding: 0; font-size: 14px; }

/* ── sidebar ────────────────────────────── */

#side {
  border-right: 1px solid var(--ln);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--ln2) transparent;
}
.sec { padding: 14px 16px 16px; border-bottom: 1px solid var(--ln); }
.sec.grow { flex: 1 0 auto; }
.sec h2 {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  margin: 0 0 12px;
  font-size: 10.5px; font-weight: 500; letter-spacing: .14em; color: var(--fg);
}
.sec h2 b { font-weight: 400; color: var(--dim); margin-right: 10px; }
.sec h2 .aux { font-size: 10px; letter-spacing: .04em; color: var(--mid); font-weight: 400; text-align: right; }

.row { display: grid; grid-template-columns: 72px 1fr 36px; align-items: center; gap: 10px; min-height: 28px; margin-top: 6px; }
.row.two { grid-template-columns: 96px 1fr; }
.lab { color: var(--mid); font-size: 10px; letter-spacing: .12em; }
.val { text-align: right; color: var(--fg2); }
.btns { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.btns > button { flex: 1; }
.note { margin: 10px 0 0; color: var(--dim); font-size: 10.5px; line-height: 1.55; }

.file { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin-bottom: 4px; }

.wrow { display: grid; grid-template-columns: 96px 1fr auto; gap: 10px; align-items: center; margin-top: 6px; }
.wrow .val { color: var(--fg); }
.setline { text-align: left; }
.nud button { width: 28px; padding: 0; font-size: 9px; }

.tiltrow { display: grid; grid-template-columns: 110px 1fr; gap: 8px; align-items: center; }
.angle { position: relative; }
.angle input { padding-right: 20px; text-align: right; font-size: 13px; }
.angle .unit { position: absolute; right: 8px; top: 5px; color: var(--mid); pointer-events: none; }
.scrub {
  height: 28px; border: 1px solid var(--ln2); position: relative; cursor: ew-resize; overflow: hidden;
  background:
    repeating-linear-gradient(90deg, var(--fg) 0 1px, transparent 1px 50px) 0 0 / 50px 9px repeat-x,
    repeating-linear-gradient(90deg, var(--mid) 0 1px, transparent 1px 10px) 0 0 / 10px 5px repeat-x;
  background-position-y: 0, 0;
  touch-action: none;
}
.scrub:hover, .scrub.active { border-color: var(--fg); }
.scrub i { position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--fg); }
.scrub i::after { content: ""; position: absolute; left: -3px; bottom: 0; border: 3.5px solid transparent; border-bottom-color: var(--fg); }

.chk { display: flex; align-items: center; gap: 8px; text-align: left; }
.chk .box { width: 9px; height: 9px; border: 1px solid currentColor; display: inline-block; }
.chk[aria-pressed="true"] { background: var(--bg); color: var(--fg); border-color: var(--fg); }
.chk[aria-pressed="true"] .box { background: currentColor; }

.calc {
  margin-top: 10px; padding: 8px 10px; border: 1px dashed var(--ln2);
  display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 11px;
}
.calc span:nth-child(odd) { color: var(--mid); font-size: 10px; letter-spacing: .1em; align-self: center; }
.calc span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }
.calc .warn { grid-column: 1 / -1; color: var(--fg); text-align: left !important; letter-spacing: 0 !important; font-size: 11px !important; }

.phead, .pr { display: grid; grid-template-columns: 26px 1fr 64px 42px 22px; align-items: center; gap: 6px; }
.phead { font-size: 10px; letter-spacing: .1em; color: var(--dim); padding: 0 6px 4px; }
.r { text-align: right; }
.plist {
  border: 1px solid var(--ln); min-height: 30px; max-height: 260px; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--ln2) transparent;
}
.plist:empty::before { content: "no particles yet"; display: block; padding: 7px 8px; color: var(--dim); font-size: 11px; }
.pr { padding: 0 0 0 6px; height: 26px; border-bottom: 1px solid var(--ln); cursor: pointer; font-variant-numeric: tabular-nums; }
.pr:last-child { border-bottom: 0; }
.pr:hover { background: var(--bg2); }
.pr.on { background: var(--fg); color: var(--bg); }
.pr .i { color: var(--dim); font-size: 10px; }
.pr.on .i { color: var(--mid); }
.pr .nm {
  height: 22px; border-color: transparent; background: transparent; padding: 0 4px; margin-left: -4px; color: inherit; cursor: pointer;
}
.pr .nm:hover { border-color: var(--ln2); }
.pr.on .nm:hover { border-color: var(--mid); }
.pr .nm:focus { cursor: text; background: var(--bg); color: var(--fg); border-color: var(--fg); }
.pr .x { height: 22px; width: 22px; padding: 0; border: 0; background: transparent; color: inherit; opacity: .35; font-size: 13px; }
.pr .x:hover { opacity: 1; }
.pr.out .h::after { content: " !"; }

.stats { display: grid; grid-template-columns: repeat(2, auto 1fr); gap: 3px 10px; margin-top: 12px; font-size: 11px; }
.stats:empty { display: none; }
.stats span:nth-child(odd) { color: var(--mid); font-size: 10px; letter-spacing: .1em; align-self: center; }
.stats span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }

.hist { margin-top: 12px; display: grid; gap: 2px; font-size: 10px; }
.hist:empty { display: none; }
.hist .hh { display: flex; justify-content: space-between; color: var(--dim); letter-spacing: .1em; margin-bottom: 2px; }
.hist .hr { display: grid; grid-template-columns: 44px 1fr 22px; gap: 8px; align-items: center; color: var(--mid); font-variant-numeric: tabular-nums; }
.hist .hr .l { text-align: right; }
.hist .hr .c { text-align: right; color: var(--fg2); }
.hist .bar { height: 9px; border-left: 1px solid var(--ln2); position: relative; }
.hist .bar b { position: absolute; left: 0; top: 1px; bottom: 1px; background: var(--fg); }
.hist .edge { border-top: 1px solid var(--mid); margin-left: 52px; margin-right: 30px; }

/* ── stage ──────────────────────────────── */

#stage { position: relative; overflow: hidden; background: var(--bg); touch-action: none; }
#cv { position: absolute; inset: 0; display: block; outline: none; }

#hint {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: var(--bg); border: 1px solid var(--fg);
  padding: 5px 12px; font-size: 11px; letter-spacing: .1em; white-space: nowrap;
  pointer-events: none; display: flex; align-items: center; gap: 8px; max-width: calc(100% - 24px);
}
#hint .caret { width: 7px; height: 12px; background: var(--fg); display: inline-block; animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
#hint kbd { border: 1px solid var(--mid); padding: 0 4px; font: inherit; font-size: 10px; margin: 0 2px; }

#loupe { position: absolute; top: 14px; right: 14px; pointer-events: none; }
#loupe.left { right: auto; left: 14px; }
#loupeCv { display: block; width: 176px; height: 176px; border: 1px solid var(--fg); background: var(--bg); }
#loupe .cap {
  display: flex; justify-content: space-between; font-size: 10px; color: var(--fg2); background: var(--bg);
  border: 1px solid var(--fg); border-top: 0; padding: 2px 6px; font-variant-numeric: tabular-nums;
}

#zoomCtl { position: absolute; left: 14px; bottom: 14px; display: flex; gap: 6px; }
#zoomCtl button { height: 26px; }
#zOut, #zIn { width: 26px; padding: 0; font-size: 14px; }
#zVal { width: 64px; padding: 0; }

#minimap { position: absolute; right: 14px; bottom: 14px; border: 1px solid var(--ln2); background: var(--bg); line-height: 0; }
#minimap:hover { border-color: var(--mid); }
#mapCv { display: block; cursor: crosshair; touch-action: none; }

#empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; overflow: auto; }
.emptyInner { text-align: center; max-width: 520px; }
.ascii { color: var(--dim); font: inherit; font-size: 11px; line-height: 1.35; margin: 0 0 28px; text-align: left; display: inline-block; white-space: pre; }
#empty h1 { font-size: 44px; font-weight: 300; letter-spacing: .02em; margin: 0; line-height: 1; }
#empty .sub { color: var(--mid); margin: 10px 0 28px; letter-spacing: .06em; }
.dropbox {
  display: flex; flex-direction: column; gap: 4px; align-items: center; justify-content: center;
  width: 100%; height: auto; padding: 26px 20px; border: 1px dashed var(--mid); font-size: 12px; letter-spacing: .12em;
}
.dropbox:hover { border-style: solid; border-color: var(--fg); background: var(--bg1); }
.dropbox .dim { letter-spacing: .04em; font-size: 11px; }
.formats { margin: 14px 0 20px; font-size: 11px; }
button.link { border: 0; height: auto; padding: 2px 0; color: var(--fg2); background: none; border-bottom: 1px solid var(--ln2); }
button.link:hover { color: var(--fg); border-bottom-color: var(--fg); }

#drop {
  position: absolute; inset: 12px; border: 1px dashed var(--fg); background: var(--scrim);
  display: grid; place-items: center; font-size: 13px; letter-spacing: .2em; pointer-events: none; z-index: 5;
}

#rename {
  position: absolute; z-index: 6; height: 22px; padding: 0 6px; width: 140px;
  border: 1px solid var(--fg); background: var(--bg); font-size: 11px;
}

/* ── status bar ─────────────────────────── */

#status {
  display: flex; align-items: center; gap: 14px; padding: 0 16px;
  border-top: 1px solid var(--ln); font-size: 10.5px; color: var(--fg2); white-space: nowrap; overflow: hidden;
}
#status i { font-style: normal; color: var(--dim); margin-right: 7px; letter-spacing: .1em; }
#status b { font-weight: 400; }
#status .sep { width: 1px; height: 11px; background: var(--ln2); }
#status .grow { flex: 1; }
#stTool { letter-spacing: .1em; }

/* ── modal / toast ──────────────────────── */

#modal { position: fixed; inset: 0; background: var(--scrim); display: grid; place-items: center; z-index: 50; padding: 16px; }
.dlg { background: var(--bg); border: 1px solid var(--fg); width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.dlgHead { display: flex; justify-content: space-between; align-items: center; padding: 10px 10px 10px 18px; border-bottom: 1px solid var(--ln2); font-size: 11px; letter-spacing: .14em; }
#dlgClose { width: 28px; padding: 0; border-color: transparent; font-size: 16px; }
#dlgClose:hover { border-color: var(--fg); }
#dlgBody { padding: 18px; color: var(--fg2); line-height: 1.6; }
#dlgBody p { margin: 0 0 10px; }
.dlgFoot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 18px 18px; }
.dlgFoot:empty { display: none; }
.help h3 { font-size: 10.5px; letter-spacing: .14em; font-weight: 500; color: var(--fg); margin: 20px 0 8px; }
.helpCols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.keys { border-collapse: collapse; width: 100%; font-size: 11px; }
.keys th { text-align: left; font-weight: 500; font-size: 10px; letter-spacing: .14em; color: var(--mid); padding: 10px 0 4px; }
.keys tr:first-child th { padding-top: 0; }
.keys td { padding: 3px 0; vertical-align: top; }
.keys td:first-child { white-space: nowrap; padding-right: 12px; color: var(--fg); }
kbd { font: inherit; font-size: 10px; border: 1px solid var(--ln2); padding: 0 4px; color: var(--fg); }
.math { margin: 0 0 10px; padding: 10px 12px; border: 1px dashed var(--ln2); color: var(--fg); font: inherit; font-size: 11.5px; overflow-x: auto; }

#toast {
  position: fixed; left: 50%; bottom: 44px; transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 7px 14px; font-size: 11px; letter-spacing: .06em;
  z-index: 60; max-width: calc(100vw - 32px); pointer-events: none; animation: rise .16s ease-out;
}
#toast.err { background: var(--bg); color: var(--fg); border: 1px dashed var(--fg); }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 6px); } }

/* ── narrow screens ─────────────────────── */

@media (max-width: 1100px) {
  .tools button .k { display: none; }
  .brand { flex-basis: 170px; }
}
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr) minmax(0, 42vh) 26px; }
  #top { flex-wrap: wrap; gap: 8px; padding: 8px 16px; }
  .brand { flex: 1 1 100%; }
  .tools { margin: 0; order: 3; flex: 1 1 100%; display: flex; }
  .tools button { flex: 1; padding: 0 4px; }
  .actions { margin-left: auto; }
  #stage { grid-row: 2; grid-column: 1; }
  #side { grid-row: 3; grid-column: 1; border-right: 0; border-top: 1px solid var(--ln); }
  #status { gap: 10px; }
  #stTool, #stSave, #status .sep { display: none; }
  .helpCols { grid-template-columns: 1fr; }
  #loupeCv { width: 128px; height: 128px; }
  .ascii { font-size: 8px; }
}
