:root {
  --bg: #07080e;
  --metal: #1a1c26;
  --edge: #3a3e4e;
  --amber: #ffb030;
  --cyan: #37e4ff;
  --ink: #e8ecf6;
  --dim: #99a1b6;
  --display: "Arial Black", "Segoe UI Black", Impact, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%;
  background:
    radial-gradient(1100px 700px at 50% -10%, #1d2448 0%, transparent 70%),
    radial-gradient(800px 600px at 90% 110%, #2a1238 0%, transparent 70%),
    var(--bg);
  color: var(--ink);
  font: 15px/1.45 "Segoe UI", system-ui, Arial, sans-serif;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}

#app {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(210px, 1fr) auto minmax(210px, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 14px;
  padding: 12px 18px;
  align-items: stretch;
}

/* ---- fronton ---- */
#backbox { display: flex; flex-direction: column; gap: 12px; min-width: 0; justify-content: center; }
#backglass {
  width: 100%; flex: 1 1 auto; min-height: 0; max-height: 62vh; display: block;
  border-radius: 12px;
  border: 3px solid var(--edge);
  box-shadow: 0 0 40px rgba(55, 140, 255, .35), inset 0 0 0 1px #000;
}
.dmdframe {
  padding: 8px; border-radius: 10px;
  background: linear-gradient(#2b2e3b, #101118);
  border: 1px solid var(--edge);
  box-shadow: 0 8px 26px rgba(0, 0, 0, .6);
}
#dmd { display: block; width: 100%; aspect-ratio: 4 / 1; border-radius: 3px; background: #100703; filter: drop-shadow(0 0 5px rgba(255, 130, 30, .55)); }
#mobilebar { display: none; }

/* ---- table ---- */
#cabinet { position: relative; display: flex; min-height: 0; justify-content: center; }
#tablewrap {
  height: 100%; width: min(84vh, 54vw);
  display: flex; align-items: flex-end; justify-content: center;
  perspective: 2800px; perspective-origin: 50% 20%;
}
#table {
  display: block; flex: none;
  transform-origin: 50% 100%;
  transform: rotateX(40deg);
  border-radius: 10px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, .8);
}
.flat #table { transform: none; }
.flat #tablewrap { align-items: center; }

#btnPlunge {
  display: none; position: absolute; right: 6px; bottom: 10px;
  width: 92px; height: 92px; border-radius: 50%;
  font: 13px var(--display); color: #2a1500;
  background: radial-gradient(circle at 35% 30%, #fff0c0, var(--amber) 55%, #a85500);
  border: 3px solid #fff3; box-shadow: 0 6px 22px #0009;
  touch-action: none;
}
#btnPlunge.ready { animation: pulse 0.9s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 34px var(--amber); } }

/* ---- colonne droite ---- */
#side { display: flex; flex-direction: column; gap: 12px; justify-content: center; min-width: 0; }
.panel {
  background: linear-gradient(#171923, #0e0f17);
  border: 1px solid #2b2e3b; border-radius: 12px; padding: 12px 16px;
}
.panel h2 { margin: 0 0 8px; font: 15px var(--display); letter-spacing: .04em; color: var(--amber); }
#scores { list-style: none; counter-reset: r; margin: 0; padding: 0; font-variant-numeric: tabular-nums; }
#scores li {
  counter-increment: r; display: flex; gap: 8px; padding: 3px 4px; border-bottom: 1px solid #ffffff10;
  align-items: baseline;
}
#scores li::before { content: counter(r); width: 1.5em; color: var(--dim); text-align: right; }
#scores .n { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#scores .s { color: var(--cyan); }
#scores li.me { background: #ffb03026; border-radius: 5px; }
.note { margin: 8px 0 0; color: var(--dim); font-size: 12px; }

