@font-face { font-family: "DM Mono"; font-weight: 300; font-display: swap; src: url(fonts/dm-mono-300.woff2) format("woff2"); }
@font-face { font-family: "DM Mono"; font-weight: 400; font-display: swap; src: url(fonts/dm-mono-400.woff2) format("woff2"); }
@font-face { font-family: "DM Mono"; font-weight: 500; font-display: swap; src: url(fonts/dm-mono-500.woff2) format("woff2"); }

@property --spent { syntax: "<percentage>"; inherits: true; initial-value: 0%; }

:root {
  --ground: #d4d4d4;
  --block: #acacac;
  --ink: #0b0b0b;
  --j: #00edb3;
  --r: #ff0a5f;
  --accent: var(--j);
  --hi: #f2f2f2;
  --lo: #a6a6a6;
  --gap: 2px;
  --gutter: 16px;
  --d: min(80vw, 40dvh);
  --vh: 100dvh;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  background: var(--ground);
}
body {
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--ground);
  color: var(--ink);
  font: 400 13px/1.35 "DM Mono", ui-monospace, Menlo, monospace;
  font-variant-numeric: tabular-nums;
}
[data-who="R"] { --accent: var(--r); }
[hidden] { display: none !important; }
button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 0;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
small { font-size: 11px; letter-spacing: .06em; }
i { font-style: normal; }

/* ---------- Accueil : l'objet en relief ---------- */
#home {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) var(--gutter) calc(env(safe-area-inset-bottom, 0px) + var(--gutter));
}
.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  min-height: 62px;
}
.clock { display: grid; font-weight: 300; font-size: 26px; line-height: 1.12; letter-spacing: -.01em; }
.pill {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 6px 0 16px;
  border-radius: 22px;
  letter-spacing: .06em;
  font-size: 11px;
  background: var(--ground);
  box-shadow: inset 2px 2px 5px var(--lo), inset -2px -2px 5px var(--hi);
}
.pill b {
  display: grid;
  place-items: center;
  min-width: 32px;
  height: 32px;
  border-radius: 16px;
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0;
  background: var(--ground);
  box-shadow: 2px 2px 5px var(--lo), -2px -2px 5px var(--hi);
}
.pill:active b { background: var(--accent); }

.instrument {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 2.4dvh, 22px);
  margin-top: 8px;
  padding: clamp(14px, 2.6dvh, 24px) 14px 14px;
  border-radius: 38px;
  background: var(--ground);
  box-shadow: 9px 9px 20px var(--lo), -9px -9px 20px var(--hi),
    inset 1px 1px 1px rgba(255, 255, 255, .55), inset -1px -1px 1px rgba(0, 0, 0, .05);
}

.well {
  position: relative;
  flex: none;
  width: var(--d);
  height: var(--d);
  border-radius: 50%;
  background: var(--ground);
  box-shadow: inset 5px 5px 12px var(--lo), inset -5px -5px 12px var(--hi);
}
/* L'anneau : la part consommée s'efface dans le sens des aiguilles. */
.ring {
  position: absolute;
  inset: 5%;
  border-radius: 50%;
  overflow: hidden;
  background:
    radial-gradient(circle at 26% 24%, #d9b3e6 0 14%, rgba(217, 179, 230, 0) 48%),
    radial-gradient(circle at 78% 72%, #12121c 0 16%, rgba(18, 18, 28, 0) 52%),
    conic-gradient(from 20deg, #c9a4e0, #5b57d6 32%, #15141f 56%, #2a2860 74%, #c9a4e0);
  -webkit-mask: conic-gradient(transparent var(--spent), #000 0);
  mask: conic-gradient(transparent var(--spent), #000 0);
  transition: --spent .5s cubic-bezier(.2, .7, .2, 1);
}
.ring::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url(grain.png) 0 0 / 120px;
  mix-blend-mode: overlay;
  opacity: .55;
}
.over .ring { background: var(--ink); -webkit-mask: none; mask: none; }

.ticks { position: absolute; inset: 0; }
.ticks i {
  position: absolute;
  left: 50%;
  top: 1.2%;
  width: 1px;
  height: 2.6%;
  margin-left: -.5px;
  background: var(--ink);
  transform-origin: 50% calc(var(--d) * .488);
  transform: rotate(var(--a));
}
.ticks i.now { width: 5px; margin-left: -2.5px; height: 3.2%; background: var(--ink); }

.hub {
  position: absolute;
  inset: 21%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border-radius: 50%;
  background: var(--ground);
  box-shadow: 5px 5px 12px rgba(0, 0, 0, .28), -3px -3px 9px rgba(255, 255, 255, .35),
    inset 1px 1px 1px rgba(255, 255, 255, .6);
}
.hub small { font-size: calc(var(--d) * .036); }
.big { font-weight: 300; font-size: calc(var(--d) * .155); line-height: 1.1; letter-spacing: -.03em; white-space: nowrap; }
.big.long { font-size: calc(var(--d) * .115); }
.big .dec { font-size: .46em; letter-spacing: 0; }

.caps { display: flex; gap: 8px; width: 100%; }
.cap {
  flex: 1;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 16px;
  border-radius: 22px;
  box-shadow: inset 2px 2px 5px var(--lo), inset -2px -2px 5px var(--hi);
  min-width: 0;
}
.cap span { font-size: 15px; white-space: nowrap; }
.cap.neg span { background: var(--ink); color: var(--ground); padding: 0 4px; margin-right: -4px; }

.slot {
  flex: none;
  display: flex;
  align-items: center;
  min-height: 58px;
  padding: 8px 0;
}
#note {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  width: 100%;
  padding: 0 2px;
  font-size: 12.5px;
  line-height: 1.32;
}
.slot .bar { width: 100%; }

/* ---------- Commandes : blocs francs, façon menu HUD ---------- */
.who { flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); height: clamp(88px, 19dvh, 170px); }

.block {
  position: relative;
  display: flex;
  align-items: flex-end;
  padding: 10px 12px;
  text-align: left;
  background: var(--block);
  letter-spacing: .02em;
}
.block:active { background: var(--accent); }
.who .block { font-size: 16px; }
.tag {
  display: inline-grid;
  place-items: center;
  height: 22px;
  padding: 0 5px;
  background: var(--accent);
  color: var(--ink);
  font-size: 12px;
  letter-spacing: 0;
}
.who .tag { position: absolute; top: 10px; left: 12px; }

.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding-left: 5px;
  background: var(--ink);
  color: var(--ground);
  font-size: 12px;
  letter-spacing: .03em;
}
.bar span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.x {
  position: relative;
  flex: none;
  width: 44px;
  height: 100%;
  color: var(--accent);
  font-size: 15px;
  font-weight: 500;
}
.x::after { content: ""; position: absolute; inset: -8px 0; } /* cible tactile de 48 px */
.x:active { background: var(--accent); color: var(--ink); }

/* ---------- Panneau qui se déplie ---------- */
#panel {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--vh);
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) var(--gutter) calc(env(safe-area-inset-bottom, 0px) + var(--gutter));
  background: var(--ground);
}
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }

