:root {
  --ink: #2b2118;
  --ink-soft: #5b4733;
  --paper: #ead9b4;
  --cream: #fbf4e3;
  --oxblood: #8c2a1d;
  --oxblood-bright: #b8402c;
  --oxblood-deep: #4d150d;
  --sepia-dark: #6e5236;
  --sepia: #b89c75;
  --sepia-mid: #a68c66;
  --sepia-pale: #ddcba8;
  --steel: #36424a;
  --steel-light: #66757d;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

html {
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

[hidden] {
  display: none !important;
}

/* Parchemin : grain fin, taches diffuses, dégradé bruni sur les bords */
body {
  min-height: 100vh;
  overflow-x: hidden;
  font-family: 'IM Fell English', Georgia, 'Times New Roman', serif;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .3 0 0 0 0 .2 0 0 0 0 .08 0 0 0 .8 -.28'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    radial-gradient(ellipse 30% 26% at 16% 24%, rgba(140, 98, 42, 0.13), transparent 70%),
    radial-gradient(ellipse 34% 28% at 84% 72%, rgba(140, 98, 42, 0.12), transparent 70%),
    radial-gradient(ellipse 22% 18% at 68% 14%, rgba(120, 82, 36, 0.09), transparent 70%),
    radial-gradient(ellipse 26% 22% at 28% 86%, rgba(120, 82, 36, 0.1), transparent 70%),
    radial-gradient(ellipse 85% 75% at 50% 42%, #f7edd4 0%, #ecdbb6 55%, #d6bb86 100%);
  background-attachment: fixed;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  box-shadow: inset 0 0 160px 40px rgba(96, 62, 24, 0.33);
}

.page {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 2.2vh, 24px);
  /* zones sûres : encoche caméra et barre de navigation des smartphones */
  padding:
    max(clamp(18px, 3vh, 36px), env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(32px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

/* ---------- Titre ---------- */

.title-block {
  position: relative;
  z-index: 1;
  text-align: center;
}

h1 {
  margin: 0;
  font-family: 'IM Fell English SC', Georgia, serif;
  font-weight: 400;
  font-size: clamp(2.1rem, 4.6vw, 3.4rem);
  letter-spacing: 0.06em;
  line-height: 1;
}

.flourish {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(340px, 70vw);
  margin: 10px auto 0;
}

.flourish::before,
.flourish::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--ink-soft));
}

.flourish::after {
  background: linear-gradient(90deg, var(--ink-soft), transparent);
}

.flourish i {
  width: 8px;
  height: 8px;
  background: var(--oxblood);
  transform: rotate(45deg);
  outline: 1px solid var(--ink-soft);
  outline-offset: 2px;
}

.subtitle {
  margin: 0.5em 0 0;
  font-style: italic;
  font-size: clamp(1rem, 1.8vw, 1.2rem);
  color: var(--ink-soft);
}

/* ---------- Mise en page ---------- */

.stage {
  display: grid;
  justify-items: center;
  align-items: center;
  gap: clamp(20px, 3vw, 56px);
  width: 100%;
  max-width: 1320px;
}

.compass {
  width: min(100%, 64vh, 720px);
  aspect-ratio: 1;
}

.compass svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

@media (min-width: 900px) and (min-aspect-ratio: 1/1) {
  .stage {
    grid-template-columns: auto 330px;
    justify-content: center;
  }

  .compass {
    width: min(calc(100vw - 460px), 78vh, 860px);
  }
}

/* ---------- Cadran SVG ---------- */

.rhumb {
  stroke: var(--ink-soft);
  stroke-width: 1;
  opacity: 0.2;
}

.rhumb-main {
  stroke-width: 1.4;
  opacity: 0.32;
}

.ring-line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 0.9;
}

.ring-outer {
  stroke-width: 2.8;
}

.ticks {
  stroke: var(--ink);
  stroke-width: 0.9;
}

.chequer {
  fill: var(--ink);
}

.marker {
  fill: var(--ink-soft);
}

.marker-main {
  fill: var(--oxblood);
}

.sector-highlight {
  fill: var(--oxblood);
  opacity: 0;
  transition: opacity 0.6s ease;
}

.sector-highlight.is-visible {
  opacity: 0.3;
}

.inner-ring {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.2;
}

.inner-ring.thin {
  stroke-width: 0.6;
}

.pt {
  stroke-linejoin: round;
}

.pt-0 {
  stroke: var(--ink);
  stroke-width: 1.4;
}

.pt-0.pt-dark {
  fill: var(--ink);
}

.pt-0.pt-light {
  fill: var(--cream);
}

.pt-1 {
  stroke: #4a3824;
  stroke-width: 1;
}

.pt-1.pt-dark {
  fill: var(--sepia-dark);
}

.pt-1.pt-light {
  fill: var(--sepia);
}

.pt-2 {
  stroke: #7a6446;
  stroke-width: 0.8;
}

.pt-2.pt-dark {
  fill: var(--sepia-mid);
}

.pt-2.pt-light {
  fill: var(--sepia-pale);
}

.card-grain {
  opacity: 0.55;
  mix-blend-mode: multiply;
  pointer-events: none;
}

.label {
  font-family: 'Cinzel', Georgia, serif;
  font-weight: 700;
  fill: var(--ink);
  transform-box: fill-box;
  transform-origin: center;
  transition: fill 0.12s;
}

.label-0 {
  font-size: 66px;
}

.label-1 {
  font-size: 36px;
}

.label-2 {
  font-size: 23px;
  fill: var(--ink-soft);
}

.label.is-north {
  fill: var(--oxblood);
}

.label.is-current {
  fill: var(--oxblood-bright);
}

.label.is-result {
  fill: var(--oxblood);
  animation: label-pop 0.7s ease-out;
}

@keyframes label-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.needle-north.needle-a {
  fill: #9c2a1f;
}

.needle-north.needle-b {
  fill: #cf4b38;
}

.needle-south.needle-a {
  fill: var(--steel);
}

.needle-south.needle-b {
  fill: var(--steel-light);
}

.needle polygon {
  stroke: var(--ink);
  stroke-width: 1.3;
  stroke-linejoin: round;
}

.hub-ring,
.hub-cap {
  stroke: var(--ink);
  stroke-width: 1.2;
}

.hub-pin {
  fill: var(--ink);
}

/* ---------- Panneau ---------- */

.panel {
  position: relative;
  z-index: 1;
  width: min(100%, 360px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 26px 22px 20px;
  text-align: center;
  background: rgba(251, 244, 227, 0.62);
  border: 1px solid var(--ink-soft);
  outline: 1px solid var(--ink-soft);
  outline-offset: 5px;
  box-shadow: 0 10px 30px rgba(90, 60, 24, 0.18);
}

.panel::before,
.panel::after {
  content: '';
  position: absolute;
  left: 50%;
  width: 10px;
  height: 10px;
  background: var(--oxblood);
  border: 1px solid var(--ink-soft);
  transform: translate(-50%, -50%) rotate(45deg);
}

.panel::before {
  top: -3px;
}

.panel::after {
  top: calc(100% + 3px);
}

.readout {
  width: 100%;
}

.readout-label {
  font-family: 'IM Fell English SC', Georgia, serif;
  font-size: 1rem;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
}

.readout-name {
  margin: 6px 0 2px;
  font-family: 'IM Fell English SC', Georgia, serif;
  font-size: clamp(1.45rem, 2.2vw, 1.85rem);
  line-height: 1.2;
  white-space: nowrap;
  color: var(--oxblood);
}

.readout-name.reveal {
  animation: reveal 0.7s ease-out;
}

@keyframes reveal {
  0% { opacity: 0.2; transform: scale(0.8); }
  60% { opacity: 1; transform: scale(1.08); }
  100% { opacity: 1; transform: scale(1); }
}

.readout-meta {
  min-height: 1.4em;
  font-style: italic;
  font-size: 1.05rem;
  color: var(--ink-soft);
}

.launch {
  min-width: 220px;
  padding: 16px 30px 15px 38px;
  font-family: 'Cinzel', Georgia, serif;
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--cream);
  background: linear-gradient(180deg, #a83a29 0%, #8c2a1d 55%, #74210f 100%);
  border: 1px solid var(--oxblood-deep);
  border-radius: 4px;
  box-shadow:
    inset 0 0 0 4px rgba(140, 42, 29, 0.9),
    inset 0 0 0 5px rgba(251, 244, 227, 0.5),
    0 3px 0 var(--oxblood-deep),
    0 8px 18px rgba(77, 21, 13, 0.35);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.2s ease;
}

.launch:hover {
  filter: brightness(1.08);
}

.launch:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 0 0 4px rgba(140, 42, 29, 0.9),
    inset 0 0 0 5px rgba(251, 244, 227, 0.5),
    0 1px 0 var(--oxblood-deep),
    0 4px 10px rgba(77, 21, 13, 0.3);
}

.launch:disabled {
  cursor: progress;
  filter: saturate(0.5) brightness(0.92);
  transform: none;
}

.launch:focus-visible,
.toggle:focus-visible,
.install:focus-visible {
  outline: 2px dashed var(--ink);
  outline-offset: 5px;
}

.hint {
  margin: -6px 0 0;
  font-style: italic;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.history {
  width: 100%;
  padding-top: 14px;
  border-top: 1px solid rgba(91, 71, 51, 0.4);
}

.history h2 {
  margin: 0 0 10px;
  font-family: 'IM Fell English SC', Georgia, serif;
  font-weight: 400;
  font-size: 1rem;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
}

.history ol {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history li {
  min-width: 2.6em;
  padding: 4px 7px 3px;
  font-family: 'Cinzel', Georgia, serif;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  border: 1px solid var(--ink-soft);
  border-radius: 3px;
  background: rgba(251, 244, 227, 0.75);
}

.history li:first-child {
  color: var(--cream);
  background: var(--oxblood);
  border-color: var(--oxblood-deep);
}

.history-empty {
  margin: 0;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.toggles {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 10px;
}

.toggle {
  min-height: 36px;
  padding: 4px 10px;
  font-family: 'IM Fell English', Georgia, serif;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--ink-soft);
  background: none;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
}

.toggle:hover {
  border-color: rgba(91, 71, 51, 0.45);
}

.toggle[aria-pressed='false'] {
  text-decoration: line-through;
}

.install {
  min-height: 44px;
  padding: 8px 20px;
  font-family: 'IM Fell English SC', Georgia, serif;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  color: var(--oxblood);
  background: rgba(251, 244, 227, 0.85);
  border: 1px solid var(--oxblood);
  border-radius: 4px;
  box-shadow: 0 2px 0 rgba(77, 21, 13, 0.35);
  cursor: pointer;
}

.install:active {
  transform: translateY(1px);
  box-shadow: none;
}

/* ---------- Smartphone ---------- */

/* pas de barre d'espace sur un écran tactile */
@media (hover: none) {
  .hint {
    display: none;
  }
}

@media (max-width: 480px) {
  body::before {
    box-shadow: inset 0 0 90px 18px rgba(96, 62, 24, 0.3);
  }

  .page {
    gap: 12px;
  }

  .subtitle {
    font-size: 0.98rem;
  }

  .panel {
    gap: 14px;
    padding: 22px 18px 16px;
  }

  .launch {
    width: 100%;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .label.is-result,
  .readout-name.reveal {
    animation: none;
  }
}
