/*!
 * Eagle Board — a Twelve Cross game on the Jiroft eagle board
 * Copyright (c) 2026 The Game Intelligence. All rights reserved.
 * https://thegameintelligence.com
 */
  :root{
    --bg:#f7f5f1;
    --panel:#fffdf9;
    --panel-border:#e7e0d0;
    --gauntlet:#d9a441;
    --gauntlet-dark:#b6852b;
    --gold:#a9791f;
    --danger:#a1372c;
    --safe-color:#2f8fd8;
    --white-piece:#f7f3ea;
    --white-ring:#2a2a28;
    --black-piece:#1c1a15;
    --black-ring:#d8cfb6;
    --text:#2a2619;
    --text-dim:#786f5a;
    --roll-blue:#8fcfea;
    --roll-blue-dark:#5da3c4;
    --highlight-blue:#2f8fd8;
    --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-display: -apple-system, BlinkMacSystemFont, "Segoe UI Semibold", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
    --cell-w:clamp(32px,6.2vw,46px);
    --board-gap:clamp(1px,0.4vw,2px);
    --board-pad:clamp(6px,1.8vw,10px);
    --board-min-w:clamp(158px,42vw,206px);
    font-size:16px;
  }
  *{box-sizing:border-box;}
  html,body{margin:0;padding:0; overflow-x:hidden; width:100%;}
  body{
    background:
      radial-gradient(1100px 650px at 12% -10%, #ffffff 0%, transparent 55%),
      radial-gradient(900px 600px at 105% 5%, #eef1f3 0%, transparent 60%),
      radial-gradient(1000px 750px at 50% 115%, #f6efe0 0%, transparent 55%),
      var(--bg);
    color:var(--text);
    font-family:var(--font-body);
    min-height:100vh;
    display:flex;
    flex-direction:column;
    align-items:center;
    padding:clamp(8px,2.5vw,16px) 10px 20px;
    overflow-x:hidden;
  }

  .turn-flash{
    position:fixed;
    top:50%;
    left:50%;
    transform:translate(-50%,-50%) scale(0.82);
    font-family:var(--font-display);
    font-size:clamp(2rem,9vw,3.6rem);
    letter-spacing:0.06em;
    text-transform:uppercase;
    color:#fff;
    background:rgba(20,18,14,0.84);
    padding:16px 40px;
    border-radius:14px;
    box-shadow:0 10px 34px rgba(0,0,0,0.35);
    opacity:0;
    pointer-events:none;
    z-index:200;
    transition:opacity .25s ease, transform .25s ease;
    white-space:nowrap;
  }
  .turn-flash.show{
    opacity:1;
    transform:translate(-50%,-50%) scale(1);
  }

  .table{
    display:flex;
    align-items:flex-start;
    justify-content:center;
    gap:18px;
    flex-wrap:wrap;
    width:100%;
    max-width:900px;
  }

  /* ---------- side panels ---------- */
  .panel{
    width:158px;
    flex:0 1 158px;
    background:var(--panel);
    border:1px solid var(--panel-border);
    border-radius:10px;
    padding:14px 12px;
    box-shadow:0 2px 14px rgba(60,50,20,0.06);
  }
  .panel-head{
    display:flex;
    align-items:center;
    justify-content:center;
    gap:8px;
    margin-bottom:12px;
  }
  .panel-name{
    font-family:var(--font-display);
    font-size:1.25rem;
    letter-spacing:0.02em;
    text-transform:uppercase;
    color:var(--text);
  }
  .section-label{
    font-family:var(--font-mono);
    font-size:0.62rem;
    letter-spacing:0.1em;
    text-transform:uppercase;
    color:var(--text-dim);
    margin:10px 0 6px;
  }
  .tray{
    display:flex;
    flex-wrap:wrap;
    gap:6px;
    padding:6px;
    border-radius:8px;
    background:rgba(0,0,0,0.035);
    box-shadow:inset 0 0 0 1px var(--panel-border);
    min-height:40px;
    transition:box-shadow .2s ease;
    touch-action:manipulation;
  }
  .tray.movable{
    box-shadow:0 0 0 3px var(--highlight-blue), 0 0 16px 3px rgba(47,143,216,0.7);
    cursor:pointer;
    animation:flashBlue 0.85s ease-in-out infinite;
  }
  .finished-row{
    display:flex;
    gap:4px;
    flex-wrap:wrap;
  }
  .slot{
    width:clamp(12px,3.2vw,16px);height:clamp(12px,3.2vw,16px);border-radius:50%;
    background:rgba(0,0,0,0.03);
    box-shadow:inset 0 0 0 1px rgba(0,0,0,0.14);
  }
  .slot.filled.white{background:var(--white-piece); box-shadow:inset 0 0 0 1px var(--white-ring);}
  .slot.filled.black{background:var(--black-piece); box-shadow:inset 0 0 0 1px var(--black-ring);}

  .piece{
    width:clamp(16px,5vw,24px);height:clamp(16px,5vw,24px);
    border-radius:50%;
    display:inline-block;
  }
  .piece.white{background:radial-gradient(circle at 32% 28%, #ffffff, var(--white-piece) 60%); box-shadow:inset 0 0 0 2px var(--white-ring), 0 1px 2px rgba(0,0,0,0.4);}
  .piece.black{background:radial-gradient(circle at 32% 28%, #3a362c, var(--black-piece) 65%); box-shadow:inset 0 0 0 2px var(--black-ring), 0 1px 2px rgba(0,0,0,0.5);}

  /* ---------- board ---------- */
  .board-wrap{
    background:var(--panel);
    border:1px solid var(--panel-border);
    border-radius:10px;
    padding:var(--board-pad);
    box-shadow:0 2px 14px rgba(60,50,20,0.06);
    flex:0 0 auto;
    display:flex;
    flex-direction:column;
    align-items:center;
    gap:8px;
    width:max(calc(3 * var(--cell-w) + 2 * var(--board-gap) + 2 * var(--board-pad)), var(--board-min-w));
    box-sizing:border-box;
  }
  .board{
    display:grid;
    grid-template-columns:repeat(3, var(--cell-w));
    grid-auto-rows:var(--cell-w);
    gap:var(--board-gap);
  }
  .cell{
    position:relative;
    border-radius:50%;
    background:#ffffff;
    border:1px solid #000000;
    display:flex;
    align-items:center;
    justify-content:center;
    touch-action:manipulation;
  }
  .cell.safe{
    background:#fbf6e6;
  }
  .cell.safe .cross{
    position:absolute;
    width:56%;
    height:56%;
    pointer-events:none;
    opacity:0.6;
  }
  .cell.safe .cross::before,
  .cell.safe .cross::after{
    content:'';
    position:absolute;
    top:50%; left:50%;
    width:16%; height:100%;
    background:var(--safe-color);
    border-radius:2px;
    transform-origin:center;
  }
  .cell.safe .cross::before{
    transform:translate(-50%,-50%) rotate(45deg);
  }
  .cell.safe .cross::after{
    transform:translate(-50%,-50%) rotate(-45deg);
  }
  .cell.start{box-shadow:inset 0 0 0 2px rgba(0,0,0,0.18);}
  .cell.movable{
    box-shadow:0 0 0 3px var(--highlight-blue), 0 0 18px 4px rgba(47,143,216,0.75);
    cursor:pointer;
    animation:flashBlue 0.85s ease-in-out infinite;
    z-index:2;
  }
  @keyframes flashBlue{
    0%,100%{ filter:brightness(1); box-shadow:0 0 0 3px var(--highlight-blue), 0 0 18px 4px rgba(47,143,216,0.75); }
    50%{ filter:brightness(1.22); box-shadow:0 0 0 4px var(--highlight-blue), 0 0 26px 8px rgba(47,143,216,0.95); }
  }

  .legend{
    display:flex;
    gap:14px;
    flex-wrap:wrap;
    justify-content:center;
    font-family:var(--font-mono);
    font-size:0.66rem;
    color:var(--text-dim);
    text-transform:uppercase;
    letter-spacing:0.03em;
  }
  .legend .dot{
    width:10px;height:10px;border-radius:50%;
    display:inline-block;
    margin-right:5px;
    vertical-align:middle;
  }
  .legend .dot.safe{background:var(--safe-color);}
  .legend .dot.p1{background:rgba(47,143,216,0.85);}
  .legend .dot.p2{background:rgba(211,64,140,0.85);}
  .legend .dot.shared{background:rgba(182,133,43,0.85);}
  #guide-legend{display:none;}
  #guide-legend.show{display:flex;}

  /* ---------- route guide ---------- */
  .board.guide-active .cell[data-col="0"]{box-shadow:inset 0 0 0 2px rgba(47,143,216,0.55);}
  .board.guide-active .cell[data-col="2"]{box-shadow:inset 0 0 0 2px rgba(211,64,140,0.55);}
  .board.guide-active .cell[data-col="1"]{box-shadow:inset 0 0 0 2px rgba(182,133,43,0.55);}
  .guide-tag{
    position:absolute;
    bottom:1px;
    left:50%;
    transform:translateX(-50%);
    font-family:var(--font-mono);
    font-size:clamp(0.36rem,1.4vw,0.48rem);
    letter-spacing:0.02em;
    line-height:1.15;
    text-align:center;
    color:#fff;
    background:rgba(20,20,20,0.72);
    padding:1px 3px;
    border-radius:3px;
    white-space:nowrap;
    pointer-events:none;
    z-index:6;
  }
  .guide-arrow{
    position:absolute;
    top:50%;
    left:50%;
    transform:translate(-50%,-50%);
    font-size:clamp(0.9rem,3.4vw,1.3rem);
    color:var(--highlight-blue);
    pointer-events:none;
    z-index:6;
    animation:guideBounce 1.2s ease-in-out infinite;
  }
  .guide-arrow.exit{color:var(--danger);}
  @keyframes guideBounce{
    0%,100%{ opacity:0.55; }
    50%{ opacity:1; }
  }

  /* ---------- controls ---------- */
  .controls{
    margin-top:0;
    display:flex;
    flex-direction:column;
    align-items:center;
    gap:10px;
    width:100%;
    max-width:100%;
    padding:0 4px;
  }
  .die-row{
    display:flex;
    flex-wrap:wrap;
    align-items:center;
    justify-content:center;
    gap:12px;
    row-gap:8px;
  }
  .die-frame{
    width:clamp(52px,14vw,68px);
    height:clamp(52px,14vw,68px);
    flex-shrink:0;
    display:flex;
    align-items:center;
    justify-content:center;
    overflow:hidden;
    contain:layout paint size;
    cursor:default;
    touch-action:manipulation;
    -webkit-tap-highlight-color:transparent;
    border-radius:16px;
  }
  .die-frame.ready{
    cursor:pointer;
  }
  .die-face{
    width:100%;
    height:100%;
    object-fit:contain;
    filter:drop-shadow(0 4px 6px rgba(60,50,20,0.28));
    transform-origin:50% 50%;
    will-change:transform;
  }
  .die-frame.ready .die-face{
    animation:diePulse 1.3s ease-in-out infinite;
  }
  @keyframes diePulse{
    0%,100%{ transform:scale(1); filter:brightness(1); }
    50%{ transform:scale(0.93); filter:brightness(1.1) drop-shadow(0 0 8px rgba(47,143,216,0.65)); }
  }
  .die-face.rolling{animation:shake .22s ease-in-out infinite;}
  @keyframes shake{
    0%{transform:rotate(-6deg) scale(0.92);}
    50%{transform:rotate(6deg) scale(0.92);}
    100%{transform:rotate(-6deg) scale(0.92);}
  }

  button{
    font-family:var(--font-display);
    font-size:clamp(1.05rem,3.2vw,1.15rem);
    letter-spacing:0.04em;
    text-transform:uppercase;
    padding:12px 24px;
    min-height:46px;
    border-radius:8px;
    border:none;
    cursor:pointer;
    background:var(--gauntlet);
    color:#20241d;
    box-shadow:0 3px 0 var(--gauntlet-dark);
    transition:transform .05s ease, filter .15s ease;
    touch-action:manipulation;
  }
  button:hover:not(:disabled){filter:brightness(1.08);}
  button:active:not(:disabled){transform:translateY(2px); box-shadow:0 1px 0 var(--gauntlet-dark);}
  button:disabled{
    opacity:0.35;
    cursor:default;
    box-shadow:none;
  }

  .icon-row{
    display:flex;
    flex-wrap:wrap;
    justify-content:center;
    gap:clamp(8px,2.5vw,14px);
    margin-top:2px;
  }
  .icon-btn{
    width:clamp(38px,10vw,46px);
    height:clamp(38px,10vw,46px);
    min-height:clamp(38px,10vw,46px);
    border-radius:50%;
    display:flex;
    align-items:center;
    justify-content:center;
    background:var(--panel);
    color:var(--text-dim);
    border:1px solid var(--panel-border);
    box-shadow:0 2px 8px rgba(60,50,20,0.08);
    font-family:var(--font-display);
    font-size:1.3rem;
    padding:0;
    line-height:1;
  }
  .icon-btn:hover:not(:disabled){color:var(--text); border-color:var(--text-dim); filter:none;}
  .icon-btn:active:not(:disabled){transform:translateY(1px); box-shadow:0 1px 4px rgba(60,50,20,0.1);}
  .icon-btn.muted{color:var(--danger); border-color:var(--danger);}
  .icon-btn.active{background:var(--highlight-blue); color:#fff; border-color:var(--highlight-blue);}

  .win-overlay{
    position:fixed;inset:0;
    background:rgba(10,18,14,0.86);
    display:none;
    align-items:center;justify-content:center;
    flex-direction:column;
    gap:16px;
    z-index:50;
    text-align:center;
    padding:20px;
  }
  .win-overlay.show{display:flex;}
  .win-overlay h2{
    font-family:var(--font-display);
    font-size:3rem;
    color:var(--gold);
    margin:0;
    text-transform:uppercase;
  }

  @media (max-width:700px){
    body{padding-top:8px; padding-bottom:24px;}
    .table{
      display:flex;
      flex-direction:row;
      flex-wrap:wrap;
      align-items:flex-start;
      justify-content:center;
      gap:clamp(4px,2vw,10px);
    }
    .board-wrap{
      gap:8px;
    }
    .panel{
      width:clamp(56px,18vw,84px);
      max-width:84px;
      flex:0 1 clamp(56px,18vw,84px);
      padding:6px 4px;
    }
    .panel-name{font-size:clamp(0.85rem,3.6vw,1.05rem);}
    .panel-head{margin-bottom:6px;}
    .section-label{font-size:0.52rem; margin:5px 0 3px; letter-spacing:0.04em;}
    .tray{
      justify-content:center;
      min-height:auto;
      gap:4px;
      padding:4px;
    }
    .finished-row{
      justify-content:center;
      gap:3px;
    }
  }
  @media (max-width:380px){
    .panel{width:clamp(50px,17vw,70px);}
    .die-frame{width:clamp(44px,12vw,58px); height:clamp(44px,12vw,58px);}
  }
  @media (max-height:520px) and (orientation:landscape){
    :root{ --cell-w:clamp(19px,4.2vh,28px); --board-gap:1px; --board-pad:5px; --board-min-w:150px; }
    body{padding-top:4px; padding-bottom:8px;}
    .board-wrap{gap:5px;}
    .die-frame{width:clamp(32px,9vw,42px); height:clamp(32px,9vw,42px);}
    .icon-btn{width:34px; height:34px; min-height:34px;}
    .icon-row{gap:8px;}
    .legend{font-size:0.56rem; gap:8px;}
    .table{gap:6px;}
  }
  @media (hover:none) and (pointer:coarse){
    .cell.movable, .tray.movable{ -webkit-tap-highlight-color: transparent; }
  }
  @media (prefers-reduced-motion: reduce){
    *{animation:none !important; transition:none !important;}
  }

  /* ================================================================
     EAGLE BOARD — overrides the 3-column grid with the Jiroft eagle.
     Wings = each player's 4-cup rail, body = 12-cup shared path.
     ================================================================ */
  :root{
    --eagle-w: min(clamp(200px, 52vw, 300px), calc((100vh - 170px) * 0.468));
  }
  .board-wrap{
    width:max(calc(var(--eagle-w) + 2 * var(--board-pad)), var(--board-min-w));
  }
  .board.eagle-board{
    display:block;
    position:relative;
    width:var(--eagle-w);
    aspect-ratio:479 / 1024;
    height:auto;
  }
  .eagle-board .eagle-svg{
    position:absolute;
    inset:0;
    width:100%;
    height:100%;
    pointer-events:none;
  }
  .eagle-board .cell{
    position:absolute;
    background:transparent;
    border:none;
    box-shadow:none;
  }
  .eagle-board .cell.safe{background:transparent; border:2.5px solid var(--safe-color); box-sizing:border-box;}
  .eagle-board .cell.safe .cross{opacity:0.9;}
  .eagle-board .cell.safe .cross::before,
  .eagle-board .cell.safe .cross::after{background:#8fd0ff;}
  .eagle-board .cell.start{box-shadow:0 0 0 2px rgba(239,230,207,0.75);}
  .eagle-board .cell .piece{
    width:80%;
    height:80%;
    position:relative;
    z-index:1;
  }
  .eagle-board .cell.movable{
    box-shadow:0 0 0 3px var(--highlight-blue), 0 0 18px 4px rgba(47,143,216,0.75);
  }
  .board.eagle-board.guide-active .cell[data-col="0"]{box-shadow:0 0 0 3px rgba(47,143,216,0.9);}
  .board.eagle-board.guide-active .cell[data-col="2"]{box-shadow:0 0 0 3px rgba(211,64,140,0.9);}
  .board.eagle-board.guide-active .cell[data-col="1"]{box-shadow:0 0 0 3px rgba(217,164,65,0.95);}
  .eagle-board .guide-arrow{color:#bfe6ff; text-shadow:0 1px 3px rgba(0,0,0,0.8);}
  .eagle-board .guide-arrow.exit{color:#ff8a7a;}
  .eagle-board .guide-tag{bottom:auto; top:100%; margin-top:1px;}

  @media (max-height:520px) and (orientation:landscape){
    :root{ --eagle-w: min(200px, calc((100vh - 24px) * 0.48)); }
  }

  /* ---------- difficulty picker ---------- */
  .mode-overlay{
    position:fixed;inset:0;
    background:rgba(10,18,14,0.86);
    display:none;
    align-items:center;justify-content:center;
    flex-direction:column;
    gap:18px;
    z-index:60;
    text-align:center;
    padding:20px;
  }
  .mode-overlay.show{display:flex;}
  .mode-overlay h2{
    font-family:var(--font-display);
    font-size:clamp(1.8rem,7vw,2.6rem);
    color:var(--gold);
    margin:0;
    text-transform:uppercase;
    letter-spacing:0.04em;
  }
  .mode-buttons{display:flex; gap:14px; flex-wrap:wrap; justify-content:center;}
  .mode-buttons button{min-width:130px;}
  .mode-buttons button[data-mode="hard"]{background:var(--danger); color:#fff; box-shadow:0 3px 0 #6e241c;}


  /* ================================================================
     ANCIENT THEME — board resting on bare soil and dust,
     pieces lying scattered on the ground beside it
     ================================================================ */
  body.theme-ancient{
    background:
      radial-gradient(900px 500px at 50% 30%, rgba(255,236,190,0.16), transparent 70%),
      radial-gradient(1200px 800px at 50% 120%, rgba(20,12,4,0.5), transparent 60%),
      url("../img/soil.svg");
    background-size:auto, auto, 320px 320px;
    color:#f3e6cc;
  }
  body.theme-ancient .board-wrap{background:transparent; border:none; box-shadow:none;}
  body.theme-ancient .eagle-svg{filter:drop-shadow(0 14px 14px rgba(20,12,4,0.65));}
  body.theme-ancient .legend{color:#f3e6cc; text-shadow:0 1px 2px rgba(0,0,0,0.8);}
  body.theme-ancient .icon-btn{
    background:rgba(40,28,14,0.72);
    color:#f3e6cc;
    border:1px solid rgba(243,230,204,0.35);
    box-shadow:0 3px 8px rgba(10,5,0,0.5);
  }
  body.theme-ancient .icon-btn:hover:not(:disabled){color:#fff; border-color:#f3e6cc;}
  body.theme-ancient .icon-btn.active{background:var(--highlight-blue); color:#fff; border-color:var(--highlight-blue);}
  body.theme-ancient .die-face{filter:drop-shadow(0 5px 6px rgba(10,5,0,0.6));}
  body.theme-ancient .turn-flash{background:rgba(40,28,14,0.9); color:#f3e6cc;}

  /* side panels: no box, just labels and pieces on the ground */
  body.theme-ancient .panel{background:transparent; border:none; box-shadow:none;}
  body.theme-ancient .panel-name{color:#fff6e4; text-shadow:0 1px 3px rgba(0,0,0,0.9);}
  body.theme-ancient .section-label{color:#f3e6cc; text-shadow:0 1px 2px rgba(0,0,0,0.9);}
  body.theme-ancient .tray,
  body.theme-ancient .finished-row{
    position:relative;
    display:block;
    width:100%;
    height:clamp(96px,26vw,128px);
    padding:0;
    background:transparent;
    box-shadow:none;
    border-radius:16px;
  }
  body.theme-ancient .tray .piece,
  body.theme-ancient .finished-row .slot.filled{
    position:absolute;
    width:clamp(18px,5vw,24px); height:clamp(18px,5vw,24px);
    left:calc(var(--sx) * 100% - clamp(9px,2.5vw,12px));
    top:calc(var(--sy) * 100% - clamp(9px,2.5vw,12px));
    transform:rotate(var(--rot));
    border-radius:50%;
  }
  /* grounded pieces: a soft contact shadow on the soil */
  body.theme-ancient .tray .piece.white,
  body.theme-ancient .finished-row .slot.filled.white{
    background:radial-gradient(circle at 32% 28%, #ffffff, var(--white-piece) 60%);
    box-shadow:inset 0 0 0 2px var(--white-ring), 2px 4px 5px rgba(10,5,0,0.7);
  }
  body.theme-ancient .tray .piece.black,
  body.theme-ancient .finished-row .slot.filled.black{
    background:radial-gradient(circle at 32% 28%, #3a362c, var(--black-piece) 65%);
    box-shadow:inset 0 0 0 2px var(--black-ring), 2px 4px 5px rgba(10,5,0,0.7);
  }
  body.theme-ancient .finished-row .slot:not(.filled){display:none;}
  body.theme-ancient .tray.movable{
    box-shadow:0 0 0 3px var(--highlight-blue), 0 0 16px 3px rgba(47,143,216,0.7);
    background:rgba(47,143,216,0.12);
  }

  /* ancient theme: finished pieces are not shown */
  body.theme-ancient .finished-row,
  body.theme-ancient .finished-label{display:none;}

  /* AI label turns red in Hard mode */
  .panel-name.hard{color:#d9382b;}
  body.theme-ancient .panel-name.hard{color:#ff5e4d; text-shadow:0 1px 3px rgba(0,0,0,0.95);}

  /* ================================================================
     MOBILE + CROSS-BROWSER LAYOUT
     Phones/tablets in portrait: both player panels side by side on top,
     board and controls below - nothing wraps under the buttons.
     ================================================================ */
  @supports (height:100dvh){
    :root{ --eagle-w: min(clamp(200px, 52vw, 300px), calc((100dvh - 170px) * 0.468)); }
  }
  /* Safari < 15 has no aspect-ratio: size the board explicitly */
  @supports not (aspect-ratio: 1 / 1){
    .board.eagle-board{ height:calc(var(--eagle-w) * 1024 / 479); }
  }
  .board-wrap, .panel, .table{ -webkit-box-sizing:border-box; box-sizing:border-box; }
  .die-frame, .icon-btn, .cell, .tray{ -webkit-user-select:none; user-select:none; }

  @media (max-width:700px) and (orientation:portrait), (max-width:520px){
    .table{
      display:grid;
      grid-template-columns:1fr 1fr;
      grid-template-areas:
        "p1 p2"
        "board board";
      gap:8px;
      width:100%;
      max-width:520px;
    }
    #panel-1{ grid-area:p1; }
    #panel-2{ grid-area:p2; }
    .board-wrap{ grid-area:board; justify-self:center; width:auto; max-width:100%; }
    .panel{
      width:auto; max-width:none; flex:none;
      padding:8px 8px 10px;
    }
    .panel-head{ margin-bottom:4px; }
    .panel-name{ font-size:1rem; }
    .section-label{ font-size:0.56rem; margin:4px 0 3px; }
    .tray{ justify-content:flex-start; gap:4px; padding:4px; min-height:30px; }
    .tray .piece{ width:20px; height:20px; }
    .finished-row{ justify-content:flex-start; gap:3px; }
    .slot{ width:13px; height:13px; }
    /* board as large as the screen width allows; page may scroll a little */
    :root{ --eagle-w: min(74vw, 300px, calc((100vh - 300px) * 0.468)); }
    @supports (height:100dvh){ :root{ --eagle-w: min(74vw, 300px, calc((100dvh - 300px) * 0.468)); } }
    body.theme-ancient{ --eagle-w: min(74vw, 300px, calc((100vh - 316px) * 0.468)); }
    .board-wrap{ padding:6px; gap:6px; }
    .controls{ gap:6px; }
    .die-frame{ width:48px; height:48px; }
    .icon-btn{ width:40px; height:40px; min-height:40px; }
    body.theme-ancient .tray{ height:104px; }
    body.theme-ancient .tray .piece{ width:20px; height:20px; left:calc(var(--sx) * 100% - 10px); top:calc(var(--sy) * 100% - 10px); }
  }
  /* phone held sideways: panels left/right, board sized by height */
  @media (max-height:520px) and (orientation:landscape){
    .table{ display:flex; flex-wrap:nowrap; align-items:flex-start; justify-content:center; gap:8px; }
    .panel{ width:clamp(110px,22vw,160px); flex:0 0 clamp(110px,22vw,160px); padding:6px; }
    .board-wrap{ flex:0 0 auto; }
    :root{ --eagle-w: min(260px, calc((100vh - 16px) * 0.468)); }
    @supports (height:100dvh){ :root{ --eagle-w: min(260px, calc((100dvh - 16px) * 0.468)); } }
    .board-wrap{ flex-direction:row; align-items:center; gap:10px; width:auto; }
    .controls{ width:auto; }
    .icon-row{ flex-direction:column; }
    body.theme-ancient .tray{ height:96px; }
  }

  /* Ancient theme: die rests on a pale flat stone so it reads against the dark soil */
  body.theme-ancient .die-frame{
    width:clamp(64px,17vw,84px);
    height:clamp(64px,17vw,84px);
    border-radius:42% 48% 44% 50% / 46% 42% 50% 44%;
    background:
      radial-gradient(circle at 34% 30%, rgba(255,255,255,0.55), transparent 45%),
      radial-gradient(ellipse at 50% 55%, #efe4cc 0%, #dccdae 55%, #bfae8c 100%);
    box-shadow:
      inset -3px -4px 8px rgba(90,70,40,0.35),
      inset 2px 2px 4px rgba(255,255,255,0.6),
      0 6px 10px rgba(10,5,0,0.65);
    overflow:visible;
    contain:none;
  }
  body.theme-ancient .die-face{
    width:82%; height:82%;
    filter:drop-shadow(0 3px 3px rgba(40,25,10,0.55)) brightness(1.12) contrast(1.08);
  }
  body.theme-ancient .die-frame.ready{
    box-shadow:
      inset -3px -4px 8px rgba(90,70,40,0.35),
      inset 2px 2px 4px rgba(255,255,255,0.6),
      0 6px 10px rgba(10,5,0,0.65),
      0 0 0 3px rgba(255,236,190,0.75),
      0 0 22px 6px rgba(255,226,160,0.55);
  }
  @media (max-width:700px) and (orientation:portrait), (max-width:520px){
    body.theme-ancient .die-frame{ width:56px; height:56px; }
  }
  @media (max-height:520px) and (orientation:landscape){
    body.theme-ancient .die-frame{ width:50px; height:50px; }
  }

  /* ---------- ambient weather (Ancient theme only) ---------- */
  .weather{ position:fixed; inset:0; pointer-events:none; overflow:hidden; z-index:40; }
  body:not(.theme-ancient) .weather{ display:none; }
  .mist{
    position:absolute; left:50%;
    width:var(--w); height:var(--h);
    margin-left:calc(var(--w) / -2);
    border-radius:50%;
    background:
      radial-gradient(ellipse at 35% 50%, rgba(245,238,224,0.85) 0%, rgba(245,238,224,0) 60%),
      radial-gradient(ellipse at 65% 45%, rgba(235,228,214,0.8) 0%, rgba(235,228,214,0) 55%),
      radial-gradient(ellipse at 50% 60%, rgba(255,250,240,0.6) 0%, rgba(255,250,240,0) 65%);
    filter:blur(18px);
    opacity:0;
    animation:mistDrift 12s ease-in-out forwards;
  }
  @keyframes mistDrift{
    0%  { transform:translateX(var(--from)) scale(0.9); opacity:0; }
    25% { opacity:var(--o); }
    75% { opacity:var(--o); }
    100%{ transform:translateX(var(--to)) scale(1.15); opacity:0; }
  }
  .gust{ position:absolute; inset:0; }
  .gust span{
    position:absolute; left:0; height:2px;
    border-radius:2px;
    background:linear-gradient(90deg, rgba(240,226,196,0), rgba(240,226,196,0.75), rgba(240,226,196,0));
    box-shadow:0 0 6px rgba(240,226,196,0.4);
    opacity:0;
    animation:gustLTR 1.2s ease-in forwards;
  }
  .gust.rtl span{ animation-name:gustRTL; }
  @keyframes gustLTR{
    0%{ transform:translateX(-30vw); opacity:0; } 20%{ opacity:1; } 100%{ transform:translateX(110vw); opacity:0; }
  }
  @keyframes gustRTL{
    0%{ transform:translateX(110vw); opacity:0; } 20%{ opacity:1; } 100%{ transform:translateX(-30vw); opacity:0; }
  }
  /* pieces slide and turn as the wind pushes them */
  body.theme-ancient .tray .piece.blown,
  body.theme-ancient .finished-row .slot.blown{
    transition:left 1.3s cubic-bezier(.2,.7,.3,1), top 1.3s cubic-bezier(.2,.7,.3,1), transform 1.3s cubic-bezier(.2,.7,.3,1);
  }
  @media (prefers-reduced-motion: reduce){ .weather{ display:none; } }

  /* ---------- earth tremor + board sway (Ancient theme only) ---------- */
  body.theme-ancient.quake{ animation:groundShake 1.5s ease-out; }
  @keyframes groundShake{
    0%{ background-position:0 0, 0 0, 0 0; }
    10%{ background-position:0 0, 0 0, -6px 3px; }
    20%{ background-position:0 0, 0 0, 5px -4px; }
    30%{ background-position:0 0, 0 0, -5px -2px; }
    40%{ background-position:0 0, 0 0, 4px 4px; }
    55%{ background-position:0 0, 0 0, -3px 1px; }
    70%{ background-position:0 0, 0 0, 2px -2px; }
    85%{ background-position:0 0, 0 0, -1px 1px; }
    100%{ background-position:0 0, 0 0, 0 0; }
  }
  body.theme-ancient.quake .table{ animation:sceneShake 1.5s ease-out; }
  @keyframes sceneShake{
    0%,100%{ transform:translate(0,0); }
    10%{ transform:translate(-5px,2px); } 20%{ transform:translate(5px,-3px); }
    30%{ transform:translate(-4px,-1px); } 40%{ transform:translate(4px,3px); }
    55%{ transform:translate(-2px,1px); } 70%{ transform:translate(2px,-1px); } 85%{ transform:translate(-1px,0); }
  }
  /* the board slides and tilts on the shaking ground, then settles back */
  body.theme-ancient.quake .board-wrap{ -webkit-animation:boardShiftNow 1.7s cubic-bezier(.3,.6,.3,1); animation:boardShiftNow 1.7s cubic-bezier(.3,.6,.3,1); will-change:transform; }
  @keyframes boardShift{
    0%{ transform:translate(0,0) rotate(0); }
    15%{ transform:translate(var(--qx), 3px) rotate(var(--qr)); }
    30%{ transform:translate(calc(var(--qx) * -0.6), -2px) rotate(calc(var(--qr) * -0.7)); }
    45%{ transform:translate(calc(var(--qx) * 0.5), 2px) rotate(calc(var(--qr) * 0.5)); }
    65%{ transform:translate(calc(var(--qx) * -0.25), -1px) rotate(calc(var(--qr) * -0.25)); }
    100%{ transform:translate(0,0) rotate(0); }
  }
  /* gentle sway when a gust passes */
  body.theme-ancient .board-wrap.sway{ animation:boardSway 2.1s ease-in-out; transform-origin:50% 90%; }
  @keyframes boardSway{
    0%,100%{ transform:rotate(0); }
    30%{ transform:rotate(var(--sway)); }
    60%{ transform:rotate(calc(var(--sway) * -0.4)); }
  }
  @media (prefers-reduced-motion: reduce){
    body.theme-ancient.quake, body.theme-ancient.quake .table, body.theme-ancient.quake .board-wrap,
    body.theme-ancient .board-wrap.sway{ animation:none; }
  }

  /* eagle blinks during a tremor (lid hidden the rest of the time) */
  .eagle-svg .eyelid{ transform:scaleY(0); }   /* lid group's origin is the top of the eye */
  /* the eagle also blinks now and then on its own during play (a quick natural blink) */
  body.theme-ancient.eagle-blink .eagle-svg .eyelid{ animation:eagleBlinkQuick .42s ease-in-out; }
  @keyframes eagleBlinkQuick{
    0%      { transform:scaleY(0); }
    40%,55% { transform:scaleY(1); }
    100%    { transform:scaleY(0); }
  }
  /* earth tremor: three blinks in a row */
  body.theme-ancient.quake .eagle-svg .eyelid{ animation:eagleBlinkTriple 1.5s ease-in-out; }
  @keyframes eagleBlinkTriple{
    0%,6%   { transform:scaleY(0); }
    13%     { transform:scaleY(1); }
    21%     { transform:scaleY(0.05); }
    29%     { transform:scaleY(1); }
    37%     { transform:scaleY(0.05); }
    45%     { transform:scaleY(1); }
    55%,100%{ transform:scaleY(0); }
  }
  @keyframes eagleBlink{
    0%,8%   { transform:scaleY(0); }
    18%     { transform:scaleY(1); }
    30%     { transform:scaleY(0.05); }
    44%     { transform:scaleY(1); }
    56%,100%{ transform:scaleY(0); }
  }
  @media (prefers-reduced-motion: reduce){ body.theme-ancient.quake .eagle-svg .eyelid, body.theme-ancient.eagle-blink .eagle-svg .eyelid{ animation:none; } }

  /* ================================================================
     ANCIENT ENDINGS
     lose: earthquake, cracks, board shatters -> "You are cursed"
     win : wind and tremors stop, board left alone -> "You destroyed the curse"
     ================================================================ */
  .ending{
    position:fixed; inset:0; z-index:55;
    display:none; flex-direction:column; align-items:center; justify-content:center; gap:22px;
    pointer-events:none; text-align:center; padding:20px;
  }
  .ending.show{ display:flex; }
  .ending h2{
    margin:0;
    font-family:Georgia, "Times New Roman", serif;
    font-size:clamp(2.4rem, 10vw, 5rem);
    letter-spacing:0.08em;
    text-transform:uppercase;
    opacity:0;
    animation:endingIn 1.6s ease-out forwards;
  }
  .ending button{ pointer-events:auto; opacity:0; animation:endingIn 1s ease-out 1.2s forwards; }
  .ending.cursed h2{
    color:#b3261b;
    text-shadow:0 0 18px rgba(0,0,0,0.9), 0 0 40px rgba(120,0,0,0.65), 0 2px 0 #2a0503;
  }
  .ending.cursed button{ background:#5a120c; color:#f3e6cc; box-shadow:0 3px 0 #2a0503; }
  .ending.victory{ justify-content:flex-end; padding-bottom:7vh; }
  .ending.victory h2{
    font-size:clamp(1.6rem, 6vw, 3rem);
    color:#ffe7a8;
    text-shadow:0 0 14px rgba(0,0,0,0.85), 0 0 30px rgba(255,214,120,0.55);
  }
  @keyframes endingIn{ from{ opacity:0; transform:scale(0.92); letter-spacing:0.3em; } to{ opacity:1; transform:scale(1); } }

  /* everything except the board fades away at the end */
  body.ending-mode .panel,
  body.ending-mode .controls{ transition:opacity 1s ease; opacity:0; pointer-events:none; }
  body.ending-mode .cell{ pointer-events:none; }

  /* massive earthquake */
  body.theme-ancient.doom{ animation:groundShakeBig 0.5s linear 6; }
  body.theme-ancient.doom .table{ animation:sceneShakeBig 0.25s linear 12; }
  @keyframes groundShakeBig{
    0%,100%{ background-position:0 0, 0 0, 0 0; }
    25%{ background-position:0 0, 0 0, -14px 8px; }
    50%{ background-position:0 0, 0 0, 12px -10px; }
    75%{ background-position:0 0, 0 0, -9px -6px; }
  }
  @keyframes sceneShakeBig{
    0%,100%{ transform:translate(0,0) rotate(0); }
    25%{ transform:translate(-12px,6px) rotate(-0.8deg); }
    50%{ transform:translate(11px,-7px) rotate(0.7deg); }
    75%{ transform:translate(-8px,-4px) rotate(-0.5deg); }
  }
  body.doom .eagle-svg .eyelid{ animation:eagleBlink 0.6s ease-in-out 4; }

  /* cracks */
  .eagle-svg .crack{ fill:none; stroke-linecap:round; stroke-linejoin:round; transition:stroke-dashoffset 1.6s cubic-bezier(.3,.7,.4,1); }
  .eagle-svg .crack.shadow{ stroke:rgba(0,0,0,0.55); }
  .eagle-svg .crack.line{ stroke:#0b0b0a; }
  .eagle-svg .crack.edge{ stroke:#a7aa9f; opacity:0.7; transform:translate(0.8px,0.8px); }
  .eagle-svg .cracks.grow .crack{ stroke-dashoffset:0 !important; }

  /* shattering */
  .board.eagle-board.broken > .eagle-svg,
  .board.eagle-board.broken > .cell{ visibility:hidden; }
  .shards{ position:absolute; inset:0; pointer-events:none; }
  .shard{ position:absolute; inset:0; animation:shardFall 1.9s cubic-bezier(.5,0,.8,.6) forwards; }
  .shard img{ width:100%; height:100%; display:block; }
  @keyframes shardFall{
    0%  { transform:translate(0,0) rotate(0); opacity:1; }
    15% { transform:translate(calc(var(--dx) * 0.15), -6px) rotate(calc(var(--dr) * 0.1)); opacity:1; }
    100%{ transform:translate(var(--dx), var(--dy)) rotate(var(--dr)); opacity:0; }
  }

  /* victory: calm, warm light around the board */
  body.theme-ancient.lifted .board-wrap{ animation:none; }
  body.theme-ancient.lifted .eagle-svg{
    transition:filter 2s ease;
    filter:drop-shadow(0 14px 14px rgba(20,12,4,0.65)) drop-shadow(0 0 26px rgba(255,214,130,0.45));
  }
  @media (prefers-reduced-motion: reduce){
    body.theme-ancient.doom, body.theme-ancient.doom .table, .shard{ animation:none; }
    .shard{ opacity:0; }
  }

  /* ---------- X spaces: yellow cups with a bold, clear cross ---------- */
  .eagle-board .cell.safe{
    background:radial-gradient(circle at 40% 34%, #fff2a8 0%, #ffd94a 45%, #e7b21c 85%, #b98a12 100%);
    border:2.5px solid #ffe066;
    box-sizing:border-box;
    box-shadow:inset 0 2px 4px rgba(120,80,0,0.45), 0 0 8px rgba(255,214,70,0.55);
  }
  .eagle-board .cell.safe .cross{ width:74%; height:74%; opacity:1; }
  .eagle-board .cell.safe .cross::before,
  .eagle-board .cell.safe .cross::after{
    background:#3d2600;
    width:20%;
    border-radius:3px;
    box-shadow:0 0 0 1px rgba(255,240,180,0.6);
  }
  .eagle-board .cell.safe .piece{ z-index:2; }
  .eagle-board .cell.safe.movable{
    box-shadow:0 0 0 3px var(--highlight-blue), 0 0 18px 4px rgba(47,143,216,0.75), inset 0 2px 4px rgba(120,80,0,0.45);
  }
  .legend .dot.safe{ background:#ffd94a; box-shadow:inset 0 0 0 1px #b98a12; }

  /* ---------- beak: lower jaw swings open on its hinge during tremors ---------- */
  /* hinge is set in the SVG (the jaw group sits at the corner of the mouth), so the default origin is correct everywhere */
  .eagle-svg .jaw{ transform:rotate(0deg); }
  .eagle-svg .mouth{ opacity:0; }
  body.eagle-call .eagle-svg .mouth{ opacity:1; }
  body.eagle-call .eagle-svg .jaw{ animation:beakCall 1.05s ease-in-out; }
  @keyframes beakCall{
    0%,5%   { transform:rotate(0deg); }
    18%     { transform:rotate(17deg); }
    58%     { transform:rotate(15deg); }
    82%,100%{ transform:rotate(0deg); }
  }
  @keyframes beakCry{
    0%,6%   { transform:rotate(0deg); }
    14%     { transform:rotate(17deg); }
    34%     { transform:rotate(15deg); }
    42%     { transform:rotate(1deg); }
    50%     { transform:rotate(16deg); }
    72%     { transform:rotate(14deg); }
    82%,100%{ transform:rotate(0deg); }
  }
  @media (prefers-reduced-motion: reduce){ body.eagle-call .eagle-svg .jaw{ animation:none; } }

  /* ---------- the eagle turns its head (3D head model drawn by script) ---------- */
  body.eagle-dark .board-wrap .eagle-svg{ filter:drop-shadow(0 0 22px rgba(255,60,40,0.35)); }

  /* ================================================================
     COMPATIBILITY: older Safari/iOS, Firefox, Android browsers, notched phones
     ================================================================ */
  html{ -webkit-text-size-adjust:100%; text-size-adjust:100%; }
  body{
    -webkit-tap-highlight-color:transparent;
    touch-action:manipulation;                 /* no double-tap zoom on game taps */
    overscroll-behavior:none;                  /* no pull-to-refresh mid-game */
    padding-left:max(10px, env(safe-area-inset-left));
    padding-right:max(10px, env(safe-area-inset-right));
    padding-bottom:max(20px, env(safe-area-inset-bottom));
  }
  /* "inset" is missing in Safari < 14.1: spell the edges out */
  .weather, .ending, .mode-overlay, .win-overlay, .shards, .shard, .gust, .eagle-board .eagle-svg{ top:0; right:0; bottom:0; left:0; }
  .cell, .tray, .die-frame, .icon-btn, .ending button, .mode-buttons button{ -webkit-user-select:none; user-select:none; -webkit-touch-callout:none; }
  /* keep the shaking/swaying board on its own GPU layer so phones don't redraw the stone every frame */
  .board-wrap, .eagle-board .eagle-svg{ will-change:transform; -webkit-backface-visibility:hidden; backface-visibility:hidden; }
  .mist{ will-change:transform, opacity; }
  @media (max-width:700px){
    .mist{ filter:blur(11px); }
  }
  /* browsers without min()/clamp(): fixed, safe board sizes */
  @supports not (width: min(1px, 2px)){
    :root, body.theme-ancient{ --eagle-w:260px !important; }
    @media (max-width:520px){ :root, body.theme-ancient{ --eagle-w:62vw !important; } }
  }

  /* ================================================================
     PHONES (portrait): panels as narrow columns beside the board so the
     board gets most of the screen height. Overrides the earlier stacked layout.
     ================================================================ */
  @media (max-width:700px) and (orientation:portrait), (max-width:520px) and (orientation:portrait){
    .table{
      grid-template-columns:var(--side-w) minmax(0,1fr) var(--side-w);
      grid-template-areas:"p1 board p2";
      align-items:start;
      gap:6px;
    }
    :root{
      --side-w:clamp(56px, 16.5vw, 74px);
      --eagle-w:min(calc(100vw - 2 * var(--side-w) - 44px), calc((100vh - 150px) * 0.468), 300px);
    }
    @supports (height:100dvh){
      :root{ --eagle-w:min(calc(100vw - 2 * var(--side-w) - 44px), calc((100dvh - 150px) * 0.468), 300px); }
    }
    body.theme-ancient{ --eagle-w:min(calc(100vw - 2 * var(--side-w) - 44px), calc((100vh - 150px) * 0.468), 300px); }
    @supports (height:100dvh){
      body.theme-ancient{ --eagle-w:min(calc(100vw - 2 * var(--side-w) - 44px), calc((100dvh - 150px) * 0.468), 300px); }
    }
    .panel{ padding:6px 4px 8px; }
    .panel-name{ font-size:0.9rem; }
    .tray{ justify-content:center; }
    .tray .piece{ width:19px; height:19px; }
    .finished-row{ justify-content:center; }
    .slot{ width:12px; height:12px; }
    /* ancient: pieces scatter down a tall, narrow patch (2 columns x 6 rows) */
    body.theme-ancient .tray{ height:calc(var(--eagle-w) * 1024 / 479 * 0.55); }
    body.theme-ancient .tray .piece{ width:19px; height:19px; left:calc(var(--sx) * 100% - 9.5px); top:calc(var(--sy) * 100% - 9.5px); }
  }

  /* Live theme on desktop/tablet: leave room for the larger die stone */
  @media (min-width:701px) and (min-height:521px){
    body.theme-ancient{ --eagle-w:min(clamp(200px, 52vw, 300px), calc((100vh - 205px) * 0.468)); }
    @supports (height:100dvh){ body.theme-ancient{ --eagle-w:min(clamp(200px, 52vw, 300px), calc((100dvh - 205px) * 0.468)); } }
  }
  /* phone held sideways: taller ground patch so 10 pieces never touch */
  @media (max-height:520px) and (orientation:landscape){
    body.theme-ancient .tray{ height:132px; }
    body.theme-ancient .tray .piece{ width:20px; height:20px; left:calc(var(--sx) * 100% - 10px); top:calc(var(--sy) * 100% - 10px); }
  }
  /* small screens: each cup gets a slightly larger invisible tap area */
  @media (max-width:700px), (max-height:520px){
    .eagle-board .cell::after{ content:''; position:absolute; top:-3px; right:-3px; bottom:-3px; left:-3px; border-radius:50%; }
  }

  /* while the eagle faces the players, everything behind the board fades to black */
  body::before{
    content:''; position:fixed; top:0; right:0; bottom:0; left:0;
    background:#000; opacity:0; pointer-events:none; z-index:0;
    transition:opacity 1.1s ease;
  }
  body.eagle-dark::before{ opacity:1; }
  .table{ position:relative; z-index:1; }
  .weather{ transition:opacity 1.1s ease; }
  body.eagle-dark .weather{ opacity:0; }

  /* final head turn (all pieces off): background fades to white instead of black */
  body.eagle-white::before{ background:#fff; }
  body.eagle-white.eagle-dark .board-wrap .eagle-svg{ filter:drop-shadow(0 0 22px rgba(0,0,0,0.25)); }
  /* the carved eye blinks while the eagle cries on an X space */
  body.eagle-call .eagle-svg .eyelid{ animation:eagleBlinkOnce 1.05s ease-in-out; }
  @keyframes eagleBlinkOnce{
    0%,6%   { transform:scaleY(0); }
    16%,30% { transform:scaleY(1); }
    42%,100%{ transform:scaleY(0); }
  }
  body.eagle-white .panel-name, body.eagle-white .section-label{ color:#2a2619 !important; text-shadow:none !important; transition:color .6s ease; }

  /* ---------- info note ---------- */
  .info-modal{
    position:fixed; top:0; right:0; bottom:0; left:0; z-index:70;
    display:flex; align-items:center; justify-content:center; padding:20px;
    background:rgba(10,8,5,0.72);
  }
  .info-modal[hidden]{ display:none; }
  .info-card{
    position:relative; max-width:420px; width:100%;
    background:#fbf6ea; color:#2a2619;
    border-radius:14px; padding:26px 24px 20px;
    box-shadow:0 18px 40px rgba(0,0,0,0.5);
    font-family:var(--font-body); line-height:1.5; text-align:left;
    animation:infoIn .22s ease-out;
  }
  @keyframes infoIn{ from{ opacity:0; transform:translateY(8px) scale(.97); } to{ opacity:1; transform:none; } }
  .info-card h2{ margin:0 0 12px; font-family:Georgia, "Times New Roman", serif; font-size:1.35rem; color:#5a3a12; }
  .info-card p{ margin:0 0 12px; font-size:0.98rem; }
  .info-close{
    position:absolute; top:8px; right:8px; width:36px; height:36px; min-height:36px; padding:0;
    border-radius:50%; background:transparent; box-shadow:none; color:#786f5a; font-size:1.6rem; line-height:1;
  }
  .info-close:hover{ color:#2a2619; }
  .info-ok{ display:block; margin:6px 0 0 auto; padding:10px 26px; min-height:42px; }
  body.theme-ancient .info-card{ background:#efe4cc; }
  /* five round buttons always on one line on phones (may extend a little past the board's width) */
  @media (max-width:700px), (max-height:520px){
    .board-wrap, .controls{ overflow:visible; }
    .icon-row{ flex-wrap:nowrap; gap:6px; white-space:nowrap; }
    .icon-btn{ width:36px; height:36px; min-height:36px; flex:0 0 auto; }
    .icon-btn svg{ width:18px; height:18px; }
  }
  @media (max-height:520px) and (orientation:landscape){
    .icon-row{ flex-direction:column; }
  }
  /* all sizes: the button row never wraps; it may extend past the board's width */
  .board-wrap, .controls{ overflow:visible; }
  .icon-row{ flex-wrap:nowrap; white-space:nowrap; }
  .icon-btn{ flex:0 0 auto; }

  /* ================================================================
     LARGER DIE (all sizes) — board leaves a little more room for it
     ================================================================ */
  .die-frame{ width:clamp(70px, 18vw, 92px); height:clamp(70px, 18vw, 92px); }
  body.theme-ancient .die-frame{ width:clamp(80px, 21vw, 112px); height:clamp(80px, 21vw, 112px); }
  body.theme-ancient .die-face{ width:86%; height:86%; }
  :root{ --eagle-w:min(clamp(200px, 52vw, 300px), calc((100vh - 195px) * 0.468)); }
  @supports (height:100dvh){ :root{ --eagle-w:min(clamp(200px, 52vw, 300px), calc((100dvh - 195px) * 0.468)); } }
  @media (min-width:701px) and (min-height:521px){
    body.theme-ancient{ --eagle-w:min(clamp(200px, 52vw, 300px), calc((100vh - 235px) * 0.468)); }
    @supports (height:100dvh){ body.theme-ancient{ --eagle-w:min(clamp(200px, 52vw, 300px), calc((100dvh - 235px) * 0.468)); } }
  }
  /* phones held upright */
  @media (max-width:700px) and (orientation:portrait), (max-width:520px) and (orientation:portrait){
    .die-frame, body.theme-ancient .die-frame{ width:68px; height:68px; }
    :root, body.theme-ancient{ --eagle-w:min(calc(100vw - 2 * var(--side-w) - 44px), calc((100vh - 172px) * 0.468), 300px); }
    @supports (height:100dvh){
      :root, body.theme-ancient{ --eagle-w:min(calc(100vw - 2 * var(--side-w) - 44px), calc((100dvh - 172px) * 0.468), 300px); }
    }
  }
  /* phones held sideways: die sits beside the board, so it can be big without costing height */
  @media (max-height:520px) and (orientation:landscape){
    .die-frame, body.theme-ancient .die-frame{ width:66px; height:66px; }
  }
  /* phones held sideways: the board is sized by height alone (die and buttons sit beside it) */
  @media (max-height:520px) and (orientation:landscape){
    :root, body.theme-ancient{ --eagle-w:min(260px, calc((100vh - 16px) * 0.468)); }
    @supports (height:100dvh){ :root, body.theme-ancient{ --eagle-w:min(260px, calc((100dvh - 16px) * 0.468)); } }
  }

  /* ================================================================
     PHONES HELD UPRIGHT — BIG BOARD
     The board takes nearly the full screen height. Everything else sits in
     the empty corners around the eagle: pieces beside the head (top corners),
     die and buttons beside the tail (bottom corners).
     ================================================================ */
  @media (max-width:700px) and (orientation:portrait){
    :root, body.theme-ancient{
      --eagle-w:min(calc(100vw - 16px), calc((100vh - 44px) * 0.468), 420px);
      --side:calc((100vw - var(--eagle-w)) / 2);          /* empty margin each side of the board */
    }
    @supports (height:100dvh){
      :root, body.theme-ancient{ --eagle-w:min(calc(100vw - 16px), calc((100dvh - 44px) * 0.468), 420px); }
    }
    body{ padding-left:0; padding-right:0; padding-top:max(8px, env(safe-area-inset-top)); }
    .table{
      display:block; position:relative;
      width:var(--eagle-w); max-width:none; margin:0 auto;
    }
    .board-wrap{
      position:relative; width:var(--eagle-w); padding:0; margin:0;
      background:transparent; border:none; box-shadow:none;
    }
    /* --- waiting pieces beside the head --- */
    .panel{
      position:absolute; top:0; z-index:3;
      background:transparent; border:none; box-shadow:none; padding:0 2px;
      max-width:none; flex:none;
      height:calc(var(--eagle-w) * 1024 / 479 * 0.135);
      overflow:visible;
    }
    #panel-1{ left:calc(6px - var(--side)); width:calc(var(--side) + var(--eagle-w) * 0.39 - 8px); }
    #panel-2{ right:calc(6px - var(--side)); width:calc(var(--side) + var(--eagle-w) * 0.215 - 6px); }
    .panel-head{ justify-content:flex-start; margin:0 0 2px; }
    #panel-2 .panel-head{ justify-content:flex-end; }
    .panel-name{ font-size:0.82rem; letter-spacing:0.04em; }
    .tray{ padding:0; min-height:0; gap:3px; background:transparent; box-shadow:none; justify-content:flex-start; }
    #panel-2 .tray{ justify-content:flex-end; }
    .tray .piece{ width:18px; height:18px; }
    .tray.movable{ border-radius:10px; }
    .finished-label{ display:none; }
    .finished-row{ gap:2px; margin-top:3px; justify-content:flex-start; }
    #panel-2 .finished-row{ justify-content:flex-end; }
    .slot{ width:8px; height:8px; }
    body.theme-ancient .tray{ height:46px; }
    body.theme-ancient .tray .piece{ width:18px; height:18px; left:calc(var(--sx) * 100% - 9px); top:calc(var(--sy) * 100% - 9px); }
    /* --- die (left) and buttons (right) beside the tail --- */
    .controls{
      position:absolute; z-index:3; bottom:0;
      left:calc(6px - var(--side)); right:calc(6px - var(--side));
      width:auto; max-width:none; padding:0;
      flex-direction:row; justify-content:space-between; align-items:flex-end;
      pointer-events:none;
    }
    .controls > *{ pointer-events:auto; }
    .die-row{ order:1; }
    .icon-row{
      order:2; display:grid; grid-template-columns:repeat(2, 36px); gap:6px;
      flex-direction:initial; margin:0;
    }
    .die-frame, body.theme-ancient .die-frame{ width:min(76px, calc(var(--side) + var(--eagle-w) * 0.33)); height:min(76px, calc(var(--side) + var(--eagle-w) * 0.33)); }
    .icon-btn{ width:36px; height:36px; min-height:36px; }
    /* route-guide colour key: below the board when shown */
    #guide-legend{ position:absolute; top:calc(100% + 6px); left:0; right:0; pointer-events:none; }
  }
  /* normal theme on phones: slightly smaller pieces so 10 always fit in two rows beside the head */
  @media (max-width:700px) and (orientation:portrait){
    body:not(.theme-ancient) .tray{ gap:2px; }
    body:not(.theme-ancient) .tray .piece{ width:16px; height:16px; }
    body:not(.theme-ancient) .slot{ width:7px; height:7px; }
    body:not(.theme-ancient) .finished-row{ gap:2px; margin-top:2px; }
    body:not(.theme-ancient) .panel-name{ font-size:0.76rem; }
  }
  /* piece size follows the width of each corner, so 5 always fit across (2 rows of 5) */
  @media (max-width:700px) and (orientation:portrait){
    #panel-1{ --pz:min(18px, calc((var(--side) + var(--eagle-w) * 0.39 - 12px) / 5 - 3px)); }
    #panel-2{ --pz:min(18px, calc((var(--side) + var(--eagle-w) * 0.215 - 10px) / 5 - 3px)); }
    .panel .tray .piece,
    body:not(.theme-ancient) .panel .tray .piece,
    body.theme-ancient .panel .tray .piece{ width:var(--pz); height:var(--pz); }
    body.theme-ancient .panel .tray .piece{ left:calc(var(--sx) * 100% - var(--pz) / 2); top:calc(var(--sy) * 100% - var(--pz) / 2); }
    body:not(.theme-ancient) .tray{ gap:2px 3px; }
  }

  /* AI corner on phones: 4 across, 3 rows (it is narrow but has height to spare) */
  @media (max-width:700px) and (orientation:portrait){
    #panel-2{ --pz:min(18px, calc((var(--side) + var(--eagle-w) * 0.215 - 10px) / 4 - 3px)); }

  }

  /* ---------- Live switch (theme button): the Jiroft eagle head, red when Live is on ---------- */
  .live-btn svg{ width:28px; height:28px; }
  .live-btn .eagle-ico{ fill:#9a917e; transition:fill .3s ease; }
  .live-btn .eagle-ico-holes{ fill:#f7f5f1; }
  .live-btn .eagle-ico-line{ stroke:#f7f5f1; }
  .live-btn .eagle-ico-eye{ fill:#f7f5f1; }
  .live-btn .eagle-ico-pupil{ fill:#4a4433; }
  .live-btn.active, body.theme-ancient .icon-btn.live-btn.active{
    background:radial-gradient(circle at 40% 35%, #3a2a1a, #1f160c);
    border-color:#e0442f;
    box-shadow:0 0 0 2px rgba(224,68,47,0.55), 0 3px 8px rgba(10,5,0,0.5);
  }
  .live-btn.active .eagle-ico{ fill:#e5332a; }
  .live-btn.active .eagle-ico-holes, .live-btn.active .eagle-ico-eye{ fill:#ffe1d6; }
  .live-btn.active .eagle-ico-line{ stroke:#5a0f0a; }
  .live-btn.active .eagle-ico-pupil{ fill:#3a0806; }
  .live-btn.active svg{ animation:liveGlow 2.2s ease-in-out infinite; }
  @keyframes liveGlow{ 0%,100%{ filter:drop-shadow(0 0 0 rgba(255,59,42,0)); } 50%{ filter:drop-shadow(0 0 4px rgba(255,59,42,0.85)); } }
  @media (prefers-reduced-motion: reduce){ .live-btn.active svg{ animation:none; } }

  .info-card .info-live{ padding:10px 12px; border-radius:10px; background:rgba(229,51,42,0.08); border:1px solid rgba(229,51,42,0.25); }
  .info-live-ico{ display:inline-block; width:9px; height:9px; margin-right:8px; border-radius:50%; background:#e5332a; vertical-align:middle; box-shadow:0 0 6px rgba(229,51,42,0.7); }

  /* At rest the eagle is one piece of stone. Only while the head turns is the body cut
     at the neck and the head shown as its own layer (so it can be swapped for the turning head). */
  .eagle-svg .head-stone{ display:none; }
  body.eagle-turn .eagle-svg .head-stone{ display:inline; }
  body.eagle-turn .eagle-svg .body-stone{ clip-path:url(#bodyClip); }

  /* ---------- "put it back" challenge ---------- */
  .knocked{ position:fixed; z-index:45; border-radius:50%; pointer-events:none; }
  .knocked.flying{ transition:left .6s cubic-bezier(.3,.6,.3,1), top .6s cubic-bezier(.5,-0.4,.6,1), transform .6s ease; transform:rotate(200deg); }
  .knocked.waiting{ animation:knockedPulse 1s ease-in-out infinite; pointer-events:auto; cursor:pointer; }
  .knocked.waiting::after{ content:''; position:absolute; top:-12px; right:-12px; bottom:-12px; left:-12px; border-radius:50%; }   /* easier to tap */
  .knocked.selected{ animation:none; box-shadow:0 0 0 3px #2f8fd8, 0 0 18px 6px rgba(47,143,216,.8); }
  @keyframes knockedPulse{ 0%,100%{ box-shadow:0 0 0 2px rgba(255,214,90,.9), 0 0 14px 4px rgba(255,190,60,.6); } 50%{ box-shadow:0 0 0 3px rgba(255,214,90,1), 0 0 22px 8px rgba(255,190,60,.85); } }
  .knocked .ch-ring{ position:absolute; top:-35%; left:-35%; width:170%; height:170%; transform:rotate(-90deg); overflow:visible; opacity:0; }
  .knocked.waiting .ch-ring{ opacity:1; }
  .knocked .ch-ring circle{ fill:none; stroke:#ffd84a; stroke-width:3; stroke-linecap:round; stroke-dasharray:113.1; stroke-dashoffset:calc(113.1 * (1 - var(--ch, 1))); }
  .challenge-ui{
    position:fixed; left:50%; bottom:max(14px, env(safe-area-inset-bottom)); z-index:46;
    transform:translateX(-50%) translateY(10px); opacity:0; transition:opacity .3s ease, transform .3s ease;
    display:flex; align-items:center; gap:12px; max-width:calc(100vw - 24px);
    padding:10px 18px 10px 10px; border-radius:30px;
    background:rgba(20,14,8,0.92); color:#ffe7a8; box-shadow:0 0 0 2px #ffd84a, 0 6px 20px rgba(0,0,0,.6);
    font-family:var(--font-display); font-size:clamp(0.85rem, 3.6vw, 1.05rem); text-align:left; pointer-events:none;
  }
  .challenge-ui.show{ opacity:1; transform:translateX(-50%); }
  .challenge-ui .ch-num{ flex:0 0 auto; width:40px; height:40px; border-radius:50%; display:flex; align-items:center; justify-content:center;
    background:#ffd84a; color:#2a1a05; font-size:1.3rem; font-weight:700; }
  .challenge-ui.ok{ box-shadow:0 0 0 2px #5ad16a, 0 6px 20px rgba(0,0,0,.6); }
  .challenge-ui.ok .ch-num{ background:#5ad16a; }
  .challenge-ui.bad{ box-shadow:0 0 0 2px #e5332a, 0 6px 20px rgba(0,0,0,.6); }
  .challenge-ui.bad .ch-num{ background:#e5332a; color:#fff; }
  .eagle-board .cell.ch-right{ box-shadow:0 0 0 3px #5ad16a, 0 0 16px 4px rgba(90,209,106,.8) !important; }
  .eagle-board .cell.ch-wrong{ box-shadow:0 0 0 3px #e5332a, 0 0 16px 4px rgba(229,51,42,.8) !important; }
  /* die and buttons step back while the eagle stares */
  .controls{ transition:opacity 1s ease; }
  body.eagle-dark .controls{ opacity:0.15; }
  /* the glow around the eagle eases in and out with the stare */
  .eagle-board .eagle-svg{ transition:filter 1.1s ease; }

  .eagle-board .cell.ch-spot{ cursor:pointer; animation:flashBlue 0.85s ease-in-out infinite; z-index:2; }

  /* ---------- losing ending (Live): black body, red neon, head stays stone and stares ---------- */
  .eagle-svg .body-black{ transition:opacity 1.2s ease; }
  body.cursed-end .eagle-svg .body-black{ opacity:1; }
  body.cursed-end .eagle-board .cell,
  body.cursed-end .panel,
  body.cursed-end .controls,
  body.cursed-end #guide-legend,
  body.cursed-end .knocked{ visibility:hidden !important; opacity:0 !important; }
  body.cursed-end .board-wrap .eagle-svg{ animation:neonPulse 1.8s ease-in-out infinite; }
  @keyframes neonPulse{
    0%,100%{ filter:drop-shadow(0 0 3px #ff2a1a) drop-shadow(0 0 10px #ff1a0a) drop-shadow(0 0 26px rgba(255,20,10,0.75)); }
    50%    { filter:drop-shadow(0 0 5px #ff4a3a) drop-shadow(0 0 16px #ff2a1a) drop-shadow(0 0 40px rgba(255,30,15,0.95)); }
  }
  body.cursed-end .weather{ display:none; }
  .ending.cursed{ justify-content:flex-end; padding-bottom:7vh; }
  .ending.cursed h2{ font-size:clamp(1.9rem, 8vw, 3.6rem); }
  @media (prefers-reduced-motion: reduce){ body.cursed-end .board-wrap .eagle-svg{ animation:none; filter:drop-shadow(0 0 4px #ff2a1a) drop-shadow(0 0 18px #ff1a0a); } }
  .ending.cursed h2{ background:rgba(0,0,0,0.78); padding:6px 18px; border-radius:12px; box-shadow:0 0 24px 10px rgba(0,0,0,0.7); }

  /* losing ending: the head turns black too — red eyes, white eyebrows */
  body.cursed-end .head3d [fill="url(#skull3d)"],
  body.cursed-end .head3d [fill="url(#stone)"]{ fill:#050505; filter:none; transition:fill 1.2s ease; }
  body.cursed-end .head3d [fill="url(#hole)"],
  body.cursed-end .head3d path[stroke="#8d9087"]{ opacity:0 !important; }
  body.cursed-end .head3d path[stroke="rgba(0,0,0,0.35)"]{ opacity:0; }
  body.cursed-end .head3d [stroke="#0e0f0d"][stroke-width="1.5"]{ stroke:#ff2a1a; stroke-width:2.5; }
  body.cursed-end .head3d path[stroke-width="6"]{ stroke:#ffffff; }
  /* the whole head black: skull texture and neck too (they are ready-made pictures in the lighter drawing) */
  body.cursed-end .head3d [fill="url(#skullTexP)"]{ fill:#050505; }
  body.cursed-end .head3d image.baked{ opacity:0; }
  body.cursed-end .head3d path[data-baked]{ visibility:visible !important; fill:#050505; filter:none; }
  /* red beak on the black head */
  body.cursed-end .head3d [fill="url(#beak3d)"]{ fill:url(#beakRed); }
  body.cursed-end .head3d ellipse[fill="#8f9289"]{ fill:#6e0803; }

  /* victory: the board is left alone (no pieces) while the eagle celebrates */
  body.lifted .eagle-board .cell{ visibility:hidden; }
  .eagle-board .eagle-svg{ overflow:visible; }   /* spread wings may reach past the drawing's edge */
  .ending.victory h2{ background:rgba(30,20,8,0.72); padding:6px 18px; border-radius:12px; box-shadow:0 0 24px 10px rgba(30,20,8,0.55); }
  /* info note never taller than the screen (phones held sideways): scrolls inside */
  .info-card{ max-height:calc(100vh - 24px); overflow-y:auto; -webkit-overflow-scrolling:touch; }
  @supports (height:100dvh){ .info-card{ max-height:calc(100dvh - 24px); } }
  @media (max-height:520px){ .info-card{ padding:18px 18px 14px; } .info-card p{ font-size:0.9rem; margin-bottom:8px; } .info-card h2{ font-size:1.15rem; margin-bottom:8px; } }

  /* while the eagle turns or an ending plays, the die and buttons cannot be tapped */
  body.eagle-turn .controls, body.ending-mode .controls{ pointer-events:none !important; }
  body.eagle-turn .controls *, body.ending-mode .controls *{ pointer-events:none !important; }

  /* ================================================================
     DIFFICULTY PICKER — Persian style: arched panel, star tilework, gold and turquoise
     ================================================================ */
  .mode-overlay{ background:radial-gradient(ellipse at 50% 40%, rgba(20,14,40,0.82), rgba(5,4,10,0.94)); }
  .mode-card{
    position:relative; width:min(380px, calc(100vw - 32px));
    border-radius:190px 190px 18px 18px / 150px 150px 18px 18px;   /* pointed-arch top */
    padding:10px; overflow:hidden;
    background:linear-gradient(160deg, #f4dc95, #b8862f 45%, #f1d27e 70%, #9c6f22);
    box-shadow:0 0 0 2px #5a3a10, 0 18px 50px rgba(0,0,0,0.65), 0 0 40px rgba(217,180,90,0.25);
    animation:modeIn .45s cubic-bezier(.2,.8,.3,1);
  }
  @keyframes modeIn{ from{ opacity:0; transform:translateY(14px) scale(.96); } to{ opacity:1; transform:none; } }
  .mode-card::before{     /* inner turquoise frame line */
    content:''; position:absolute; top:10px; right:10px; bottom:10px; left:10px; z-index:2; pointer-events:none;
    border-radius:182px 182px 12px 12px / 144px 144px 12px 12px;
    box-shadow:inset 0 0 0 3px #3fb6b0, inset 0 0 0 5px #0d2a5c, inset 0 0 0 6px #d9b45a;
  }
  .mode-pattern{ position:absolute; top:10px; right:10px; bottom:10px; left:10px; width:calc(100% - 20px); height:calc(100% - 20px);
    border-radius:182px 182px 12px 12px / 144px 144px 12px 12px; }
  .mode-inner{
    position:relative; z-index:3; margin:44px 22px 22px; padding:20px 18px 22px;
    border-radius:120px 120px 12px 12px / 90px 90px 12px 12px;
    background:radial-gradient(ellipse at 50% 30%, rgba(13,32,74,0.94), rgba(8,20,48,0.97));
    box-shadow:0 0 0 2px #d9b45a, 0 0 0 5px rgba(13,42,92,0.9), 0 0 0 6px #3fb6b0;
    text-align:center;
  }
  .mode-rosette{ width:54px; height:54px; display:block; margin:-46px auto 4px; filter:drop-shadow(0 2px 4px rgba(0,0,0,.6)); }
  .mode-sub{ margin:0; font-family:Georgia, "Times New Roman", serif; font-style:italic; letter-spacing:0.18em; text-transform:uppercase; font-size:0.72rem; color:#3fb6b0; }
  .mode-overlay h2{
    margin:4px 0 6px; font-family:Georgia, "Times New Roman", serif; font-weight:normal;
    font-size:clamp(1.5rem, 6.5vw, 2rem); letter-spacing:0.06em; text-transform:none;
    color:#f4dc95; text-shadow:0 1px 0 #6b4a12, 0 0 14px rgba(244,220,149,0.35);
  }
  .mode-divider{ display:flex; align-items:center; justify-content:center; gap:8px; margin:2px 0 16px; }
  .mode-divider span{ height:1px; width:60px; background:linear-gradient(90deg, transparent, #d9b45a, transparent); }
  .mode-divider i{ width:9px; height:9px; background:#3fb6b0; transform:rotate(45deg); box-shadow:0 0 0 2px #d9b45a; }
  .mode-buttons{ display:flex; flex-direction:column; gap:12px; }
  .mode-buttons button{
    display:flex; flex-direction:column; align-items:center; gap:2px; width:100%; min-width:0;
    padding:10px 16px 11px; border-radius:10px; text-transform:none; letter-spacing:0;
    font-family:Georgia, "Times New Roman", serif; border:2px solid #d9b45a;
    transition:transform .12s ease, filter .15s ease, box-shadow .15s ease;
  }
  .mode-buttons button[data-mode="easy"]{
    background:linear-gradient(180deg, #5fd0c8, #2a8f8a 55%, #1d6f6b); color:#fff8e6;
    box-shadow:inset 0 1px 0 rgba(255,255,255,.45), inset 0 -3px 0 rgba(0,0,0,.25), 0 3px 0 #0f4a47, 0 6px 14px rgba(0,0,0,.4);
  }
  .mode-buttons button[data-mode="hard"]{
    background:linear-gradient(180deg, #e8763a, #b8321e 55%, #8a1f12); color:#fff2df;
    box-shadow:inset 0 1px 0 rgba(255,255,255,.4), inset 0 -3px 0 rgba(0,0,0,.25), 0 3px 0 #5a140b, 0 6px 14px rgba(0,0,0,.4);
  }
  .mode-buttons button:hover:not(:disabled){ filter:brightness(1.08); transform:translateY(-1px); }
  .mode-buttons button:active:not(:disabled){ transform:translateY(2px); }
  .mb-title{ font-size:1.3rem; letter-spacing:0.05em; text-shadow:0 1px 2px rgba(0,0,0,.45); }
  .mb-note{ font-size:0.78rem; font-style:italic; opacity:0.9; }
  /* intro after choosing difficulty: what the live game is */
  .mode-intro[hidden], .mode-choose[hidden]{ display:none; }
  .mode-intro p{ margin:0 0 10px; font-family:Georgia, "Times New Roman", serif; font-size:0.98rem; line-height:1.5; color:#f3ead2; }
  .mode-intro p b{ color:#f4dc95; font-weight:normal; letter-spacing:0.04em; }
  .mode-intro p:last-of-type{ margin-bottom:16px; }
  .intro-go{
    display:flex; align-items:center; justify-content:center; width:100%; min-width:0; padding:10px 16px 11px;
    border-radius:10px; border:2px solid #d9b45a; text-transform:none; letter-spacing:0;
    font-family:Georgia, "Times New Roman", serif; color:#3a2508;
    background:linear-gradient(180deg, #f8e3a1, #d9b45a 55%, #a87a26);
    box-shadow:inset 0 1px 0 rgba(255,255,255,.55), inset 0 -3px 0 rgba(0,0,0,.2), 0 3px 0 #6b4a12, 0 6px 14px rgba(0,0,0,.4);
    transition:transform .12s ease, filter .15s ease;
  }
  .intro-go .mb-title{ text-shadow:0 1px 0 rgba(255,240,200,.6); }
  .intro-go:hover{ filter:brightness(1.06); transform:translateY(-1px); }
  .intro-go:active{ transform:translateY(2px); }
  .mode-card{ max-height:calc(100vh - 24px); overflow-y:auto; -webkit-overflow-scrolling:touch; }
  @supports (height:100dvh){ .mode-card{ max-height:calc(100dvh - 24px); } }
  @media (max-height:520px){ .mode-intro p{ font-size:0.86rem; margin-bottom:6px; } .mode-intro h2{ font-size:1.3rem; } }
  @media (max-height:520px){
    .mode-inner{ margin:30px 18px 16px; padding:12px 14px 14px; }
    .mode-rosette{ width:40px; height:40px; margin-top:-34px; }
    .mode-buttons{ flex-direction:row; }
    .mode-divider{ margin-bottom:10px; }
  }

  /* ---------- winning: gold background for the whole sequence, with readable text ---------- */
  body.pearl::before{
    opacity:1;
    background:
      radial-gradient(ellipse at 25% 20%, rgba(255,240,180,0.9), transparent 45%),
      radial-gradient(ellipse at 78% 75%, rgba(255,226,140,0.8), transparent 50%),
      linear-gradient(135deg, #b8862f 0%, #e9c46a 30%, #f7e1a0 50%, #d9a63e 72%, #9c6f22 100%);
    background-size:160% 160%;
    animation:pearlSheen 8s ease-in-out infinite;
  }
  @keyframes pearlSheen{ 0%,100%{ background-position:0% 0%; } 50%{ background-position:100% 100%; } }
  body.pearl .weather{ display:none; }
  body.pearl .panel-name, body.pearl .section-label{ color:#3a2508 !important; text-shadow:0 1px 0 rgba(255,240,200,0.6) !important; }
  body.pearl .board-wrap .eagle-svg{ filter:drop-shadow(0 12px 16px rgba(70,45,10,0.45)) drop-shadow(0 0 22px rgba(255,245,210,0.7)); }
  body.pearl .ending.victory h2{
    background:rgba(255,250,236,0.94); color:#4a2e06;
    text-shadow:none; box-shadow:0 0 0 2px #8a6418, 0 6px 20px rgba(70,45,10,0.4);
  }
  body.pearl .ending.victory button{ background:#4a2e06; color:#fbe9b8; box-shadow:0 3px 0 #2a1a03; }
  @media (prefers-reduced-motion: reduce){ body.pearl::before{ animation:none; } }
  body.pearl .ending.victory h2{ font-size:clamp(1.3rem, 4.6vw, 2.3rem); max-width:calc(100vw - 40px); padding:8px 22px; box-sizing:border-box; }

  /* ---------- settings panel ---------- */
  .settings-card h2{ margin-bottom:14px; }
  .set-row{ display:flex; align-items:center; justify-content:space-between; gap:14px; padding:12px 0; border-bottom:1px solid rgba(90,58,18,0.18); cursor:pointer; }
  .set-row span{ display:flex; flex-direction:column; gap:2px; }
  .set-row b{ font-size:1rem; color:#3a2a12; }
  .set-row small{ font-size:0.8rem; color:#786f5a; line-height:1.35; }
  .set-row input{ position:absolute; opacity:0; width:1px; height:1px; }
  .switch{ position:relative; flex:0 0 auto; width:50px; height:28px; border-radius:14px; background:#b9b0a0; transition:background .2s ease; box-shadow:inset 0 1px 3px rgba(0,0,0,.3); }
  .switch::after{ content:''; position:absolute; top:3px; left:3px; width:22px; height:22px; border-radius:50%; background:#fff; box-shadow:0 1px 3px rgba(0,0,0,.35); transition:transform .2s ease; }
  .set-row input:checked + .switch{ background:#2a8f8a; }
  .set-row input:checked + .switch::after{ transform:translateX(22px); }
  .set-row input:focus-visible + .switch{ box-shadow:0 0 0 3px rgba(47,143,216,.6); }
  .set-note{ font-size:0.82rem !important; color:#786f5a; margin:12px 0 4px !important; }
  /* six buttons on phones: three rows of two beside the tail */
  @media (max-width:700px) and (orientation:portrait){ .icon-row{ gap:5px; } }
  /* phones held sideways: six buttons as 3 rows of 2 beside the board */
  @media (max-height:520px) and (orientation:landscape){
    .icon-row{ display:grid; grid-template-columns:repeat(2, 34px); gap:6px; flex-direction:initial; }
    .icon-btn{ width:34px; height:34px; min-height:34px; }
  }

  /* ================================================================
     LEAVING LIVE: confirm, then "sands of time" (the board runs out like sand, then starts over in Normal mode)
     ================================================================ */
  .leave-card{ text-align:center; }
  .leave-glass{ width:34px; height:50px; display:block; margin:0 auto 8px; }
  .leave-buttons{ display:flex; gap:10px; justify-content:center; flex-wrap:wrap; margin-top:4px; }
  .leave-buttons button{ margin:0; min-height:42px; padding:10px 18px; }
  .leave-stay{ background:transparent; color:#5a3a12; box-shadow:inset 0 0 0 2px #c9a55a; }
  .leave-stay:hover{ background:rgba(201,165,90,0.15); }
  .sand-canvas{ position:fixed; top:0; left:0; width:100vw; height:100vh; pointer-events:none; z-index:66; }
  .sand-veil{ position:fixed; top:0; right:0; bottom:0; left:0; z-index:65; pointer-events:auto;
    background:radial-gradient(ellipse at 50% 45%, rgba(214,178,108,0.28), rgba(70,48,18,0.55));
    opacity:0; transition:opacity .6s ease; }
  .sand-veil.on{ opacity:1; }
  .sand-glass{ position:fixed; left:50%; top:50%; width:64px; height:96px; margin:-48px 0 0 -32px; z-index:67; pointer-events:none;
    opacity:0; transform:scale(.8); transition:opacity .5s ease, transform .5s ease; filter:drop-shadow(0 4px 10px rgba(0,0,0,.6)); }
  .sand-glass.on{ opacity:1; transform:scale(1); }
  .sand-glass svg{ width:100%; height:100%; transition:transform .7s cubic-bezier(.5,0,.3,1); }
  .sand-glass.flip svg{ transform:rotate(180deg); }
  .sand-glass .sg-top{ transform-origin:20px 24px; animation:sgTop 2.4s linear forwards; }
  .sand-glass .sg-bot{ transform-origin:20px 55px; animation:sgBot 2.4s linear forwards; }
  .sand-glass .sg-stream{ animation:sgStream .25s linear infinite alternate; }
  @keyframes sgTop{ from{ transform:scaleY(1); } to{ transform:scaleY(0.05); } }
  @keyframes sgBot{ from{ transform:scaleY(0.1); } to{ transform:scaleY(1); } }
  @keyframes sgStream{ from{ opacity:.6; } to{ opacity:1; } }
  /* the waiting pieces and the die run out with the board, and everything settles back in */
  body.sand-out .panel, body.sand-out .controls{ opacity:0; transition:opacity 1.8s ease; }
  body.sand-in .board{ animation:sandSettle .9s ease-out; }
  body.sand-in .panel, body.sand-in .controls{ animation:sandSettle .9s ease-out; }
  @keyframes sandSettle{ from{ opacity:0; filter:blur(3px) sepia(.6); } to{ opacity:1; filter:none; } }
  .leave-modal{ z-index:120; }

  /* ================================================================
     DESKTOP & TABLET — BIG BOARD (like the phone layout)
     The board is sized by the screen height. The waiting pieces sit in the
     columns beside the head; the die (left) and buttons (right) sit in the
     same columns beside the tail, so nothing below the board steals height.
     ================================================================ */
  @media (min-width:701px) and (min-height:521px){
    :root, body.theme-ancient{
      --dside:clamp(150px, 17vw, 250px);
      --dgap:clamp(14px, 2vw, 28px);
      --eagle-w:min(calc((100vh - 44px) * 0.468), calc(100vw - 2 * var(--dside) - 2 * var(--dgap) - 24px), 640px);
    }
    @supports (height:100dvh){
      :root, body.theme-ancient{ --eagle-w:min(calc((100dvh - 44px) * 0.468), calc(100vw - 2 * var(--dside) - 2 * var(--dgap) - 24px), 640px); }
    }
    body{ padding-top:16px; padding-bottom:16px; }
    .table{
      display:flex; flex-wrap:nowrap; align-items:flex-start; justify-content:center;
      gap:var(--dgap); width:auto; max-width:none; margin:0 auto;
    }
    .panel{ width:var(--dside); flex:0 0 var(--dside); max-width:none; }
    .board-wrap{
      position:relative; flex:0 0 auto; width:var(--eagle-w); padding:0; margin:0;
      background:transparent; border:none; box-shadow:none;
    }
    .board.eagle-board{ width:var(--eagle-w); height:calc(var(--eagle-w) * 1024 / 479); }
    /* die and buttons in the side columns, level with the tail */
    .controls{
      position:absolute; z-index:3; bottom:0;
      left:calc(-1 * (var(--dside) + var(--dgap))); right:calc(-1 * (var(--dside) + var(--dgap)));
      width:auto; max-width:none; padding:0; margin:0;
      display:flex; flex-direction:row; justify-content:space-between; align-items:flex-end;
      pointer-events:none;
    }
    .controls > *{ pointer-events:auto; }
    .die-row{ order:1; width:var(--dside); display:flex; justify-content:center; margin:0; }
    .icon-row{
      order:2; width:var(--dside); margin:0;
      display:grid; grid-template-columns:repeat(3, 44px); gap:10px; justify-content:center;
    }
    .icon-btn{ width:44px; height:44px; min-height:44px; }
    .die-frame, body.theme-ancient .die-frame{
      width:min(124px, calc(var(--dside) - 20px), calc(var(--eagle-w) * 0.3));
      height:min(124px, calc(var(--dside) - 20px), calc(var(--eagle-w) * 0.3));
    }
    /* route-guide colour key: in the right column, above the buttons */
    #guide-legend{
      position:absolute; right:0; bottom:calc(2 * 44px + 10px + 22px); width:var(--dside);
      flex-direction:column; align-items:flex-start; gap:8px; pointer-events:none;
    }
  }
  /* desktop & tablet: waiting pieces scale with the bigger board */
  @media (min-width:701px) and (min-height:521px){
    .panel{ --pz:clamp(20px, calc(var(--eagle-w) * 0.058), 30px); }
    .panel .tray .piece, body:not(.theme-ancient) .panel .tray .piece, body.theme-ancient .panel .tray .piece{ width:var(--pz); height:var(--pz); }
    body.theme-ancient .panel .tray{ height:calc(var(--eagle-w) * 1024 / 479 * 0.24); }
    body.theme-ancient .panel .tray .piece{ left:calc(var(--sx) * 100% - var(--pz) / 2); top:calc(var(--sy) * 100% - var(--pz) / 2); }
    .slot{ width:calc(var(--pz) * 0.55); height:calc(var(--pz) * 0.55); }
    .panel-name{ font-size:clamp(1rem, 1.3vw, 1.35rem); }
  }

  /* ================================================================
     DIFFICULTY CARD — JIROFT STYLE
     A carved chlorite panel like the Jiroft "house" vessels: a running key
     frieze and cross band on top, latticed windows down both sides, a
     draped doorway arch over the text, and fluted columns along the base.
     Light incised lines with a dark shadow edge, inlays of turquoise and
     carnelian on the buttons.
     ================================================================ */
  .mode-overlay{ background:radial-gradient(ellipse at 50% 40%, rgba(24,22,16,0.84), rgba(6,6,4,0.95)); }
  .mode-card{
    width:min(400px, calc(100vw - 24px)); padding:0; border-radius:16px; overflow:hidden;
    display:flex; flex-direction:column;
    background-color:#353832;
    background-image:
      url("../img/jiroft-stone.svg"),
      radial-gradient(ellipse at 30% 20%, rgba(120,128,112,0.35), transparent 60%),
      linear-gradient(160deg, #42463f, #2b2e29 60%, #1f211d);
    box-shadow:0 0 0 2px #151613, 0 0 0 4px #5b5f55, 0 0 0 5px #151613, 0 20px 50px rgba(0,0,0,0.7),
               inset 0 2px 0 rgba(255,255,255,0.08), inset 0 -3px 0 rgba(0,0,0,0.35);
  }
  .mode-card::before{ content:none; }
  .mode-card::after{ content:''; position:absolute; top:0; right:0; bottom:0; left:0; pointer-events:none; border-radius:16px;
    box-shadow:inset 0 0 40px rgba(0,0,0,0.45); }
  /* bands of carving */
  .jf-band{ flex:0 0 auto; background-repeat:repeat-x; background-position:center; }
  .jf-fret{
    height:30px; margin:10px 10px 0;
    border-top:2px solid #cfc9b6; border-bottom:2px solid #cfc9b6;
    box-shadow:0 1px 0 #141512, inset 0 1px 0 #141512;
    background-image:url("../img/jiroft-key.svg");
  }
  .jf-cross{
    height:20px; margin:4px 10px 0;
    background-image:url("../img/jiroft-cross.svg");
  }
  .jf-flutes{
    height:44px; margin:0 10px 10px;
    border-top:2px solid #cfc9b6; box-shadow:inset 0 1px 0 #141512;
    background-position:center top;
    background-image:url("../img/jiroft-flutes.svg");
  }
  /* middle: latticed windows either side of the doorway */
  .jf-body{ flex:1 1 auto; display:flex; align-items:stretch; gap:8px; margin:8px 10px; min-height:0; }
  .jf-pillar{
    flex:0 0 32px; border-radius:3px;
    box-shadow:0 0 0 2px #cfc9b6, 0 0 0 3px #141512, inset 0 0 8px rgba(0,0,0,0.5);
    background-repeat:repeat-y; background-position:center top;
    background-image:url("../img/jiroft-lattice.svg");
  }
  /* the doorway: a recessed panel under a draped arch */
  .mode-inner{
    flex:1 1 auto; margin:0; padding:0 14px 16px; border-radius:4px;
    background-color:rgba(18,19,16,0.42);
    background-image:url("../img/jiroft-hatch.svg");
    box-shadow:0 0 0 2px #cfc9b6, 0 0 0 3px #141512, inset 0 3px 10px rgba(0,0,0,0.55);
    text-align:center;
  }
  .jf-arch{ display:block; width:calc(100% + 28px); height:auto; margin:0 -14px 2px; }
  .mode-rosette{ display:none; }
  .mode-sub{ margin:0; font-family:Georgia, "Times New Roman", serif; font-style:normal; font-variant:small-caps;
    letter-spacing:0.22em; text-transform:none; font-size:0.86rem; color:#bfb9a6; text-shadow:0 1px 0 #0e0f0c; }
  .mode-overlay h2{
    margin:2px 0 6px; font-family:Georgia, "Times New Roman", serif; font-weight:normal;
    font-size:clamp(1.45rem, 6.2vw, 1.9rem); letter-spacing:0.05em;
    color:#ece5d0; text-shadow:0 2px 0 #0e0f0c, 0 -1px 0 rgba(255,255,255,0.12);
  }
  /* divider: a short run of the key frieze */
  .mode-divider{ display:block; height:12px; width:150px; margin:4px auto 16px;
    background:url("../img/jiroft-key-small.svg") repeat-x center;
    opacity:0.85; }
  .mode-divider span, .mode-divider i{ display:none; }
  /* buttons: carved stone tablets with an inlaid stone edge */
  .mode-buttons{ gap:12px; }
  .mode-buttons button, .intro-go{
    position:relative; border:none; border-radius:6px; color:#efe8d4;
    font-family:Georgia, "Times New Roman", serif;
    background-color:#2c2f2a;
    background-image:linear-gradient(180deg, rgba(255,255,255,0.08), rgba(0,0,0,0.25)),
      url("../img/jiroft-hatch-button.svg");
    transition:transform .12s ease, filter .15s ease, box-shadow .15s ease;
  }
  .mode-buttons button[data-mode="easy"]{   /* turquoise inlay */
    background-color:#2c2f2a; color:#efe8d4;
    background-image:linear-gradient(180deg, rgba(58,167,158,0.22), rgba(0,0,0,0.25));
    box-shadow:inset 0 0 0 2px #cfc9b6, inset 0 0 0 4px #1c1e1a, inset 0 0 0 7px #3aa79e, inset 0 0 0 8px #141512,
               0 3px 0 #10110e, 0 8px 16px rgba(0,0,0,0.45);
  }
  .mode-buttons button[data-mode="hard"]{   /* carnelian inlay */
    background-color:#2c2f2a; color:#efe8d4;
    background-image:linear-gradient(180deg, rgba(182,69,42,0.22), rgba(0,0,0,0.25));
    box-shadow:inset 0 0 0 2px #cfc9b6, inset 0 0 0 4px #1c1e1a, inset 0 0 0 7px #b6452a, inset 0 0 0 8px #141512,
               0 3px 0 #10110e, 0 8px 16px rgba(0,0,0,0.45);
  }
  .intro-go{   /* pale limestone inlay */
    color:#efe8d4; background-color:#2c2f2a;
    background-image:linear-gradient(180deg, rgba(217,207,174,0.16), rgba(0,0,0,0.25));
    box-shadow:inset 0 0 0 2px #cfc9b6, inset 0 0 0 4px #1c1e1a, inset 0 0 0 7px #d9cfae, inset 0 0 0 8px #141512,
               0 3px 0 #10110e, 0 8px 16px rgba(0,0,0,0.45);
  }
  .mode-buttons button{ padding:13px 18px 14px; }
  .intro-go{ padding:13px 18px 14px; }
  .mb-title{ font-size:1.3rem; letter-spacing:0.06em; text-shadow:0 2px 0 #0e0f0c; }
  .intro-go .mb-title{ text-shadow:0 2px 0 #0e0f0c; }
  .mode-buttons button[data-mode="easy"] .mb-note{ color:#8fd6cf; }
  .mode-buttons button[data-mode="hard"] .mb-note{ color:#e69a82; }
  .mb-note{ opacity:1; text-shadow:0 1px 0 #0e0f0c; }
  .mode-buttons button:hover:not(:disabled), .intro-go:hover{ filter:brightness(1.12); transform:translateY(-1px); }
  .mode-buttons button:active:not(:disabled), .intro-go:active{ transform:translateY(2px); }
  .mode-buttons button:focus-visible, .intro-go:focus-visible{ outline:2px solid #e9dfc0; outline-offset:3px; }
  .mode-intro p{ color:#e6dfca; text-shadow:0 1px 0 #0e0f0c; }
  .mode-intro p b{ color:#8fd6cf; }
  @media (max-height:520px){
    .jf-fret{ height:22px; margin-top:6px; } .jf-cross{ display:none; } .jf-flutes{ height:26px; margin-bottom:6px; }
    .jf-body{ margin:6px 8px; } .jf-pillar{ flex-basis:24px; background-size:24px 24px; }
    .mode-inner{ padding:0 12px 10px; } .jf-arch{ width:calc(100% + 24px); margin:0 -12px 0; max-height:36px; }
    .mode-divider{ margin-bottom:10px; }
  }
  @media (max-width:360px){ .jf-pillar{ flex-basis:24px; background-size:24px 24px; } .jf-body{ gap:6px; } }
  /* game name: bold and large at the top of the doorway */
  .mode-sub{
    font-weight:bold; font-size:clamp(1.15rem, 5.4vw, 1.5rem); letter-spacing:0.12em;
    font-variant:small-caps; color:#ece5d0; margin:0 0 2px;
    text-shadow:0 2px 0 #0e0f0c, 0 -1px 0 rgba(255,255,255,0.12);
  }
  .mode-overlay h2{ font-size:clamp(1.3rem, 5.4vw, 1.65rem); color:#d8d1bc; }
  /* the carved middle never squeezes under the bands: the card scrolls instead on very short screens */
  .jf-body{ flex:0 0 auto; }
  @media (max-height:520px){
    .mode-sub{ font-size:1.15rem; }
    .mode-overlay h2{ font-size:1.2rem; margin:0 0 4px; }
    .mode-buttons{ flex-direction:row; flex-wrap:nowrap; }
    .mode-buttons button{ width:auto; flex:1 1 0; padding:9px 12px 10px; }
  }

  /* ---------- button icons: image files in the img folder (one colour set per theme) ---------- */
  .ico{ display:inline-block; width:20px; height:20px; vertical-align:middle; background:no-repeat center / contain; }
  .ico-restart{ background-image:url("../img/icon-restart.svg"); }
  .ico-sound-on{ background-image:url("../img/icon-sound-on.svg"); }
  .ico-sound-off{ background-image:url("../img/icon-sound-off.svg"); }
  .ico-settings{ background-image:url("../img/icon-settings.svg"); }
  .ico-info{ background-image:url("../img/icon-info.svg"); }
  body.theme-ancient .ico-restart{ background-image:url("../img/icon-restart-live.svg"); }
  body.theme-ancient .ico-sound-on{ background-image:url("../img/icon-sound-on-live.svg"); }
  body.theme-ancient .ico-settings{ background-image:url("../img/icon-settings-live.svg"); }
  body.theme-ancient .ico-info{ background-image:url("../img/icon-info-live.svg"); }
  @media (max-height:520px) and (orientation:landscape){ .ico{ width:18px; height:18px; } }
  /* Live switch: grey eagle head when off, red when on */
  .ico-live{
    display:inline-block; width:28px; height:28px; vertical-align:middle;
    background:url("../img/icon-live-off.svg") no-repeat center / contain;
  }
  .live-btn.active .ico-live{ background-image:url("../img/icon-live-on.svg"); animation:liveGlow 2.2s ease-in-out infinite; }
  @media (prefers-reduced-motion: reduce){ .live-btn.active .ico-live{ animation:none; } }
  img.jf-arch{ display:block; width:calc(100% + 28px); height:auto; margin:0 -14px 2px; }
  @media (max-height:520px){ img.jf-arch{ width:calc(100% + 24px); margin:0 -12px 0; max-height:36px; object-fit:fill; } }
  img.leave-glass{ width:34px; height:50px; display:block; margin:0 auto 8px; }

  /* route guide shows only the player's own path: the AI's wing is not marked, and there is no text key */
  .board.guide-active .cell[data-col="2"], .board.eagle-board.guide-active .cell[data-col="2"]{ box-shadow:none; }
  #guide-legend, #guide-legend.show{ display:none !important; }
  /* route guide arrows: bold and black */
  .guide-arrow, .eagle-board .guide-arrow, .eagle-board .guide-arrow.exit{
    color:#000; font-weight:900; -webkit-text-stroke:1.6px #000; text-shadow:0 0 3px rgba(255,255,255,0.55);
  }
  /* the last space is an X: its "leave the board" arrow sits just below the cup, not on top of the X */
  .eagle-board .guide-arrow.exit{ top:auto; bottom:-1.2em; transform:translate(-50%, 0); animation:guideBounceExit 1.2s ease-in-out infinite; }
  @keyframes guideBounceExit{ 0%,100%{ transform:translate(-50%, 0); } 50%{ transform:translate(-50%, 3px); } }

  /* credit line under the difficulty buttons */
  .mode-credit{
    margin:14px 0 0; font-family:Georgia, "Times New Roman", serif; font-size:0.72rem; line-height:1.5;
    letter-spacing:0.04em; color:#a9a390; text-shadow:0 1px 0 #0e0f0c;
  }
  @media (max-height:520px){ .mode-credit{ margin-top:8px; font-size:0.66rem; } .mode-credit br{ display:none; } }
  .mode-credit b{ font-weight:bold; color:#cfc9b6; letter-spacing:0.06em; }
  @media (max-height:520px){ .mode-credit br{ display:inline; } .mode-credit br:first-of-type{ display:none; } }

  /* ---------- X-sign challenge: the yellow X discs knocked off the board ---------- */
  .x-token{
    position:fixed; z-index:45; border-radius:50%; pointer-events:none; box-sizing:border-box;
    display:flex; align-items:center; justify-content:center;
    background:radial-gradient(circle at 40% 34%, #fff2a8 0%, #ffd94a 45%, #e7b21c 85%, #b98a12 100%);
    border:2.5px solid #ffe066;
    box-shadow:inset 0 2px 4px rgba(120,80,0,0.45), 0 4px 10px rgba(0,0,0,0.55);
  }
  .x-token .cross{ position:relative; width:74%; height:74%; pointer-events:none; }
  .x-token .cross::before, .x-token .cross::after{
    content:''; position:absolute; top:50%; left:50%; width:20%; height:100%;
    background:#3d2600; border-radius:3px; box-shadow:0 0 0 1px rgba(255,240,180,0.6);
  }
  .x-token .cross::before{ transform:translate(-50%,-50%) rotate(45deg); }
  .x-token .cross::after{ transform:translate(-50%,-50%) rotate(-45deg); }
  .x-token.flying{ transition:left .6s cubic-bezier(.3,.6,.3,1), top .6s cubic-bezier(.5,-0.4,.6,1), transform .6s ease, opacity .6s ease; transform:rotate(160deg); }
  .x-token.waiting{ animation:knockedPulse 1s ease-in-out infinite; pointer-events:auto; cursor:pointer; }
  .x-token.waiting::after{ content:''; position:absolute; top:-12px; right:-12px; bottom:-12px; left:-12px; border-radius:50%; }
  .x-token.selected{ animation:none; box-shadow:0 0 0 3px #2f8fd8, 0 0 18px 6px rgba(47,143,216,.8); }
  .x-token .ch-ring{ position:absolute; top:-35%; left:-35%; width:170%; height:170%; transform:rotate(-90deg); overflow:visible; opacity:0; pointer-events:none; }
  .x-token.waiting .ch-ring{ opacity:1; }
  .x-token .ch-ring circle{ fill:none; stroke:#ffd84a; stroke-width:3; stroke-linecap:round; stroke-dasharray:113.1; stroke-dashoffset:calc(113.1 * (1 - var(--ch, 1))); }
  .x-token.lost{ transition:transform .6s ease, opacity .6s ease; transform:scale(0.2) rotate(300deg); opacity:0; }
  body.cursed-end .x-token{ visibility:hidden !important; opacity:0 !important; }

  /* challenge message: in the bottom-left corner beside the tail (over the unused die), never over the board's spaces */
  .challenge-ui{
    left:max(8px, env(safe-area-inset-left)); right:auto;
    bottom:max(10px, env(safe-area-inset-bottom));
    width:auto; max-width:min(300px, calc((100vw - var(--eagle-w) * 0.36) / 2 - 16px));
    transform:translateY(10px); border-radius:18px; padding:10px 14px 10px 10px;
  }
  .challenge-ui.show{ transform:none; }
  /* narrow corners (phones held upright): number on top, words underneath */
  @media (max-width:700px) and (orientation:portrait){
    .challenge-ui{
      flex-direction:column; align-items:center; gap:6px; text-align:center;
      padding:10px 8px 10px; font-size:0.8rem; line-height:1.25;
    }
    .challenge-ui .ch-num{ width:34px; height:34px; font-size:1.1rem; }
  }
  @media (min-width:701px) and (min-height:521px){
    .challenge-ui{
      left:calc(50% - var(--eagle-w) / 2 - var(--dgap) - var(--dside)); width:var(--dside); max-width:none;
      bottom:16px; flex-direction:column; align-items:center; gap:8px; text-align:center; padding:12px 12px 14px;
    }
  }

  /* eagle's full-head stare: a bold red neon glow around the whole eagle */
  body.eagle-dark .board-wrap .eagle-svg{
    filter:drop-shadow(0 0 3px #ff3b2a) drop-shadow(0 0 12px rgba(255,40,20,0.95)) drop-shadow(0 0 34px rgba(255,30,10,0.8));
  }

  /* ================================================================
     OLDER BROWSERS: safety nets
     ================================================================ */
  /* no min()/clamp() (Chrome < 79, Firefox < 75, Samsung Internet < 12): fixed sizes for the layout values */
  @supports not (width: min(1px, 2px)){
    :root, body.theme-ancient{ --side-w:64px; --dside:200px; --dgap:20px; }
    .panel{ --pz:20px; }
    #panel-1, #panel-2{ --pz:16px; }
    @media (min-width:701px) and (min-height:521px){
      :root, body.theme-ancient{ --eagle-w:330px !important; }
      .panel{ --pz:24px; }
    }
    @media (min-width:701px) and (min-height:900px){ :root, body.theme-ancient{ --eagle-w:420px !important; } }
  }
  /* no gap in flex rows (Safari / iOS < 14.1, Chrome < 84): margins give the same spacing */
  @supports not (inset: 0){
    .mode-buttons > * + *{ margin-top:12px; }
    .table > * + *{ margin-left:var(--dgap, 18px); }
    .tray .piece{ margin:1.5px; }
    .challenge-ui > * + *{ margin-left:12px; }
    .leave-buttons > * + *{ margin-left:10px; }
    .finished-row .slot{ margin:1px; }
    @media (max-height:520px){ .mode-buttons > * + *{ margin-top:0; margin-left:12px; } }
    @media (max-width:700px) and (orientation:portrait){ .challenge-ui > * + *{ margin-left:0; margin-top:6px; } }
  }

  /* ================================================================
     LIGHT RENDERING: glow and shadow as ready-made pictures
     Once the pictures are made (body.fx-baked), the costly live CSS
     filters on the board are switched off and the pictures are shown
     instead. Fading a picture in and out costs almost nothing.
     ================================================================ */
  .eagle-board .eagle-glow{
    position:absolute; display:block; max-width:none; pointer-events:none;
    opacity:0; -webkit-transition:opacity 1.1s ease; transition:opacity 1.1s ease;
    -webkit-user-select:none; user-select:none;
  }
  body.fx-baked .eagle-board .eagle-svg,
  body.fx-baked.theme-ancient .eagle-svg,
  body.fx-baked.eagle-dark .board-wrap .eagle-svg,
  body.fx-baked.eagle-white.eagle-dark .board-wrap .eagle-svg,
  body.fx-baked.cursed-end .board-wrap .eagle-svg,
  body.fx-baked.pearl .board-wrap .eagle-svg{ filter:none !important; -webkit-filter:none !important; animation:none !important; }
  body.fx-baked.theme-ancient .eagle-glow.g-shadow{ opacity:1; }
  body.fx-baked.eagle-dark .eagle-glow.g-shadow,
  body.fx-baked.pearl .eagle-glow.g-shadow,
  body.fx-baked.cursed-end .eagle-glow.g-shadow{ opacity:0; }
  body.fx-baked.eagle-dark .eagle-glow.g-red{ opacity:1; }
  body.fx-baked.eagle-white.eagle-dark .eagle-glow.g-red{ opacity:0; }
  body.fx-baked.eagle-white.eagle-dark .eagle-glow.g-dark{ opacity:1; }
  body.fx-baked.pearl:not(.eagle-dark) .eagle-glow.g-pearl{ opacity:1; }
  body.fx-baked.cursed-end .eagle-glow.g-red{ opacity:1; animation:glowPulse 1.8s ease-in-out infinite; }
  @keyframes glowPulse{ 0%,100%{ opacity:.78; } 50%{ opacity:1; } }
  @media (prefers-reduced-motion: reduce){ body.fx-baked.cursed-end .eagle-glow.g-red{ animation:none; } }
  body.fx-baked.theme-ancient.lifted .eagle-glow.g-shadow{ opacity:0; }
  body.fx-baked.theme-ancient.lifted .eagle-glow.g-lift{ opacity:1; -webkit-transition-duration:2s; transition-duration:2s; }
  body.fx-baked.eagle-dark .eagle-glow.g-lift, body.fx-baked.pearl .eagle-glow.g-lift{ opacity:0; }
  body.eagle-turn .eagle-svg .body-shadow{ clip-path:url(#bodyClip); }
  /* victory wings: the still board's shadow and glow would leave a ghost of the folded wings behind them */
  body.wings-out .eagle-svg .body-shadow{ display:none; }   /* no stray shadows from the moving wings */
  body.fx-baked.wings-out .eagle-glow{ opacity:0 !important; -webkit-transition:none !important; transition:none !important; }
  /* settings (wind and tremors) only belong to Live mode */
  body:not(.theme-ancient) #settings-btn{ display:none; }
  /* Normal mode: the eagle never blinks */
  body:not(.theme-ancient) .eagle-svg .eyelid{ animation:none !important; transform:scaleY(0) !important; }

  /* ================================================================
     NEXT GAME: the snake's curse (shown after a win)
     ================================================================ */
  .end-actions{ display:flex; flex-wrap:wrap; justify-content:center; gap:12px; }
  .end-actions [hidden]{ display:none; }
  .continue-btn{ background:#b3261b; color:#fff3dc; box-shadow:0 3px 0 #5a120c; }
  body.pearl .ending.victory button.continue-btn{ background:#b3261b; color:#fff3dc; box-shadow:0 3px 0 #5a120c; }
  .continue-btn:active:not(:disabled){ box-shadow:0 1px 0 #5a120c; }

  .snake-curse{
    position:fixed; top:0; right:0; bottom:0; left:0; z-index:110;
    display:flex; align-items:center; justify-content:center;
    padding:16px; box-sizing:border-box; overflow:auto;
    background-color:#0b0d0c;
    background-image:radial-gradient(ellipse at 50% 46%, rgba(178,30,18,0.62) 0%, rgba(90,12,8,0.34) 30%, rgba(11,13,12,0) 64%);
    opacity:0; transition:opacity .6s ease;
  }
  .snake-curse[hidden]{ display:none; }
  .snake-curse.show{ opacity:1; }
  .snake-curse__inner{ display:flex; flex-direction:column; align-items:center; gap:18px; text-align:center; max-width:640px; }
  .snake-curse__art{
    display:block; width:auto; height:auto;
    max-height:58vh; max-height:58dvh; max-width:72vw;
    filter:drop-shadow(0 18px 30px rgba(0,0,0,0.7));
    transform:scale(0.94); transition:transform 1.2s ease-out;
  }
  .snake-curse.show .snake-curse__art{ transform:scale(1); }
  .snake-curse h2{
    margin:0; font-family:Georgia, "Times New Roman", serif;
    font-size:clamp(1.5rem, 5.4vw, 2.6rem); line-height:1.2; letter-spacing:0.04em;
    color:#ffe7a8; text-shadow:0 0 14px rgba(0,0,0,0.85), 0 0 30px rgba(255,180,90,0.35);
  }
  @media (max-height:520px) and (orientation:landscape){
    .snake-curse__inner{ flex-direction:row; flex-wrap:wrap; justify-content:center; max-width:none; }
    .snake-curse__art{ max-height:84vh; max-height:84dvh; }
    .snake-curse__text{ display:flex; flex-direction:column; gap:18px; }
  }

  .icon-btn.snake-btn{ display:inline-flex; align-items:center; justify-content:center; }
  .icon-btn.snake-btn[hidden]{ display:none; }
  .icon-btn.snake-btn svg{ display:block; width:86%; height:86%; }
  .icon-btn.snake-btn.snake-new{ animation:snakeNew 1.2s ease-in-out 4; }
  @keyframes snakeNew{
    0%,100%{ box-shadow:0 0 0 0 rgba(230,60,40,0); }
    50%{ box-shadow:0 0 0 6px rgba(230,60,40,0.55); }
  }
  .snake-toast{
    position:fixed; left:50%; top:16px; top:calc(16px + env(safe-area-inset-top, 0px)); z-index:111; transform:translateX(-50%);
    max-width:calc(100vw - 32px); box-sizing:border-box;
    padding:12px 18px; border-radius:10px;
    background:rgba(20,22,21,0.94); color:#f3e6cc; border:1px solid #b3261b;
    font-family:var(--font-display); font-size:0.95rem; text-align:center;
    box-shadow:0 10px 30px rgba(0,0,0,0.5);
  }
  .snake-toast[hidden]{ display:none; }
  @media (prefers-reduced-motion:reduce){
    .snake-curse, .snake-curse__art{ transition:none; }
    .icon-btn.snake-btn.snake-new{ animation:none; }
  }
  .snake-curse__text{ display:flex; flex-direction:column; align-items:center; gap:18px; }