.display { display: flex; align-items: flex-end; gap: 8px; flex: none; }
.frame {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  height: clamp(84px, 15dvh, 124px);
  padding: 0 14px;
  border: 2px solid var(--accent);
}
#amount { font-weight: 300; font-size: clamp(44px, 8.5dvh, 64px); letter-spacing: -.03em; white-space: nowrap; }
.seed { flex: none; width: 13px; height: 13px; background: var(--accent); animation: blink 1.1s steps(2, jump-none) infinite; }
.checker { flex: none; width: 25px; height: 25px; fill: var(--accent); outline: 1px solid var(--accent); }

.pad {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 1fr;
  gap: var(--gap);
}
.pad .block { font-size: clamp(22px, 3.6dvh, 28px); font-weight: 300; padding: 6px 10px; }
.pad .block.off { visibility: hidden; }

.go {
  flex: none;
  height: 60px;
  width: 100%;
  background: var(--ink);
  color: var(--ground);
  font-size: 15px;
  align-items: center;
}
.go::after {
  content: "";
  position: absolute;
  right: 16px;
  top: 50%;
  width: 13px;
  height: 13px;
  margin-top: -6.5px;
  background: var(--accent);
}
.go:active { background: var(--accent); color: var(--ink); }
.go:active::after { background: var(--ink); }
.go:disabled { background: var(--block); color: rgba(11, 11, 11, .45); cursor: default; }
.go:disabled::after { display: none; }
.shake { animation: shake .24s steps(4) both; }

.frame-label {
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 2px;
  height: 84px;
}
.frame-label small { font-size: 13px; }
#label {
  width: 100%;
  font: 300 24px/1.2 "DM Mono", ui-monospace, monospace;
  color: var(--ink);
  background: none;
  border: 0;
  border-radius: 0;
  outline: 0;
  caret-color: var(--accent);
  letter-spacing: -.01em;
}
#label::placeholder { color: rgba(11, 11, 11, .5); }

.sugg {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: minmax(58px, 1fr);
  align-content: start;
  gap: var(--gap);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
.sugg .block { font-size: 15px; overflow: hidden; }
.sugg .block span { line-height: 1.15; overflow-wrap: anywhere; }

#rows { list-style: none; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: grid; gap: var(--gap); align-content: start; }
#rows li {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding-left: 8px;
  background: var(--block);
}
#rows .what { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
#rows .when { font-size: 11px; }
#rows .amt { font-size: 15px; }
#rows .x { height: 52px; color: var(--ink); }
#rows .sure { background: var(--accent); }
#rows .sure .x { background: var(--ink); color: var(--accent); }

/* Le pas à pas : tout apparaît par à-coups, pas en fondu. */
.pop { animation: pop .1s steps(2) both; animation-delay: calc(var(--i, 0) * 16ms); }
@keyframes pop { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: none; } }
@keyframes blink { from { opacity: 1; } to { opacity: .15; } }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

@media (prefers-reduced-motion: reduce) {
  .pop, .seed, .shake { animation: none; }
  .ring { transition: none; }
}
@media (hover: hover) and (pointer: fine) {
  .block:not(.go):hover { background: #9f9f9f; }
  .block:active { background: var(--accent) !important; }
}
