/* ============================================================================
   HOLOCLOTH  ·  stylesheet
   ----------------------------------------------------------------------------
   Port of Holocloth by Dmitry Kurash (MIT, see LICENSE). New in the port:
   upstream styles its panel with DialKit. This sheet draws a panel in the same
   form: dark card, rounded rows, sliders as fill bars with the value at the
   right. The fonts are the system UI face and the system monospace face.
     grep -n 'PANEL'      the desktop card at the top right
     grep -n 'CONTROLS'   slider, select, color, toggle, action, chip rows
     grep -n 'TOUCH'      44px targets on any coarse pointer
     grep -n 'PHONE'      dock and bottom sheet
     grep -n 'LANDSCAPE'  the right drawer on a short landscape screen
   ========================================================================== */
:root{
  --bg:#0b0c12; --card:rgba(24,24,28,0.94); --row:rgba(255,255,255,0.055);
  --row-hi:rgba(255,255,255,0.09); --fill:rgba(255,255,255,0.13);
  --line:rgba(255,255,255,0.07); --ink:#e6e7ec; --dim:#9b9ca6; --faint:#5b5c66;
  --accent:#c9d8ff; --panel-w:300px;
  --ui:ui-sans-serif,system-ui,-apple-system,'Segoe UI',Roboto,'Helvetica Neue',Arial,sans-serif;
  --mono:ui-monospace,'SF Mono',Menlo,Consolas,'Liberation Mono',monospace;
}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html,body{width:100%;height:100%;overflow:hidden;background:var(--bg);overscroll-behavior:none}
body{font-family:var(--ui);color:var(--ink);-webkit-font-smoothing:antialiased;font-size:13px}
button,select,input{font:inherit;color:inherit}
button{touch-action:manipulation;-webkit-tap-highlight-color:transparent}

#stage{position:fixed;inset:0;opacity:0;transition:opacity 0.6s ease}
#stage.ready{opacity:1}
#stage canvas{display:block;touch-action:none}

#loader{position:fixed;inset:0;display:grid;place-items:center;background:var(--bg);z-index:100;transition:opacity 0.5s ease}
#loader.hiding{opacity:0;pointer-events:none}
#loader .arc{animation:spin 1.1s linear infinite;transform-origin:36px 36px}
@keyframes spin{to{transform:rotate(270deg)}}

#credit{
  position:fixed;left:calc(14px + env(safe-area-inset-left));bottom:calc(12px + env(safe-area-inset-bottom));z-index:20;
  font-size:11px;color:var(--dim);text-decoration:none;opacity:0.75;letter-spacing:0.01em;
}
#credit:hover{opacity:1;color:var(--ink);text-decoration:underline}

#hint{
  position:fixed;left:50%;bottom:14px;transform:translateX(-50%);z-index:20;pointer-events:none;
  font-size:11px;color:var(--dim);letter-spacing:0.04em;white-space:nowrap;transition:opacity 0.8s;
}
#hint.gone{opacity:0}
#dock,#sheetGrip{display:none}

.icon-btn{
  flex:0 0 auto;width:34px;height:34px;border:0;border-radius:9px;background:var(--row);color:var(--ink);
  cursor:pointer;font-size:15px;line-height:1;display:grid;place-items:center;
}
.icon-btn:hover{background:var(--row-hi)}
.icon-btn:disabled{opacity:0.35;cursor:default}

/* PANEL. A card at the top right, the upstream DialKit place. */
#panel{
  position:fixed;top:16px;right:16px;width:var(--panel-w);max-height:calc(100% - 32px);z-index:40;
  display:flex;flex-direction:column;background:var(--card);border:1px solid var(--line);border-radius:14px;
  box-shadow:0 12px 40px rgba(0,0,0,0.45);backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px);
  padding:10px 12px 10px;overflow-y:auto;overscroll-behavior:contain;
  transition:transform 0.28s cubic-bezier(0.4,0,0.2,1),opacity 0.2s;
}
#panel:not(.open){transform:translateX(calc(100% + 24px));opacity:0;pointer-events:none}
#panelOpen{position:fixed;top:16px;right:16px;z-index:39;width:38px;height:38px;background:var(--card);border:1px solid var(--line)}
.p-head{display:flex;align-items:center;justify-content:space-between;margin:2px 0 8px}
.p-title{font-size:15px;font-weight:600;letter-spacing:0.005em}
.p-versions{display:flex;gap:6px;padding-bottom:10px;margin-bottom:8px;border-bottom:1px solid var(--line)}
.p-versions select{
  flex:1;min-width:0;height:34px;border:0;border-radius:9px;background:var(--row);padding:0 10px;cursor:pointer;
  appearance:none;-webkit-appearance:none;
  background-image:linear-gradient(45deg,transparent 50%,var(--dim) 50%),linear-gradient(135deg,var(--dim) 50%,transparent 50%);
  background-position:calc(100% - 15px) 15px,calc(100% - 10px) 15px;background-size:5px 5px;background-repeat:no-repeat;
}
.p-credit{padding:10px 2px 2px;margin-top:6px;border-top:1px solid var(--line);font-size:11px}
.p-credit a{color:var(--dim);text-decoration:none}
.p-credit a:hover{color:var(--ink);text-decoration:underline}

