:root {
  color-scheme: dark;
  --bg: #101820;
  --ink: #f5f7f4;
  --muted: #aeb8ad;
  --line: rgba(255,255,255,.16);
  --panel: rgba(16,24,32,.88);
  --accent: #f7c948;
  --good: #39d98a;
  --bad: #ff5a5f;
  --blue: #45aaf2;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button, input {
  font: inherit;
}

button {
  border: 0;
  min-height: 48px;
  border-radius: 8px;
  padding: 0 16px;
  color: var(--ink);
  background: rgba(255,255,255,.12);
  touch-action: manipulation;
}

button:active { transform: translateY(1px); }

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: rgba(255,255,255,.08);
  text-transform: uppercase;
}

fieldset {
  margin: 0;
  border: 0;
  padding: 0;
}

.app {
  min-height: 100dvh;
  background:
    linear-gradient(140deg, rgba(57,217,138,.14), transparent 42%),
    linear-gradient(330deg, rgba(247,201,72,.14), transparent 38%),
    #101820;
}

.screen {
  display: none;
  min-height: 100dvh;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
}

.screen.active {
  display: flex;
  flex-direction: column;
}

#home {
  position: relative;
}

.brand {
  margin-top: 6dvh;
}

.mark {
  display: inline-grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background: var(--accent);
  color: #101820;
  font-weight: 900;
}

h1, h2, p { margin: 0; }

h1 {
  margin-top: 14px;
  font-size: clamp(34px, 10vw, 48px);
  line-height: 1;
}

h2 {
  font-size: 24px;
  line-height: 1.1;
}

.duel {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  margin: 22px 0 0;
}

.duel-card {
  display: grid;
  gap: 6px;
  place-items: center;
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.08);
  font-weight: 900;
}

.wolf-card {
  background: linear-gradient(180deg, rgba(255,90,95,.16), rgba(255,255,255,.08));
}

.sheep-card {
  background: linear-gradient(180deg, rgba(57,217,138,.16), rgba(255,255,255,.08));
}

.duel-icon {
  font-size: 46px;
  line-height: 1;
}

.versus {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  color: #101820;
  background: var(--accent);
  font-size: 13px;
  font-weight: 900;
}

.panel {
  margin-top: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--panel);
  backdrop-filter: blur(16px);
}

.center {
  margin: auto 0;
  text-align: center;
}

.center p {
  margin: 12px 0 20px;
  color: var(--muted);
}

.field span,
.label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.actions {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.duration-field {
  margin-top: 16px;
}

.duration-field legend {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.duration-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.duration-options label {
  min-width: 0;
}

.duration-options input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.duration-options span {
  display: grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 6px;
  background: rgba(255,255,255,.08);
  color: var(--ink);
  font-weight: 800;
  text-align: center;
}

.duration-options input:checked + span {
  border-color: var(--accent);
  background: var(--accent);
  color: #101820;
}

.join-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.primary {
  background: var(--accent);
  color: #101820;
  font-weight: 800;
}

.install-button {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  right: 18px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  min-height: 42px;
  padding: 0 12px;
  color: var(--accent);
  background: rgba(247,201,72,.1);
  font-weight: 800;
}

.install-button[hidden] {
  display: none;
}

.install-button span[aria-hidden="true"] {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 8px;
  color: #101820;
  background: var(--accent);
  font-size: 17px;
  line-height: 1;
}

.danger {
  display: none;
  background: var(--bad);
  font-weight: 800;
}

.abandon-button {
  border: 1px solid rgba(255,90,95,.5);
  color: var(--ink);
  background: rgba(255,90,95,.24);
  font-weight: 800;
}

.hint {
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar strong {
  font-size: 36px;
  letter-spacing: .14em;
}

.icon-button {
  width: 48px;
  padding: 0;
  font-size: 24px;
}

.role-badge {
  align-self: center;
  margin-top: 12dvh;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 16px;
  color: var(--accent);
  background: rgba(0,0,0,.24);
  font-weight: 900;
  text-transform: uppercase;
}

.timer.big {
  margin: auto 0 18px;
  text-align: center;
  font-size: clamp(64px, 25vw, 120px);
  font-weight: 900;
  line-height: .9;
}

#countdown h2,
#countdown p {
  text-align: center;
}

#countdown p {
  margin-top: 10px;
  color: var(--muted);
}

#abandonCountdown {
  margin-top: auto;
}

#setup .role-badge {
  margin: 0 auto 18px;
}

#setup .duration-field {
  display: block;
  margin-top: 18px;
  text-align: left;
}

.setup-actions {
  margin-top: 18px;
}

.game-screen {
  position: relative;
  padding: 0;
  overflow: hidden;
  background: #05080a;
}

#camera,
.camera-fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-fallback {
  display: none;
  place-items: center;
  color: var(--muted);
  background: #101820;
}

.hud {
  position: absolute;
  left: 12px;
  right: 12px;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.hud.top {
  top: max(12px, env(safe-area-inset-top));
}

.hud > div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(0,0,0,.48);
  backdrop-filter: blur(14px);
}

.hud strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.arrow-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.direction-arrow {
  display: none;
  width: min(34vw, 150px);
  height: min(34vw, 150px);
  place-items: center;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,.7);
  color: var(--accent);
  background: rgba(0,0,0,.34);
  font-size: min(21vw, 92px);
  line-height: 1;
  text-shadow: 0 3px 18px rgba(0,0,0,.8);
  transition: transform .2s ease;
}

.distance-label {
  position: absolute;
  top: 56%;
  max-width: calc(100% - 36px);
  border-radius: 999px;
  padding: 8px 13px;
  background: rgba(0,0,0,.56);
  color: var(--ink);
  font-weight: 800;
  text-align: center;
}

.quiz-card {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(82px + env(safe-area-inset-bottom));
  z-index: 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: rgba(16,24,32,.9);
  backdrop-filter: blur(16px);
}

.quiz-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

#quizQuestion {
  font-weight: 800;
  line-height: 1.25;
}

.answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.answers button {
  min-height: 44px;
  padding: 8px 10px;
  font-size: 14px;
  line-height: 1.15;
}

.bottom-actions {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 10px;
}

.bottom-actions button {
  min-width: 0;
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 10;
  display: none;
  border-radius: 8px;
  padding: 12px 14px;
  background: rgba(0,0,0,.78);
  color: var(--ink);
  text-align: center;
}

.toast.show {
  display: block;
}

@media (orientation: landscape) {
  .app::before {
    content: "Tourne ton smartphone en portrait";
    position: fixed;
    inset: 0;
    z-index: 99;
    display: grid;
    place-items: center;
    padding: 24px;
    background: #101820;
    color: var(--ink);
    text-align: center;
    font-size: 24px;
    font-weight: 900;
  }
}
