:root{ --felt:#201d19; --stitch:rgba(255,240,210,.14); --label:rgba(240,230,210,.28); }
  *{margin:0;padding:0;box-sizing:border-box;-webkit-tap-highlight-color:transparent}
  html,body{height:100%;overflow:hidden}
  body{
    background:
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='0.16'/%3E%3C/svg%3E"),
      var(--felt);
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    touch-action:none; user-select:none; -webkit-user-select:none;
    color:var(--label);
  }
  @font-face{
    font-family:'CaoShu';
    src:url('caoshu.woff2') format('woff2');
    unicode-range:U+534e,U+5bb9,U+9053;
  }
  #title{
    position:fixed;top:18px;left:0;right:0;text-align:center;z-index:5;
    font-family:'CaoShu',"Xingkai SC","Baoli SC","Kaiti SC",serif;font-size:34px;font-weight:400;
    letter-spacing:.4em;text-indent:.4em;color:rgba(240,230,210,.62);
  }
  #hint{position:fixed;top:72px;left:0;right:0;text-align:center;font-size:11px;letter-spacing:.08em;opacity:.55;z-index:5}
  #clock{position:fixed;font-size:11px;letter-spacing:.18em;z-index:5;opacity:.8;text-align:right;line-height:1.9}
  #reset{
    position:fixed;z-index:5;
    font:inherit;font-size:11px;letter-spacing:.2em;color:var(--label);
    background:none;border:none;padding:7px 2px;cursor:pointer;
  }
  #reset:hover{color:rgba(240,230,210,.8)}
  #ranksBtn{
    position:fixed;z-index:5;
    font:inherit;font-size:11px;letter-spacing:.2em;color:var(--label);
    background:none;border:none;padding:7px 2px;cursor:pointer;
  }
  #ranksBtn:hover{color:rgba(240,230,210,.8)}
  #levels{position:fixed;transform:translateX(-50%);display:flex;gap:20px;z-index:5}
  #footer{
    position:fixed;bottom:16px;left:0;right:0;text-align:center;z-index:5;
    font-size:11px;letter-spacing:.18em;color:rgba(240,230,210,.3);
  }
  #twt{color:inherit;text-decoration:none;cursor:pointer}
  #twt:hover{color:rgba(240,230,210,.8)}
  #heart{
    font:inherit;font-size:15px;line-height:1;background:none;border:none;cursor:pointer;
    color:#b8452e;display:inline-block;padding:0 3px;vertical-align:-2px;
    transform-origin:center;transition:transform .18s ease;
  }
  #heart:hover{transform:scale(1.3)}
  #heart.beat{animation:beat .5s ease}
  @keyframes beat{0%{transform:scale(1)}30%{transform:scale(1.5)}55%{transform:scale(1.08)}75%{transform:scale(1.32)}100%{transform:scale(1)}}
  #hcount{color:#b8452e;opacity:.8;font-size:10px;letter-spacing:.08em;margin-right:5px}
  #levels button{
    font:inherit;font-size:10px;letter-spacing:.18em;color:rgba(240,230,210,.25);
    background:none;border:none;padding:6px 2px;cursor:pointer;position:relative;
  }
  #levels button:hover{color:rgba(240,230,210,.6)}
  #levels button.on{color:rgba(240,230,210,.7)}
  #levels button.on::after{
    content:'';position:absolute;left:50%;transform:translateX(-50%);bottom:-3px;
    width:3px;height:3px;border-radius:50%;background:#b8452e;
  }

  /* wooden tray: thick rails, recessed board, a real cut for the gate */
  #tray{
    position:absolute;border-radius:12px;
    background:
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.10'/%3E%3C/svg%3E"),
      repeating-linear-gradient(88deg, rgba(42,30,16,.12) 0 2px, rgba(0,0,0,0) 2px 7px),
      linear-gradient(#5e4a35, #4c3b29);
    box-shadow:0 8px 22px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,235,205,.16), inset 0 -2px 3px rgba(0,0,0,.3);
  }
  #board{
    position:absolute;border-radius:5px;
    background:
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E"),
      repeating-linear-gradient(2deg, rgba(48,36,20,.08) 0 2px, rgba(0,0,0,0) 2px 9px),
      linear-gradient(#7b684c, #706045);
    box-shadow:inset 0 6px 16px rgba(0,0,0,.52), inset 0 2px 4px rgba(0,0,0,.35), inset 0 -1px 0 rgba(255,235,200,.1);
  }
  #gateCut{
    position:absolute;z-index:1;
    background:linear-gradient(#8a6842, #7b5a38 70%, rgba(32,29,25,.9));
    border-radius:0 0 4px 4px;
    box-shadow:inset 6px 0 6px -3px rgba(0,0,0,.65), inset -6px 0 6px -3px rgba(0,0,0,.65), inset 0 3px 5px -2px rgba(0,0,0,.4);
  }

  .blk{
    position:absolute;left:0;top:0;border-radius:3px;cursor:grab;z-index:2;
    background-size:100% 100%;
    box-shadow:
      0 2px 0 rgba(52,36,20,.55),          /* the block's visible side */
      0 5px 8px rgba(0,0,0,.42),
      0 12px 20px rgba(0,0,0,.22);
    will-change:transform;
  }
  .blk.drag{cursor:grabbing;box-shadow:
      0 3px 0 rgba(52,36,20,.45),
      0 12px 20px rgba(0,0,0,.5),
      0 24px 40px rgba(0,0,0,.28);z-index:6}
  .blk.settle{transition:transform .12s ease-out}
  .blk.exit{transition:transform .8s cubic-bezier(.4,.1,.4,1), opacity .8s;opacity:0}

  /* ── the finished painting: mounted straight, solemn ── */
  #veil{
    position:fixed;inset:0;z-index:20;display:flex;flex-direction:column;
    align-items:center;justify-content:center;gap:18px;
    background:rgba(12,10,8,.62);backdrop-filter:blur(4px);
    opacity:0;pointer-events:none;transition:opacity .9s;
  }
  #veil.show{opacity:1;pointer-events:auto}
  #artwrap{position:relative;filter:drop-shadow(0 26px 70px rgba(0,0,0,.6))}
  #artimg{
    display:block;
    width:min(78vw, 66vh * .8);
    aspect-ratio: 4 / 5;
  }
  #sealLink{
    position:absolute;
    left:81.8%; top:86.9%; width:9.4%; height:7.5%;
    cursor:pointer;
  }
  #veil.show #artwrap{animation:mountIn 1s cubic-bezier(.25,.7,.3,1) backwards}
  @keyframes mountIn{from{opacity:0;transform:translateY(26px)}}
  #cardbtns{display:flex;gap:10px;width:min(78vw, 66vh * .8)}
  #cardbtns button{
    flex:1;font:inherit;font-size:11px;letter-spacing:.22em;padding:9px 0;cursor:pointer;
  }
  #dl{background:rgba(240,232,216,.92);color:#37312a;border:1px solid rgba(240,232,216,.92)}
  #dl:hover{background:#fff}
  #again{background:none;color:rgba(240,230,210,.55);border:1px solid rgba(240,230,210,.3)}
  #modeBtn{background:none;color:rgba(240,230,210,.55);border:1px solid rgba(240,230,210,.3)}
  #modeBtn:hover{color:rgba(240,230,210,.9);border-color:rgba(240,230,210,.6)}
  #closeBoard{background:none;color:rgba(240,230,210,.55);border:1px solid rgba(240,230,210,.3)}
  #closeBoard:hover{color:rgba(240,230,210,.9);border-color:rgba(240,230,210,.6)}
  /* the sheet arrives two ways: after a solve, or from the board button */
  #veil #closeBoard, #veil #boardLevels{display:none}
  #veil.board #dl, #veil.board #modeBtn, #veil.board #again{display:none}
  #veil.board #closeBoard{display:block}
  #veil.board #boardLevels{display:flex}
  #boardLevels{gap:10px;width:min(78vw, 66vh * .8);margin-bottom:-6px}
  #boardLevels button{
    flex:1;font:inherit;font-size:11px;letter-spacing:.22em;padding:9px 0;cursor:pointer;
    background:none;color:rgba(240,230,210,.35);border:1px solid rgba(240,230,210,.16);
  }
  #boardLevels button:hover{color:rgba(240,230,210,.7);border-color:rgba(240,230,210,.35)}
  #boardLevels button.on{color:rgba(240,230,210,.85);border-color:rgba(240,230,210,.5)}
  #boardLevels button.on::after{
    content:'';display:block;width:3px;height:3px;border-radius:50%;background:#b8452e;
    margin:5px auto -8px;
  }
  #again:hover{color:rgba(240,230,210,.9);border-color:rgba(240,230,210,.6)}
