html, body {
  margin: 0; height: 100%; background: #23262b; overflow: hidden; color: #e8eaed;
  font: 14px system-ui, sans-serif; -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

#board { position: absolute; inset: 0; overflow: hidden; }
#paper, #nav {
  background:
    linear-gradient(#cfd5dd, #cfd5dd) 33.333% 0 / 1px 100% no-repeat,
    linear-gradient(#cfd5dd, #cfd5dd) 66.667% 0 / 1px 100% no-repeat,
    linear-gradient(#cfd5dd, #cfd5dd) 0 33.333% / 100% 1px no-repeat,
    linear-gradient(#cfd5dd, #cfd5dd) 0 66.667% / 100% 1px no-repeat,
    #fff;
}
#paper { position: absolute; box-shadow: 0 2px 16px rgba(0,0,0,.4); }
.pg {
  position: fixed; z-index: 3; width: 34px; height: 64px; padding: 0; border: 0; border-radius: 8px;
  background: rgba(35,38,43,.72); color: #e8eaed; font: 28px/1 system-ui, sans-serif; cursor: pointer;
  touch-action: manipulation;
}
.pg:hover { background: rgba(35,38,43,.92); }
#pgL { left: 6px; top: 50%; margin-top: -32px; }
#pgR { right: 6px; top: 50%; margin-top: -32px; }
#pgU { left: 50%; top: 72px; margin-left: -17px; transform: rotate(90deg); }
#pgD { left: 50%; bottom: 40px; margin-left: -17px; transform: rotate(90deg); }
canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none;
  transform-origin: 0 0; -webkit-touch-callout: none;
}
body.edit #live { cursor: crosshair; }
body.edit.text #live { cursor: text; }
html, body { position: fixed; inset: 0; overscroll-behavior: none; touch-action: none; }
#bar, #toast, #msg { touch-action: manipulation; }
#zoomReset { min-width: 58px; font-variant-numeric: tabular-nums; }

#textEdit {
  position: absolute; z-index: 1; box-sizing: content-box; margin: 0; padding: 0; border: 0;
  outline: 1px dashed #0a66d8; outline-offset: 3px; background: rgba(255,255,255,.75);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.25; resize: none; overflow: hidden; white-space: pre;
  -webkit-user-select: text; user-select: text; touch-action: manipulation;
}

button {
  font: inherit; color: #fff; background: #3a3f47; border: 2px solid transparent;
  border-radius: 10px; min-width: 44px; min-height: 44px; padding: 0 10px; cursor: pointer;
}
button:active { background: #4a5059; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid #8ab4f8; outline-offset: 2px; }

/* ---- toolbar ---- */
#bar {
  position: fixed; top: 8px; left: 8px; z-index: 3; display: flex; flex-wrap: wrap; gap: 6px;
  padding: 6px; max-width: calc(100vw - 16px); box-sizing: border-box; align-items: center;
  background: rgba(35,38,43,.92); border-radius: 12px;
}
#bar button { width: 44px; height: 44px; padding: 0; font-size: 13px; }
#bar button.wide { width: auto; padding: 0 10px; }
#bar button.on { border-color: #fff; }
#bar .sw { border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); }
#bar .sep { width: 1px; height: 30px; background: #555; margin: 0 2px; }
#bar .tools { display: none; }
body.edit #bar .tools { display: inline-block; }
body.edit #bar #swatches { display: contents; }

/* ---- panels ---- */
.panel {
  /* Bottom right, so an open panel never covers the toolbar (top left). */
  position: fixed; bottom: 32px; right: 8px; z-index: 4; box-sizing: border-box;
  width: min(340px, calc(100vw - 16px)); max-height: calc(100% - 110px); overflow: auto;
  touch-action: pan-y;
  padding: 12px; background: rgba(35,38,43,.97); border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,.5);
}
.panel header { display: flex; align-items: center; justify-content: space-between; }
.panel h2 { margin: 0; font-size: 16px; font-weight: 600; }
.panel .hint { color: #9aa3ad; font-size: 12px; margin: 6px 0 10px; }
.panel a { color: #8ab4f8; }
.panel p { margin: 12px 0 0; }

#layerList { list-style: none; margin: 0; padding: 0; }
#layerList li {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 0;
  border-top: 1px solid #3a3f47;
}
#layerList li.dim .who, #layerList li.dim .dot { opacity: .45; }
#layerList li.off .who { text-decoration: line-through; color: #9aa3ad; }
#layerList .dot {
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.3);
}
#layerList .who { flex: 1 1 90px; min-width: 0; }
#layerList .who small { color: #9aa3ad; margin-left: 6px; }
#layerList button { font-size: 13px; }
#layerList button.danger { background: #6b2b2b; }

