* { box-sizing: border-box; }
:root {
  --bg: #fff4e8; --panel: #fff; --ink: #4b3a30; --muted: #a08f80;
  --coral: #ff7a59; --teal: #2a9d8f; --gold: #ffc23d;
  --c1: #fdf0e1; --c2: #f9e6d0; --line: #f0dcc4; --shadow: 0 3px 0 #f0dcc4;
  --cs: min(calc((100dvh - 300px) / 7), calc(44vw / 7), 96px);
}
@media (orientation: portrait) {
  :root { --cs: min(calc((100vw - 90px) / 7), calc((100dvh - 720px) / 7), 96px); }
}
html { touch-action: manipulation; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font-family: 'Fredoka', ui-rounded, system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

#app {
  height: 100dvh; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
header { display: flex; align-items: center; gap: 10px; padding: 10px 14px; }
.title { margin-right: auto; font-weight: 600; font-size: 22px; }
.pill {
  display: flex; align-items: center; gap: 6px; background: #fff; border-radius: 999px;
  padding: 6px 14px; box-shadow: var(--shadow); font-size: 18px;
}
.pill b { font-weight: 600; }
.pill small { color: var(--muted); font-size: 13px; }
.pill.bump { animation: bump .45s; }
@keyframes bump { 50% { transform: scale(1.25); } }

main { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr auto; gap: 14px; padding: 0 14px 14px; }
@media (orientation: portrait) {
  main { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .boardPanel { justify-self: center; }
}
.roomPanel, .boardPanel { background: var(--panel); border-radius: 24px; box-shadow: var(--shadow); padding: 12px; min-height: 0; min-width: 0; }

/* Pièce */
.roomPanel { display: flex; flex-direction: column; gap: 10px; }
.roomHead { display: flex; align-items: center; gap: 10px; }
.roomHead h2 { margin: 0; font-size: 20px; font-weight: 600; }
.prog { flex: 1; height: 10px; background: var(--c2); border-radius: 99px; overflow: hidden; }
#progBar { height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--coral)); border-radius: 99px; transition: width .8s; }
#progTxt { color: var(--muted); font-size: 15px; }
.peek { background: var(--c1); border-radius: 99px; padding: 6px 12px; font-size: 15px; }
.peek[hidden] { display: none; }
.roomView { flex: 1; min-height: 0; border-radius: 16px; overflow: hidden; background: #efe5d8; }
.roomView svg { display: block; width: 100%; height: 100%; }
#room g.a { opacity: 0; transition: opacity 1s ease; }
#room g.b { transition: opacity 1s ease; }
#room g.a.on { opacity: 1; }
#room g.b.off { opacity: 0; }
#room.peek g.a { opacity: 0; transition-duration: .25s; }
#room.peek g.b { opacity: 1; transition-duration: .25s; }
#room.instant g { transition: none; }

.tasks { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 2px 4px; }
.tasks::-webkit-scrollbar { display: none; }
.task {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px; background: var(--c1);
  border-radius: 16px; padding: 8px 12px; border: 2px solid transparent; box-shadow: var(--shadow);
}
.task .ti { font-size: 24px; }
.task .tn { font-size: 15px; text-align: left; max-width: 8.5em; line-height: 1.1; }
.task .tc { font-weight: 600; background: #fff; border-radius: 99px; padding: 3px 8px; font-size: 14px; white-space: nowrap; }
.task.can { border-color: var(--coral); background: #fff3ee; animation: glow 1.6s infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 5px rgba(255,122,89,.2); } }
.alldone { padding: 10px; font-weight: 600; color: var(--teal); }

/* Plateau */
.boardPanel { display: flex; flex-direction: column; gap: 10px; width: calc(var(--cs) * 7 + 64px); }
.orders { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.order {
  background: var(--c1); border-radius: 16px; padding: 8px 6px; display: flex; flex-direction: column;
  align-items: center; gap: 5px; min-width: 0; border: 2px solid transparent;
}
.order.ready { border-color: var(--teal); background: #eaf7f4; }
.order.new { animation: slideIn .45s cubic-bezier(.2,.9,.3,1.2); }
@keyframes slideIn { from { transform: translateY(-14px) scale(.9); opacity: 0; } }
.who { display: flex; align-items: center; gap: 5px; max-width: 100%; }
.av { font-size: 20px; }
.nm { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.need { display: flex; gap: 5px; }
.ni { font-size: 26px; width: 42px; height: 42px; display: grid; place-items: center; background: #fff; border-radius: 12px; position: relative; }
.ni.ok::after, .cell.want::after {
  content: '✓'; position: absolute; width: 17px; height: 17px; border-radius: 50%;
  background: var(--teal); color: #fff; font-size: 11px; display: grid; place-items: center; font-weight: 700;
}
.ni.ok::after { right: -4px; bottom: -4px; }
.rw { font-size: 13px; color: var(--muted); height: 28px; display: flex; align-items: center; }
.deliver { background: var(--teal); color: #fff; border-radius: 99px; padding: 0 16px; font-weight: 600; font-size: 14px; height: 28px; animation: bump 1.2s infinite; }

.board {
  display: grid; grid-template-columns: repeat(7, var(--cs)); grid-auto-rows: var(--cs); gap: 4px;
  padding: 8px; background: #f3dfc6; border-radius: 18px; touch-action: none; justify-content: center;
}
.cell {
  border-radius: 12px; background: var(--c1); display: grid; place-items: center; position: relative;
  font-size: calc(var(--cs) * .6); line-height: 1; transition: transform .12s;
}
.cell.alt { background: var(--c2); }
.cell .e { display: block; pointer-events: none; filter: drop-shadow(0 2px 0 rgba(0,0,0,.08)); }
.cell.gen { background: radial-gradient(circle at 50% 40%, #fff7d6, #ffe39a); box-shadow: inset 0 0 0 3px #ffd36b; }
.cell.sel { box-shadow: inset 0 0 0 3px var(--coral); }
.cell.want::after { right: 3px; top: 3px; }
.cell.max::before { content: '★'; position: absolute; left: 4px; top: 3px; font-size: 12px; color: var(--gold); }
.cell.lifted .e { opacity: .25; }
.cell.match { box-shadow: inset 0 0 0 3px var(--gold); background: #fff6d8; }
.cell.over { transform: scale(1.08); }
.cell.hint .e { animation: wiggle 1.2s infinite; }
@keyframes wiggle { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }

.info { min-height: 46px; display: flex; align-items: center; gap: 8px; padding: 0 6px; font-size: 15px; line-height: 1.25; }
.info b { font-weight: 600; }
.chain { display: inline-flex; gap: 3px; margin-left: auto; font-size: 18px; flex: 0 0 auto; }
.chain span { opacity: .3; }
.chain span.cur { opacity: 1; }

/* Effets */
.ghost { position: fixed; left: 0; top: 0; z-index: 60; pointer-events: none; font-size: calc(var(--cs) * .7); line-height: 1; }
.fly { position: fixed; left: 0; top: 0; z-index: 60; pointer-events: none; font-size: 38px; line-height: 1; }
#toast {
  position: fixed; left: 50%; bottom: 30px; transform: translate(-50%, 40px); background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 99px; opacity: 0; transition: .3s; z-index: 80; font-size: 16px;
  pointer-events: none; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.modal { position: fixed; inset: 0; background: rgba(75,58,48,.35); display: grid; place-items: center; z-index: 90; padding: 16px; }
.modal.hidden { display: none; }
.modal .card { background: #fff; border-radius: 24px; padding: 22px; max-width: 380px; width: 100%; text-align: center; animation: slideIn .35s; }
.card h3 { margin: 6px 0 8px; font-size: 22px; font-weight: 600; }
.card p { margin: 0 0 14px; color: var(--muted); line-height: 1.35; }
.card .big { font-size: 54px; }
.btn { display: block; width: 100%; background: var(--coral); color: #fff; border-radius: 14px; padding: 12px; font-weight: 600; margin-top: 8px; font-size: 17px; }
.btn.ghost { background: var(--c1); color: var(--ink); }
.btn.danger { background: #fff0ec; color: #d0482a; }
.btn:disabled { opacity: .4; }
