/* App shell */
:root {
  --shell-bg: #111214;
  --shell-fg: #e8e8ea;
  --shell-muted: #9a9ca3;
  --shell-card: #1d1f23;
  --shell-line: #2e3137;
  --shell-accent: #ff9f0a;
  --log-w: 240px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--shell-bg); color: var(--shell-fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}
body[data-calc="ios-basic"], body[data-calc="ios-sci"] { background: #000; }
body[data-calc="fx991cw"] { background: #2a2b2e; }
body[data-calc="ba2"] { background: #3a3c40; }

#stage {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  bottom: env(safe-area-inset-bottom, 0px);
  left: env(safe-area-inset-left, 0px);
  right: env(safe-area-inset-right, 0px);
  overflow: hidden;
}
body.with-log #stage { right: var(--log-w); }
.calc-root { position: absolute; inset: 0; }

.shell-btn {
  position: fixed; z-index: 20;
  top: calc(env(safe-area-inset-top, 0px) + 6px);
  width: 34px; height: 34px; border-radius: 17px;
  border: 0; padding: 0; display: grid; place-items: center;
  color: rgba(255, 255, 255, .75); background: rgba(128, 128, 128, .22);
  cursor: pointer; opacity: .55; transition: opacity .15s;
}
.shell-btn:hover, .shell-btn:focus-visible { opacity: 1; }
#switcher { left: calc(env(safe-area-inset-left, 0px) + 6px); }
#logToggle { right: calc(env(safe-area-inset-right, 0px) + 6px); }
body.with-log #logToggle { right: calc(var(--log-w) + 6px); }
@media (max-width: 899px) { #logToggle { display: none; } }

#keylog {
  position: fixed; top: 0; right: 0; bottom: 0; width: var(--log-w); z-index: 10;
  background: var(--shell-card); border-left: 1px solid var(--shell-line);
  display: flex; flex-direction: column; font-size: 13px;
}
#keylog header { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--shell-line); color: var(--shell-muted); }
#keylog header button { background: none; border: 1px solid var(--shell-line); color: var(--shell-fg); border-radius: 6px; padding: 3px 8px; cursor: pointer; }
#keylogList { list-style: none; margin: 0; padding: 8px 10px; overflow-y: auto; flex: 1; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 4px; }
#keylogList li { font: 12px/1 ui-monospace, Menlo, monospace; padding: 4px 6px; border-radius: 4px; background: #2a2d33; }

#picker, #help {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0, 0, 0, .6);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  display: grid; place-items: center; padding: 16px;
}
#picker[hidden], #help[hidden], #keylog[hidden] { display: none; }
.picker-card {
  width: min(420px, 100%); max-height: 100%; overflow: auto;
  background: var(--shell-card); border: 1px solid var(--shell-line);
  border-radius: 18px; padding: 22px 18px 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  -webkit-user-select: text; user-select: text;
}
.picker-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.01em; }
.picker-card h2 { margin: 0 0 12px; font-size: 18px; }
.picker-sub { margin: 0 0 14px; color: var(--shell-muted); font-size: 14px; }
#pickerList { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.picker-item {
  width: 100%; display: flex; align-items: center; gap: 14px; text-align: left;
  padding: 12px; border-radius: 12px; border: 1px solid var(--shell-line);
  background: #24272c; color: var(--shell-fg); cursor: pointer; font: inherit;
}
.picker-item:hover, .picker-item:focus-visible { border-color: var(--shell-accent); outline: none; }
.pi-text { display: grid; gap: 2px; }
.pi-text strong { font-size: 16px; font-weight: 600; }
.pi-text small { color: var(--shell-muted); font-size: 13px; }
.pi-swatch { width: 36px; height: 52px; border-radius: 6px; flex: none; position: relative; overflow: hidden; }
.picker-fx991cw .pi-swatch { background: linear-gradient(#1b1c1e 0 12%, #c6ccbd 12% 34%, #1b1c1e 34%); }
.picker-fx991cw .pi-swatch::after { content: ""; position: absolute; left: 6px; right: 6px; top: 58%; height: 30%; background: radial-gradient(circle, #8c8d90 2.2px, transparent 2.6px) 0 0 / 8px 8px; }
.picker-ba2 .pi-swatch { background: linear-gradient(#111 0 8%, #b9c0a8 8% 26%, #111 26%); border: 2px solid #8e9196; }
.picker-ba2 .pi-swatch::after { content: ""; position: absolute; left: 5px; right: 5px; top: 54%; height: 36%; background: radial-gradient(circle, #9b9c9e 2px, transparent 2.4px) 0 0 / 7px 7px; }
.picker-ios-basic .pi-swatch, .picker-ios-sci .pi-swatch { background: #000; border: 1px solid #333; }
.picker-ios-basic .pi-swatch::after { content: ""; position: absolute; left: 4px; right: 4px; top: 45%; bottom: 4px; background: radial-gradient(circle, #ff9f0a 2.6px, transparent 3px) 100% 0 / 7px 7px repeat-y, radial-gradient(circle, #555 2.6px, transparent 3px) 0 0 / 7px 7px; }
.picker-ios-sci .pi-swatch::after { content: ""; position: absolute; left: 3px; right: 3px; top: 30%; bottom: 4px; background: radial-gradient(circle, #ff9f0a 2px, transparent 2.3px) 100% 60% / 5px 5px repeat-y, radial-gradient(circle, #555 2px, transparent 2.3px) 0 0 / 5px 5px; }
.picker-hint { color: var(--shell-muted); font-size: 12px; margin: 14px 2px 0; line-height: 1.5; }
kbd { font: 11px ui-monospace, Menlo, monospace; padding: 1px 4px; border: 1px solid var(--shell-line); border-radius: 4px; background: #2a2d33; }
.help-card table { width: 100%; border-collapse: collapse; font-size: 13px; }
.help-card td { padding: 5px 6px; border-bottom: 1px solid var(--shell-line); vertical-align: top; }
.help-card td:first-child { font-family: ui-monospace, Menlo, monospace; white-space: nowrap; color: var(--shell-accent); }
.help-card button { margin-top: 14px; width: 100%; padding: 10px; border-radius: 10px; border: 0; background: #34373d; color: var(--shell-fg); font: inherit; cursor: pointer; }