.folder{border-top:1px solid var(--line);margin-top:6px;padding-top:4px}
.folder-head{
  width:100%;display:flex;justify-content:space-between;align-items:center;height:34px;padding:0 2px;
  background:none;border:0;cursor:pointer;font-weight:600;font-size:13px;
}
.folder-head .chev{color:var(--dim);transition:transform 0.2s;font-size:14px;transform:rotate(-90deg)}
.folder.open .folder-head .chev{transform:none}
.folder-body{display:none}
.folder.open .folder-body{display:block}

/* CONTROLS */
.ctl{
  position:relative;display:flex;align-items:center;gap:8px;height:36px;margin:6px 0;padding:0 11px;
  border-radius:8px;background:var(--row);overflow:hidden;user-select:none;-webkit-user-select:none;
}
.ctl .name{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;position:relative;z-index:1;pointer-events:none}
.ctl .val{font-family:var(--mono);font-size:12px;color:var(--ink);position:relative;z-index:1;pointer-events:none}
.slider .fill{position:absolute;left:0;top:0;bottom:0;background:var(--fill);pointer-events:none}
.slider input[type=range]{
  position:absolute;inset:0;width:100%;height:100%;opacity:0;cursor:ew-resize;margin:0;z-index:2;
  -webkit-appearance:none;appearance:none;touch-action:pan-y;
}
.slider:hover{background:var(--row-hi)}
.select select{
  border:0;background:transparent;color:var(--ink);cursor:pointer;text-align:right;padding-right:16px;height:100%;
  appearance:none;-webkit-appearance:none;
  background-image:linear-gradient(45deg,transparent 50%,var(--dim) 50%),linear-gradient(135deg,var(--dim) 50%,transparent 50%);
  background-position:calc(100% - 6px) 15px,calc(100% - 1px) 15px;background-size:5px 5px;background-repeat:no-repeat;
}
.select select option{background:#1c1c20;color:var(--ink)}
.color input[type=color]{width:20px;height:20px;border:1px solid rgba(255,255,255,0.18);border-radius:5px;padding:0;background:none;cursor:pointer}
.color input[type=color]::-webkit-color-swatch-wrapper{padding:0}
.color input[type=color]::-webkit-color-swatch{border:0;border-radius:4px}
.toggle{cursor:pointer}
.toggle input{position:absolute;opacity:0;width:1px;height:1px}
.toggle .switch{width:30px;height:18px;border-radius:9px;background:rgba(255,255,255,0.14);position:relative;transition:background 0.2s;flex:0 0 auto}
.toggle .switch::after{content:'';position:absolute;top:2px;left:2px;width:14px;height:14px;border-radius:50%;background:#d8d9de;transition:transform 0.2s}
.toggle input:checked + .switch{background:#6f86d6}
.toggle input:checked + .switch::after{transform:translateX(12px);background:#fff}
.toggle input:focus-visible + .switch{outline:2px solid var(--accent);outline-offset:2px}
.action{width:100%;justify-content:center;border:0;cursor:pointer;font-weight:500}
.action:hover{background:var(--row-hi)}
.action:active{background:var(--fill)}

.chip{
  display:flex;align-items:center;gap:8px;padding:5px 8px;margin:6px 0;
  background:rgba(255,255,255,0.05);border:1px solid rgba(255,255,255,0.06);border-radius:8px;font-size:11px;color:#c9cbd2;
}
.chip img{width:28px;height:28px;object-fit:cover;border-radius:4px;display:block}
.chip-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.chip-x{flex:0 0 auto;width:20px;height:20px;border:0;border-radius:5px;background:rgba(255,255,255,0.08);color:#e8e9ee;font-size:11px;cursor:pointer}

/* TOUCH. Any coarse pointer: every target is 44px or more, text 13px or more. */
@media (pointer:coarse){
  body{font-size:14px}
  .ctl{height:44px;margin:6px 0}
  .ctl .val{font-size:13px}
  .icon-btn{width:44px;height:44px;font-size:17px}
  .p-versions select{height:44px;background-position:calc(100% - 15px) 20px,calc(100% - 10px) 20px}
  .select select{background-position:calc(100% - 6px) 19px,calc(100% - 1px) 19px}
  .folder-head{height:44px;font-size:14px}
  .toggle .switch{width:40px;height:24px;border-radius:12px}
  .toggle .switch::after{width:20px;height:20px}
  .toggle input:checked + .switch::after{transform:translateX(16px)}
  .color input[type=color]{width:28px;height:28px}
  .chip-x{width:36px;height:36px;font-size:13px}
  .chip img{width:36px;height:36px}
  #credit,.p-credit{font-size:12px}
  .p-credit a{display:inline-block;padding:10px 0}
}

/* PHONE. The query matches PHONE_Q in main.js. */
@media (max-width:768px), (max-height:500px) and (pointer:coarse){
  :root{--dock-h:calc(64px + env(safe-area-inset-bottom))}
  #panelOpen{display:none}
  #hint{bottom:auto;top:calc(14px + env(safe-area-inset-top));left:16px;right:16px;transform:none;text-align:center;white-space:normal;line-height:1.6}
  #credit{left:auto;right:calc(12px + env(safe-area-inset-right));bottom:calc(var(--dock-h) + 8px);padding:6px 0}
  body:not(.panel-closed) #credit,body:not(.panel-closed) #hint{opacity:0;pointer-events:none}

  #dock{
    display:flex;position:fixed;left:0;right:0;bottom:0;z-index:45;gap:8px;align-items:center;
    padding:8px calc(10px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
    background:rgba(16,16,20,0.94);border-top:1px solid var(--line);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);
  }
  #dock > button{flex:0 0 48px;height:48px;border:1px solid var(--line);border-radius:12px;background:var(--row);font-size:18px;cursor:pointer}
  #dock > button.on{border-color:rgba(201,216,255,0.5);color:var(--accent)}
  .seg{flex:1;display:flex;height:48px;min-width:0;border:1px solid var(--line);border-radius:12px;overflow:hidden}
  .seg button{flex:1;min-width:0;border:0;border-right:1px solid var(--line);background:var(--row);color:var(--dim);font-size:12px;font-weight:600;letter-spacing:0.04em;cursor:pointer}
  .seg button:last-child{border-right:0}
  .seg button.on{background:rgba(201,216,255,0.14);color:#fff}

  /* The panel is a bottom sheet above the dock. */
  #panel{
    top:auto;left:0;right:0;bottom:var(--dock-h);width:auto;max-height:none;
    height:min(50vh,540px);height:min(50dvh,540px);
    border-radius:18px 18px 0 0;border-bottom:0;box-shadow:0 -8px 30px rgba(0,0,0,0.4);
    padding:0 calc(14px + env(safe-area-inset-right)) 18px calc(14px + env(safe-area-inset-left));
    transform:translateY(calc(100% + var(--dock-h)));opacity:1;display:block;
    transition:transform 0.3s cubic-bezier(0.4,0,0.2,1),height 0.3s cubic-bezier(0.4,0,0.2,1);
    -webkit-overflow-scrolling:touch;
  }
  #panel:not(.open){transform:translateY(calc(100% + var(--dock-h)));opacity:1}
  #panel.open{transform:translateY(0)}
  #panel.full{height:calc(100vh - var(--dock-h) - 40px);height:calc(100dvh - var(--dock-h) - 40px)}
  #panelClose{display:none}
  #sheetGrip{
    display:flex;position:sticky;top:0;z-index:3;justify-content:center;align-items:center;height:36px;margin:0 -14px;
    background:linear-gradient(180deg,rgba(24,24,28,1) 65%,rgba(24,24,28,0));touch-action:none;cursor:grab;
  }
  #sheetGrip span{width:46px;height:5px;border-radius:3px;background:var(--dim);opacity:0.6}
}

/* LANDSCAPE phone. The panel is a drawer on the right edge, and the dock is
   a tab at the lower left. */
@media (max-height:500px) and (orientation:landscape){
  #dock{right:auto;width:min(440px,56vw);border-right:1px solid var(--line);border-radius:0 16px 0 0}
  #credit{bottom:calc(8px + env(safe-area-inset-bottom));right:calc(12px + env(safe-area-inset-right))}
  #panel,#panel.full{
    top:0;bottom:0;left:auto;right:0;width:min(46vw,380px);height:auto;
    border-radius:0;border:0;border-left:1px solid var(--line);
    padding:0 calc(14px + env(safe-area-inset-right)) 16px 14px;
    transform:translateX(100%);
  }
  #panel:not(.open){transform:translateX(100%)}
  #panel.open{transform:translateX(0)}
  #sheetGrip{display:none}
  #panelClose{display:grid;position:sticky;top:8px}
  .p-head{position:sticky;top:0;z-index:3;background:rgba(24,24,28,1);padding-top:8px;margin-top:0}
}
