:root {
  --wood-0: #120a06;
  --wood-1: #1f130c;
  --wood-2: #3a2416;
  --wood-3: #5e3b22;
  --parch-1: #f4e7c5;
  --parch-2: #e2cc98;
  --parch-3: #c8a96a;
  --ink: #2b1c11;
  --gold: #e0ac4c;
  --gold-dim: #9b7533;
  --candle: #ffb54a;
  --text: #f2e3c2;
  --muted: #c4ab83;
  --blood: #b8352a;
  --poison: #8fd14f;
  --ok: #8fc76a;
  --display: 'Cinzel', 'Trajan Pro', Georgia, serif;
  --body: 'IM Fell English', Georgia, 'Times New Roman', serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--body);
  color: var(--text);
  font-size: 17px;
  background: #0b0603;
  overflow: hidden;
}
.hidden { display: none !important; }
.center { text-align: center; justify-content: center; }
.muted { color: var(--muted); }

/* ----- Scène 3D en fond ----- */
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; touch-action: none; }
#app { position: fixed; inset: 0; z-index: 1; overflow-y: auto; }
#app.in-game { overflow: hidden; pointer-events: none; }

.loader { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: #0b0603; transition: opacity .8s; }
.loader.done { opacity: 0; pointer-events: none; }
.loader-box { text-align: center; padding: 16px; }
.loader-title { font-family: var(--display); font-weight: 900; font-size: 2rem; color: var(--gold); text-shadow: 0 0 24px rgba(255,180,80,.4); animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .55; } }

/* ----- Éléments communs ----- */
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: .04em; margin: 0 0 .6em; }
h2 { font-size: 1.1rem; color: var(--gold); }
h3 { font-size: .9rem; color: var(--gold); }

.panel {
  background: linear-gradient(180deg, rgba(48, 29, 17, .86), rgba(22, 13, 8, .9));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(224, 172, 76, .28);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,220,160,.08);
}

.btn {
  font-family: var(--display); font-weight: 700; font-size: .92rem; letter-spacing: .05em;
  color: var(--text); cursor: pointer;
  padding: 11px 18px; border-radius: 10px;
  border: 1px solid rgba(224, 172, 76, .45);
  background: linear-gradient(180deg, var(--wood-3), var(--wood-2));
  box-shadow: 0 3px 0 var(--wood-0), inset 0 1px 0 rgba(255,220,160,.15);
  transition: transform .08s, filter .15s, opacity .15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.15); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--wood-0); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, #d79a3c, #9b6420); color: #1d1005; border-color: #f1c779; }
.btn.danger { background: linear-gradient(180deg, #c9443a, #7c1d16); border-color: #ef8a7c; }
.btn.ghost { background: rgba(15, 8, 4, .55); box-shadow: none; }
.btn.small { padding: 7px 12px; font-size: .78rem; }
.btn.wide { width: 100%; }
.btn.on { border-color: var(--candle); color: var(--candle); }
.grow { flex: 1; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; cursor: pointer;
  background: rgba(15, 8, 4, .55); color: var(--gold); border: 1px solid rgba(224,172,76,.4); font-size: 1rem;
}
.icon-btn.off { opacity: .4; text-decoration: line-through; }
.row { display: flex; gap: 10px; align-items: center; margin-top: 12px; flex-wrap: wrap; }

input, select {
  font-family: var(--body); font-size: 1.05rem; color: var(--ink);
  background: linear-gradient(180deg, var(--parch-1), var(--parch-2));
  border: 1px solid var(--parch-3); border-radius: 8px; padding: 10px 12px; min-width: 0;
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--candle); outline-offset: 2px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span { font-family: var(--display); font-size: .8rem; color: var(--muted); letter-spacing: .08em; }
.code-input { width: 120px; text-transform: uppercase; letter-spacing: .3em; font-family: var(--display); font-weight: 700; text-align: center; }

/* ----- Accueil ----- */
.screen:not(.hud) { padding: 16px; max-width: 1000px; margin: 0 auto; }
.sign { display: flex; flex-direction: column; align-items: center; margin: 18px 0 26px; }
.sign-board {
  text-align: center; padding: 22px 34px; border-radius: 16px;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,.18) 0 1px, transparent 1px 9px),
    linear-gradient(180deg, rgba(107, 68, 38, .95), rgba(63, 39, 21, .95));
  border: 3px solid #2a190d;
  box-shadow: 0 0 0 2px var(--gold-dim) inset, 0 14px 40px rgba(0,0,0,.7), 0 0 80px rgba(255,170,60,.15);
}
.sign-board h1 {
  font-size: clamp(1.9rem, 6vw, 3.3rem); font-weight: 900; margin: 0;
  color: var(--gold);
  text-shadow: 0 2px 0 #2a190d, 0 0 22px rgba(255, 180, 80, .45);
}
.sign-board p { margin: 8px 0 0; font-style: italic; color: var(--parch-2); }

