/* Orapa Mine — mobile d'abord : un onglet = un écran, sans défilement. */
:root{
  --ink:#142337;--muted:#6c7c90;--paper:#f1ede5;--card:#fff;--line:#dcd6cb;
  --navy:#1d344d;--amber:#e99e29;--amber2:#f5c65b;--teal:#2c8e80;
  --red:#d84c4f;--yellow:#e9a52c;--blue:#397fc7;--white:#e6e9dd;
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family:Outfit,system-ui,-apple-system,sans-serif;
  color:var(--ink);
  background:radial-gradient(circle at 6% -6%,#fff,transparent 34%),var(--paper);
  display:flex;flex-direction:column;
  min-height:100dvh;max-height:100dvh;overflow:hidden;
  -webkit-tap-highlight-color:transparent;
}
[hidden]{display:none!important}
button{font-family:inherit}

/* ---------- barre supérieure ---------- */
.topbar{
  flex:none;display:flex;align-items:center;justify-content:space-between;gap:12px;
  padding:9px 16px;padding-top:max(9px,env(safe-area-inset-top));
  border-bottom:1px solid var(--line);background:#fbf9f4;
}
.brand{display:flex;align-items:center;gap:8px}
.brand-mark{color:var(--amber);font-size:18px;line-height:1}
.brand h1{margin:0;font-size:14px;font-weight:700;letter-spacing:.17em}
.brand em{font-style:normal;color:var(--amber)}
.rules{font:500 10px/1 'DM Mono',monospace;color:var(--muted);letter-spacing:.05em}

/* ---------- onglets ---------- */
.tabs{
  flex:none;display:flex;gap:4px;padding:5px 10px;
  background:#e7e3da;border-bottom:1px solid var(--line);
}
.tab{
  flex:1;min-height:36px;border:0;border-radius:9px;background:transparent;
  padding:8px 4px;font:600 12px Outfit;color:#61708a;cursor:pointer;
  transition:background .15s,color .15s,box-shadow .15s;
}
.tab.active{background:var(--card);color:var(--ink);box-shadow:0 2px 8px #29394722}

/* ---------- panneaux ---------- */
.panel{flex:1;min-height:0;position:relative;display:flex;flex-direction:column;overflow:hidden}
/* contenu ancré en bas : à portée du pouce, respiration en haut */
#panel-board{justify-content:flex-end}

/* invitation discrète à passer en paysage (mobile portrait seulement) */
.rotate-hint{display:none}

.stage-head{
  flex:none;display:flex;justify-content:space-between;align-items:center;
  padding:8px 18px 2px;font:500 9px 'DM Mono',monospace;letter-spacing:.16em;color:var(--muted);
}
#counter{color:var(--ink)}
body:not(.play-mode) .stage-head{display:none}

/* ---------- plateau ---------- */
.stage{
  flex:0 1 auto;min-height:0;min-width:0;overflow:hidden;
  display:flex;align-items:center;justify-content:center;padding:10px 6px;
  --chrome:210px;
}
.play-mode .stage{--chrome:374px}

.board-frame{
  flex:none;width:max-content;height:max-content;max-width:100%;
  position:relative;padding:13px 15px;border-radius:16px;
  background:linear-gradient(150deg,#33526f,#132a43);
  box-shadow:inset 0 0 22px #0b192488,0 14px 26px #1b2e4126;
}
.board{
  /* dimensions explicites : le plateau tient toujours dans l'écran */
  --bh:min(calc(100dvh - var(--chrome)),calc((100vw - 42px) * .8),70dvh);
  height:var(--bh);width:calc(var(--bh) * 1.25);
  position:relative;overflow:hidden;border-radius:3px;
  display:grid;grid-template-columns:repeat(10,1fr);grid-template-rows:repeat(8,1fr);
  background-color:#b7c6ba;
  background-image:linear-gradient(#ffffff40 1px,transparent 1px),linear-gradient(90deg,#ffffff40 1px,transparent 1px);
  background-size:10% 12.5%;
}
.cell{border:0;background:transparent;padding:0;z-index:2;cursor:default}
.board:not(.placing) .cell{pointer-events:none}

.col-labels,.row-labels{position:absolute;display:flex;font:9px 'DM Mono',monospace;color:#d6ddd2;pointer-events:none}
.col-labels{left:16px;right:16px;justify-content:space-around}
.col-labels.top{top:4px}
.col-labels.bottom{bottom:4px}
.row-labels{top:15px;bottom:15px;flex-direction:column;justify-content:space-around}
.row-labels.left{left:5px}
.row-labels.right{right:5px}

/* ---------- gemmes ---------- */
.gem{position:absolute;z-index:3;pointer-events:none;filter:drop-shadow(3px 4px 2px #12203255);transition:filter .12s}
.gem svg{display:block;width:100%;height:100%;overflow:visible}
.gem .surface{fill:var(--color);stroke:#1b3448;stroke-opacity:.5;stroke-width:1.25;vector-effect:non-scaling-stroke}
.gem .grid-lines{fill:none;stroke:#f6f3dc;stroke-opacity:.8;stroke-width:1.2;stroke-linejoin:round;stroke-linecap:round;vector-effect:non-scaling-stroke}
.gem.red{--color:var(--red)}.gem.yellow{--color:var(--yellow)}.gem.blue{--color:var(--blue)}.gem.white{--color:var(--white)}

/* mode Recherche : gemmes manipulables (au-dessus des cases) */
.board.placing .gem{z-index:5;touch-action:none}
.board.placing .gem .surface{pointer-events:auto;cursor:grab}
.board.placing .gem .grid-lines{pointer-events:none}
.board.placing .gem.dragging{z-index:6;filter:drop-shadow(0 10px 16px #12203277)}
.board.placing .gem.dragging .surface{cursor:grabbing}

/* aperçu de pose (survol clavier/souris) */
.board.placing .cell.available:hover,
.board.placing .cell.available:focus-visible{background:#2c8e8020;box-shadow:inset 0 0 0 2px var(--teal)}
.placement-preview{opacity:.5;z-index:4!important;filter:drop-shadow(2px 3px 2px #12203255)!important}
.placement-preview .surface{stroke:#de9217!important;stroke-width:2!important}

/* gemme fantôme suivie au doigt (glissé depuis la palette) */
.drag-ghost{
  position:fixed;z-index:90;width:58px;height:58px;margin:-29px 0 0 -29px;
  pointer-events:none;filter:drop-shadow(0 8px 14px #1220324d);transition:opacity .12s;
}
.drag-ghost svg{width:100%;height:100%;overflow:visible}
.drag-ghost .surface{fill:var(--color);stroke:#274157;stroke-width:1.5;vector-effect:non-scaling-stroke}
.drag-ghost .grid-lines{fill:none;stroke:#fffde8;stroke-width:1.25;vector-effect:non-scaling-stroke}
.drag-ghost.red{--color:var(--red)}.drag-ghost.yellow{--color:var(--yellow)}.drag-ghost.blue{--color:var(--blue)}.drag-ghost.white{--color:var(--white)}

/* marques lignes / colonnes vides */
.empty-mark{position:absolute;z-index:4;pointer-events:none;background:repeating-linear-gradient(135deg,rgba(38,63,82,.32) 0 2px,rgba(255,255,255,.12) 2px 7px);box-shadow:inset 0 0 0 1px rgba(38,63,82,.4)}
.row-mark{left:0;width:100%}
.col-mark{top:0;height:100%}
.board.marking .cell{cursor:crosshair!important}
.board.marking .cell.mark-target:hover,
.board.marking .cell.mark-target:focus-visible{background:#294f6722;box-shadow:inset 0 0 0 2px #294f67}

/* ---------- barres d'action ---------- */
.dock{
  flex:none;display:flex;gap:10px;align-items:center;
  width:100%;max-width:480px;margin-inline:auto;
  padding:12px 16px;padding-bottom:max(12px,env(safe-area-inset-bottom));
}
.dock.sheet{
  max-width:640px;flex-direction:column;align-items:stretch;gap:9px;
  background:#fbf9f4;border-top:1px solid var(--line);border-radius:18px 18px 0 0;
  box-shadow:0 -8px 22px #1b2e4114;padding-top:12px;
}
.primary{
  flex:1;min-height:50px;border:0;border-radius:13px;padding:14px;
  background:linear-gradient(135deg,var(--amber),var(--amber2));
  font:600 14px Outfit;color:#263342;cursor:pointer;box-shadow:0 8px 18px #e9a73742;
}
.primary:active{transform:translateY(1px)}
.icon-btn{
  flex:none;width:50px;height:50px;border:1px solid var(--line);border-radius:13px;
  background:#fff;color:#c65b6a;font-size:22px;line-height:1;cursor:pointer;
  display:grid;place-items:center;transition:transform .15s,color .15s;
}
.icon-btn:active{transform:scale(.94)}
.icon-btn.saved{color:#e0384c;transform:scale(1.16)}

/* palette de gemmes */
.palette{display:grid;grid-template-columns:repeat(5,1fr);gap:7px}
.palette-piece{position:relative}
.piece-choice{
  width:100%;aspect-ratio:1;border:1px solid var(--line);border-radius:13px;background:#fff;
  padding:7px;cursor:grab;touch-action:none;display:grid;place-items:center;
  transition:border-color .12s,background .12s,box-shadow .12s,transform .1s;
}
.piece-choice:active{transform:scale(.95)}
.piece-choice svg{width:100%;height:100%;max-height:46px;overflow:visible;filter:drop-shadow(0 1px 1px #1a304544)}
.piece-choice .surface{fill:var(--color);stroke:#274157;stroke-width:1.5;vector-effect:non-scaling-stroke}
.piece-choice .grid-lines{fill:none;stroke:#fffde8;stroke-width:1.25;vector-effect:non-scaling-stroke}
.piece-choice.red{--color:var(--red)}.piece-choice.yellow{--color:var(--yellow)}.piece-choice.blue{--color:var(--blue)}.piece-choice.white{--color:var(--white)}
.piece-choice.selected{border-color:#e8a63a;background:#fdf0d6;box-shadow:0 0 0 2px #e8a63a inset}
.piece-choice.placed{opacity:.5}
.piece-choice.placed.selected{opacity:1}
.piece-choice.placed::after{
  content:"";position:absolute;right:5px;top:5px;width:7px;height:7px;border-radius:50%;
  background:var(--teal);opacity:.9;
}

.tool-hint{
  margin:0;text-align:center;font-size:10.5px;line-height:1.35;color:var(--muted);
}
.tool-row{display:grid;grid-template-columns:repeat(2,1fr);gap:7px}
.tool-row button{
  min-height:42px;border:1px solid var(--line);border-radius:11px;background:#f2f4f2;
  color:#556678;font:500 12px Outfit;padding:9px 6px;cursor:pointer;
}
.tool-row button:active{background:#e7eae7}
#mark-row.active,#mark-col.active{background:var(--navy);color:#fff;border-color:var(--navy)}

/* ---------- onglet grilles sauvées ---------- */
#panel-saved{padding:14px 16px;padding-bottom:max(16px,env(safe-area-inset-bottom));overflow-y:auto}
.saved-head{display:flex;justify-content:space-between;align-items:baseline;margin-bottom:14px}
.saved-head h2{margin:0;font-size:18px;letter-spacing:-.02em}
.text-button{border:0;background:transparent;color:var(--muted);font:12px Outfit;cursor:pointer}
.history{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:12px}
.history-card{display:flex;flex-direction:column;gap:9px;padding:11px;border:1px solid #e0e5df;border-radius:14px;background:#fafbf9}
.history-card .mini-board{
  position:relative;width:100%;aspect-ratio:10/8;border-radius:8px;overflow:hidden;
  background:#b7c6ba;
  background-image:linear-gradient(#ffffff44 1px,transparent 1px),linear-gradient(90deg,#ffffff44 1px,transparent 1px);
  background-size:10% 12.5%;
}
.history-card .mini-board .gem{filter:drop-shadow(1px 2px 1px #12203240)}
.history-card .mini-board .gem .surface{stroke-width:.9}
.history-card .mini-board .gem .grid-lines{stroke-width:.7}
.history-card .date{margin:0;font:9px 'DM Mono',monospace;color:#8190a0}
.history-card-body{display:flex;flex-direction:column;gap:7px}
.history-card-actions{display:flex;gap:14px}
.history-card-actions button{border:0;background:none;padding:0;font:12.5px Outfit;cursor:pointer;color:#3c6e8a}
.history-card-actions .delete{color:#9a7680}
.empty{grid-column:1/-1;margin:0;padding:40px 12px;text-align:center;color:#8290a0;font-size:13px}

/* ---------- notification éphémère ---------- */
.status{
  position:fixed;left:50%;bottom:calc(14px + env(safe-area-inset-bottom));transform:translate(-50%,12px);
  margin:0;max-width:82vw;padding:9px 16px;border-radius:999px;
  background:#1d344df2;color:#fff;font-size:12px;text-align:center;
  opacity:0;pointer-events:none;transition:opacity .25s,transform .25s;z-index:95;
}
.status.show{opacity:1;transform:translate(-50%,0)}

/* ---------- écrans larges (hors mobile en paysage) ---------- */
@media(min-width:820px) and (min-height:600px){
  .topbar{padding:14px clamp(16px,calc((100vw - 900px) / 2),40vw)}
  .tabs{justify-content:center;padding:8px 12px}
  .tab{flex:0 0 170px}
  .board{--bh:min(calc(100dvh - 210px),calc((100vw - 56px) * .46),58dvh)}
  .stage-head,#panel-saved{max-width:900px;width:100%;margin-inline:auto}
  .dock{max-width:600px}
  .dock.sheet{max-width:860px;flex-flow:row wrap;align-items:center;justify-content:center;border-radius:18px}
  .dock.sheet .palette{flex:0 1 auto;grid-template-columns:repeat(5,62px)}
  .dock.sheet .tool-hint{flex-basis:100%;order:-1}
  .dock.sheet .tool-row{flex:1;min-width:340px;grid-template-columns:repeat(4,1fr)}
  .history{grid-template-columns:repeat(auto-fill,minmax(172px,1fr))}
}

/* ---------- mobile en portrait : suggérer le paysage ---------- */
@media(orientation:portrait) and (hover:none) and (pointer:coarse){
  .rotate-hint{
    display:block;position:absolute;left:0;right:0;top:19%;z-index:1;
    margin:0;text-align:center;font-size:11.5px;letter-spacing:.02em;
    color:var(--muted);pointer-events:none;
  }
}

/* ---------- mobile en paysage : plateau plein cadre, contrôles en rail ---------- */
@media(orientation:landscape) and (max-height:600px){
  body{overflow:hidden}
  .topbar{padding:5px 14px;padding-top:max(5px,env(safe-area-inset-top))}
  .brand-mark{font-size:16px}
  .brand h1{font-size:12px;letter-spacing:.14em}
  .rules{display:none}
  .tabs{padding:4px 10px;gap:3px}
  .tab{min-height:30px;padding:6px 4px;font-size:11px}
  .rotate-hint{display:none}

  #panel-board{flex-direction:row;justify-content:flex-start;align-items:stretch;--rail:clamp(228px,33vw,326px)}
  .stage-head{display:none!important}
  .stage{
    flex:1;order:0;padding:6px;align-items:center;justify-content:center;
  }
  .board{
    --bh:min(calc(100dvh - 100px),calc((100vw - var(--rail) - 34px) / 1.25),100dvh);
    width:calc(var(--bh) * 1.25);
  }
  .board-frame{padding:11px 13px;border-radius:13px}

  .dock,.dock.sheet{
    order:1;flex:none;width:var(--rail);max-width:none;margin:0;
    flex-flow:column nowrap;align-items:stretch;justify-content:center;gap:9px;
    padding:12px 14px;padding-bottom:max(12px,env(safe-area-inset-bottom));
    border-top:0;border-left:1px solid var(--line);border-radius:0;
    background:#fbf9f4;box-shadow:none;overflow-y:auto;
  }
  #generate-tools{gap:12px}
  #generate-tools .primary{flex:0 0 auto;min-height:58px}
  #generate-tools .icon-btn{align-self:center;width:54px;height:54px}
  .dock.sheet .palette{grid-template-columns:repeat(3,1fr);gap:6px}
  .dock.sheet .piece-choice{padding:5px}
  .dock.sheet .piece-choice svg{max-height:38px}
  .dock.sheet .tool-hint{font-size:9.5px;line-height:1.3}
  .dock.sheet .tool-row{grid-template-columns:repeat(2,1fr);gap:6px}
  .dock.sheet .tool-row button{min-height:38px;font-size:11px;padding:7px 4px}

  #panel-saved{padding:10px 14px}
  .history{grid-template-columns:repeat(auto-fill,minmax(150px,1fr))}
}