.keys dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 5px 10px; align-items: center; font-size: 13px; }
.keys dt { white-space: nowrap; }
.keys dd { margin: 0; color: var(--dim); }
kbd {
  display: inline-block; min-width: 22px; padding: 1px 6px; text-align: center;
  background: #262935; border: 1px solid #454a5c; border-bottom-width: 2px; border-radius: 5px;
  font: 12px "Segoe UI", sans-serif; color: var(--ink);
}
.switches { display: flex; flex-wrap: wrap; gap: 6px; }
.switches button {
  flex: 1 1 auto; padding: 7px 10px; font: 600 13px "Segoe UI", sans-serif; color: var(--ink);
  background: #22252f; border: 1px solid #454a5c; border-radius: 8px; cursor: pointer;
}
.switches button:hover { background: #2e3240; }
.switches button.off { color: #7b8194; text-decoration: line-through; background: #14151c; }

/* ---- écrans ---- */
#overlay {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: rgba(3, 4, 10, .6); backdrop-filter: blur(3px); z-index: 10;
}
.card {
  width: min(420px, 92vw); text-align: center; padding: 26px 28px;
  background: linear-gradient(#1b1e2b, #0e0f17);
  border: 1px solid #40455a; border-radius: 16px;
  box-shadow: 0 30px 90px #000c, 0 0 50px rgba(55, 140, 255, .22);
}
.card.wide { width: min(600px, 94vw); text-align: left; }
.card h1 { margin: 0 0 10px; font: 44px/1.05 var(--display); color: var(--amber); }
.card h1 small { display: block; font-size: 20px; color: var(--cyan); }
.card h2 { margin: 0 0 12px; font: 20px var(--display); color: var(--amber); }
.card p { color: #c6cce0; }
.card ul { padding-left: 20px; margin: 0 0 16px; }
.card li { margin: 5px 0; }
.hint { font-size: 12px; color: var(--dim) !important; margin-bottom: 0; }
#final { font: 40px var(--display); color: var(--cyan); margin: 2px 0 14px; font-variant-numeric: tabular-nums; }
button.primary {
  appearance: none; border: 0; border-radius: 10px; padding: 12px 34px; cursor: pointer;
  font: 17px var(--display); color: #2a1500;
  background: linear-gradient(#ffd27a, var(--amber) 60%, #d97a10);
  box-shadow: 0 6px 18px rgba(255, 160, 40, .4);
}
button.primary:hover { filter: brightness(1.08); }
button.primary:focus-visible, .switches button:focus-visible, input:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
#hsForm { display: grid; gap: 8px; }
#hsForm label { font-weight: 700; color: var(--dim); font-size: 13px; }
#hsForm input {
  padding: 11px; text-align: center; font: 22px var(--display); letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink); background: #0b0c13; border: 1px solid #454a5c; border-radius: 9px;
  -webkit-user-select: text; user-select: text;
}

/* ---- écrans moyens : on retire la colonne droite sous la table ---- */
@media (max-width: 1100px) {
  #app { grid-template-columns: minmax(200px, 1fr) auto; }
  #side { display: none; }
  #tablewrap { width: min(84vh, 64vw); }
  #btnPlunge { display: block; }
}

/* ---- téléphone ou tablette en portrait ---- */
@media (max-width: 760px), (orientation: portrait) and (max-width: 900px) {
  #app { display: flex; flex-direction: column; gap: 6px; padding: 6px; }
  #backbox { flex: none; }
  #backglass { display: none; }
  .dmdframe { padding: 4px; }
  #cabinet { flex: 1 1 auto; }
  #tablewrap { width: 100%; }
  #table { transform: none; }
  #tablewrap { align-items: center; }
  #btnPlunge { width: 78px; height: 78px; right: 2px; bottom: 4px; }
}

/* ---- grands écrans tactiles : le bouton de lancement reste disponible ---- */
@media (pointer: coarse) {
  #btnPlunge { display: block; }
}

/* ---- mode zoom : la caméra suit la bille ---- */
.follow #tablewrap {
  display: block; position: relative; overflow: hidden;
  width: min(118vh, 60vw);
  perspective: 1500px; perspective-origin: 50% 50%;
  border-radius: 12px; border: 2px solid var(--edge);
  background: #05060b;
}
.follow #table { position: absolute; left: 0; top: 0; border-radius: 0; box-shadow: none; will-change: transform; }
#btnFollow {
  position: absolute; top: 8px; right: 8px; z-index: 3;
  padding: 7px 12px; font: 600 13px "Segoe UI", sans-serif; color: var(--ink);
  background: rgba(20, 22, 32, .82); border: 1px solid #5a6074; border-radius: 8px; cursor: pointer;
}
#btnFollow:hover { background: #2e3240; }
#btnFollow.active { color: #2a1500; background: var(--amber); border-color: #ffd27a; }
@media (max-width: 1100px) { .follow #tablewrap { width: min(118vh, 70vw); } }
@media (max-width: 760px), (orientation: portrait) and (max-width: 900px) { .follow #tablewrap { width: 100%; } }