.link { margin-top: 10px; }
.link label { display: block; color: #9aa3ad; font-size: 12px; margin-bottom: 4px; }
.link .row { display: flex; gap: 6px; }
.link input {
  flex: 1; min-width: 0; height: 44px; box-sizing: border-box; padding: 0 8px;
  font: 12px ui-monospace, monospace; color: #e8eaed; background: #1b1d21;
  border: 1px solid #3a3f47; border-radius: 10px; -webkit-user-select: text; user-select: text;
}

/* ---- toast, message, status ---- */
#toast {
  position: fixed; left: 50%; bottom: 36px; transform: translateX(-50%); z-index: 5;
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px;
  max-width: calc(100vw - 32px); box-sizing: border-box;
  background: rgba(20,22,25,.96); border-radius: 12px; box-shadow: 0 4px 24px rgba(0,0,0,.5);
}
#toast.plain { padding: 12px 14px; }

#msg {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 6;
  width: min(360px, calc(100vw - 32px)); box-sizing: border-box; padding: 20px;
  text-align: center; background: rgba(20,22,25,.97); border-radius: 14px;
  box-shadow: 0 4px 32px rgba(0,0,0,.6);
}
#msg p { margin: 0 0 14px; font-size: 16px; }
#msg a {
  display: inline-block; line-height: 44px; padding: 0 16px; border-radius: 10px;
  background: #3a3f47; color: #fff; text-decoration: none;
}

#status {
  position: fixed; right: 10px; bottom: 8px; z-index: 2; color: #9aa3ad; font-size: 12px;
  pointer-events: none;
}
#status b {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: #c0392b; margin-right: 6px;
}
#status.ok b { background: #2ecc71; }

/* ---- moving around ---- */
body.edit.move #live, body:not(.edit) #live { cursor: grab; }
#nav {
  position: fixed; left: 8px; bottom: 8px; z-index: 3; width: 144px; height: 81px;
  border: 2px solid #23262b; border-radius: 6px;
  box-shadow: 0 2px 12px rgba(0,0,0,.5); touch-action: none; cursor: pointer; overflow: hidden;
}
#navBox {
  position: absolute; box-sizing: border-box; border: 2px solid #0a66d8;
  background: rgba(10,102,216,.18); pointer-events: none;
}

/* ---- crumple ---- */
#fx { z-index: 2; pointer-events: none; }
#shelfList { list-style: none; margin: 0; padding: 0; }
#shelfList li {
  display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid #3a3f47;
}
#shelfList canvas {
  position: static; width: 128px; height: 72px; flex: none; background: #fff; border-radius: 4px;
}
#shelfList .who { flex: 1; min-width: 0; }
#shelfList .who small { display: block; color: #9aa3ad; }

/* ---- narrow screens: one row of tools that scrolls sideways ---- */
@media (max-width: 760px) {
  #bar { flex-wrap: nowrap; overflow-x: auto; overscroll-behavior: contain; touch-action: pan-x; scrollbar-width: none; }
  #bar::-webkit-scrollbar { display: none; }
  #bar button, #bar .sep { flex: none; }
}