.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; }
.rules { grid-column: 1 / -1; }
.rules summary { font-family: var(--display); color: var(--gold); cursor: pointer; font-weight: 700; }
.rules ul { margin: 12px 0 0; padding-left: 20px; line-height: 1.5; }
.rules li { margin-bottom: 6px; }

.lobby-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow-y: auto; }
.lobby-list li {
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  padding: 10px 12px; border-radius: 10px; background: rgba(0,0,0,.3); border: 1px solid rgba(224,172,76,.12);
}
.lobby-list .lcode { font-family: var(--display); font-weight: 900; color: var(--gold); letter-spacing: .15em; }
.lobby-list .lnames { flex: 1; font-size: .9rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lobby-list .empty { justify-content: center; color: var(--muted); font-style: italic; background: none; border-style: dashed; }

/* ----- Salle d'attente ----- */
.lobby-panel { max-width: 440px; margin: 20px 0 20px auto; }
.big-code {
  font-family: var(--display); font-weight: 900; text-align: center;
  font-size: 3.4rem; letter-spacing: .3em; padding-left: .3em; color: var(--gold);
  text-shadow: 0 0 24px rgba(255,180,80,.4); margin: 4px 0 8px;
}
.seat-list { list-style: none; padding: 0; margin: 0 0 8px; display: flex; flex-direction: column; gap: 8px; }
.seat-list li { display: flex; align-items: center; gap: 12px; padding: 8px 10px; background: rgba(0,0,0,.3); border-radius: 10px; }
.seat-list .sname { flex: 1; }
.seat-list .empty-seat { color: var(--muted); font-style: italic; border: 1px dashed rgba(224,172,76,.2); background: none; }
.badge {
  font-family: var(--display); font-size: .65rem; letter-spacing: .08em; padding: 3px 7px; border-radius: 999px;
  background: rgba(224,172,76,.18); color: var(--gold); border: 1px solid rgba(224,172,76,.3);
}
.badge.bot { background: rgba(140,160,190,.15); color: #b8c6dc; border-color: rgba(140,160,190,.3); }
.remove { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1.1rem; }
.remove:hover { color: var(--blood); }
.avatar {
  width: 34px; height: 34px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--display); font-weight: 900; font-size: .95rem; color: #1d1005;
  background: radial-gradient(circle at 35% 30%, var(--parch-1), var(--parch-3));
  border: 2px solid var(--gold-dim);
}
.avatar.bot { background: radial-gradient(circle at 35% 30%, #c8d3e2, #6f7f97); }

/* ----- Interface de jeu (HUD) ----- */
.hud { position: absolute; inset: 0; pointer-events: none; }
.hud button, .hud .journal, .hud .overlay { pointer-events: auto; }
.hud-top {
  position: absolute; top: 0; left: 0; right: 0; padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
}
.tags { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tag {
  font-family: var(--display); font-size: .78rem; letter-spacing: .06em; padding: 6px 10px; border-radius: 8px;
  background: rgba(10, 5, 2, .6); border: 1px solid rgba(224,172,76,.22);
}
.tag b { color: var(--gold); letter-spacing: .15em; }

.hud-status {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  width: min(560px, calc(100% - 32px)); display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.table-rank { border-color: var(--gold-dim); }
.table-rank:empty { display: none; }
.table-rank b { color: var(--gold); letter-spacing: .06em; }
.status {
  font-size: 1.12rem; text-align: center; min-height: 1.5em;
  text-shadow: 0 2px 6px #000, 0 0 12px rgba(0,0,0,.9);
}
.status b { color: var(--gold); font-family: var(--display); }
.status.myturn { color: var(--candle); }
.timer { width: min(320px, 80%); height: 4px; border-radius: 3px; background: rgba(0,0,0,.55); overflow: hidden; visibility: hidden; }
.timer.on { visibility: visible; }
#timer-fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--blood), var(--candle)); transform-origin: left; }

.banner {
  position: absolute; left: 50%; top: 32%; transform: translate(-50%, -50%);
  text-align: center; padding: 14px 28px; border-radius: 14px; width: max-content; max-width: calc(100% - 32px);
  background: radial-gradient(ellipse at center, rgba(10, 5, 2, .8), rgba(10, 5, 2, .5) 70%, transparent);
  animation: bannerIn .35s ease-out;
}
@keyframes bannerIn { from { transform: translate(-50%, -50%) scale(.8); opacity: 0; } }
.b-title { font-family: var(--display); font-weight: 900; font-size: clamp(1.4rem, 4.5vw, 2.4rem); color: var(--gold); text-shadow: 0 0 22px rgba(255,170,60,.5), 0 2px 0 #000; }
.b-sub { margin-top: 4px; color: var(--parch-1); font-style: italic; text-shadow: 0 2px 6px #000; }
.banner.accuse .b-title { color: #ff7a63; text-shadow: 0 0 22px rgba(255, 80, 60, .6), 0 2px 0 #000; }
.banner.bad .b-title { color: var(--poison); text-shadow: 0 0 24px rgba(143, 209, 79, .6), 0 2px 0 #000; }
.banner.good .b-title { color: var(--ok); }

.hud-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 0 16px max(14px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.my-info { font-family: var(--display); font-size: .75rem; letter-spacing: .08em; color: var(--muted); text-shadow: 0 1px 4px #000; }
.actions { display: flex; gap: 14px; }
.actions .btn { min-width: 160px; font-size: 1rem; padding: 13px 20px; }
.btn.danger:not(:disabled) { animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 3px 0 var(--wood-0), 0 0 22px rgba(220, 70, 50, .6); } }

.journal {
  position: absolute; right: 16px; top: 60px; width: 290px; max-height: calc(100% - 220px);
  display: flex; flex-direction: column; padding: 14px;
}
.journal ol { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; font-size: .9rem; line-height: 1.35; }
.journal li { padding: 6px 8px; border-left: 2px solid rgba(224,172,76,.25); background: rgba(0,0,0,.2); border-radius: 0 6px 6px 0; }
.journal li.round { border-color: var(--gold); color: var(--gold); font-family: var(--display); font-size: .76rem; }
.journal li.accuse { border-color: #ff7a63; color: #ffb3a6; }
.journal li.bad { border-color: var(--blood); color: #f0a093; }
.journal li.good { border-color: var(--ok); color: #cfe8bd; }
.journal li.warn { border-color: #c9a227; color: #e8d38a; font-style: italic; }
.journal li.big { border-color: var(--candle); color: var(--candle); font-weight: bold; }

.flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; background: radial-gradient(circle, rgba(120, 220, 60, .15), rgba(30, 80, 10, .85)); }
.flash.go { animation: poisonFlash 2.6s ease-out; }
@keyframes poisonFlash { 0% { opacity: 0; } 15% { opacity: 1; } 100% { opacity: 0; } }

/* ----- Fin de partie ----- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at center, rgba(20, 10, 4, .45), rgba(0,0,0,.8));
  animation: fadein .5s 1s backwards;
}
@keyframes fadein { from { opacity: 0; } }
.ov-box {
  max-width: 460px; width: 100%; text-align: center; padding: 26px 24px; border-radius: 18px;
  background: linear-gradient(180deg, rgba(58,36,22,.97), rgba(25,15,9,.98));
  border: 1px solid var(--gold-dim); box-shadow: 0 20px 60px rgba(0,0,0,.8), 0 0 60px rgba(255,170,60,.12);
}
.ov-kicker { font-family: var(--display); font-size: .75rem; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); margin: 0; }
.ov-title { font-family: var(--display); font-weight: 900; font-size: 1.6rem; margin: 10px 0 6px; color: var(--gold); }
.over-poison { display: flex; flex-direction: column; gap: 6px; margin: 16px 0 4px; text-align: left; }
.over-poison .line { display: flex; align-items: center; gap: 10px; font-size: .95rem; }
.over-poison .line .pn { flex: 1; }
.over-poison .line.win .pn { color: var(--gold); font-weight: bold; }
.over-poison .cups { font-family: var(--display); letter-spacing: .25em; }
.over-poison .cups .p { color: var(--poison); }
.over-poison .cups .d { opacity: .35; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); z-index: 80;
  background: #2a0f0b; border: 1px solid var(--blood); color: #ffd2c9; padding: 10px 18px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: .25s; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.info { background: #241a0c; border-color: var(--gold-dim); color: var(--parch-1); }
.conn { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 90; background: #2a0f0b; color: #ffd2c9; padding: 6px 14px; border-radius: 8px; border: 1px solid var(--blood); font-size: .9rem; }

@media (max-width: 760px) {
  .lobby-panel { margin: 20px auto; }
  .journal { left: 16px; right: 16px; width: auto; top: auto; bottom: 150px; max-height: 40%; }
}
@media (max-width: 640px) {
  body { font-size: 16px; }
  .hud-top { padding: 10px 16px; }
  .hud-top { flex-direction: column-reverse; align-items: stretch; gap: 8px; }
  .hud-top .tags { flex-wrap: nowrap; }
  .hud-top .tags:last-child { justify-content: flex-end; }
  #g-round { display: none; }
  .hud-top .tag { font-size: .7rem; padding: 5px 8px; }
  .hud-top .btn.small { padding: 6px 9px; font-size: .7rem; }
  .hud-status { top: 92px; }
  .status { font-size: .98rem; }
  .actions { width: 100%; }
  .actions .btn { min-width: 0; flex: 1; padding: 12px 10px; }
  .big-code { font-size: 2.6rem; }
}

/* Sélecteur de langue */
select.lang-sel {
  font-family: var(--display); font-size: .78rem; padding: 6px 8px; cursor: pointer;
  background: rgba(15, 8, 4, .7); color: var(--gold); border: 1px solid rgba(224,172,76,.4); border-radius: 18px;
}
select.lang-sel option { color: #222; background: #f2e3c2; }
.lang-float { position: fixed; top: 12px; right: 12px; z-index: 60; }
body.in-game .lang-float { display: none; }
@media (max-width: 640px) {
  .hud-top select.lang-sel { padding: 5px 6px; font-size: .7rem; }
}
