/* Salade de Cafards: parchment skin over the shared header (no base.css).
   Mobile first (a 360px phone is the base); desktop and TV are added with
   min-width queries, short landscape phones with max-height. Frame, header
   skin, Game Dashboard and dialogs here; the match table in board.css. */
:root {
  --bg1: #f7efc7; --bg2: #d5ebb5; --paper: #fff8ea; --paper-edge: #dcc79c;
  --table: #6f9347; --table-dark: #446129; --ink: #2f2818; --gold: #d8ac45;
  --tomato: #cf4d3d; --leaf: #66a63c; --shadow: #0000002f; --error: #9e241f;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: clamp(16px, 2.4vmin, 64px); }
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  margin: 0;
  overscroll-behavior: none;
  color: var(--ink);
  font-family: Georgia, "Trebuchet MS", serif;
  background: radial-gradient(circle at top, #fff8d7, transparent 30%), radial-gradient(circle at bottom right, #c9e7a6, transparent 25%), linear-gradient(180deg, var(--bg1), var(--bg2));
}
body.mode-setup {
  background: linear-gradient(#fff8d799, #d5ebb5aa), url("assets/background.webp") center/cover no-repeat;
}
body.mode-game {
  background: radial-gradient(circle at center, #ffffff12, transparent 35%), linear-gradient(180deg, #7ca14b, #527331 55%, #476428);
}
button, input { font: inherit; }
/* Local skin on top of the shared header: parchment buttons, no bar. */
.game-nav {
  flex: 0 0 auto;
  background: transparent;
  border-bottom-color: transparent;
  box-shadow: none;
}
.back-button,
.options-button {
  border: 2px solid #9daa7f;
  background: linear-gradient(180deg, #fffdf4, #efe2c2);
  color: var(--ink);
}
.back-button span { font-size: 1.1rem; line-height: 1; }
.nav-banner {
  max-height: 35px;
  max-width: min(260px, 50vw);
  border-radius: 18px;
  box-shadow: 0 10px 24px var(--shadow);
}
.options-panel-sheet {
  background: linear-gradient(180deg, var(--paper), #f7edd7);
  border: 3px solid var(--paper-edge);
  color: var(--ink);
}
.lang-switch { display: flex; align-items: center; gap: 0.7rem; }
.rules-frame { width: 100%; height: min(60dvh, 520px); border: 0; border-radius: 12px; background: white; }

/* Android bars can cover the bottom even when the safe-area inset is 0. */
.caf-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 8px max(24px, env(safe-area-inset-right, 0px))
    max(40px, calc(env(safe-area-inset-bottom, 0px) + 24px))
    max(24px, env(safe-area-inset-left, 0px));
}
.setup-screen {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.setup-card {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: min(100%, 34rem);
  padding: 0.9rem 0.6rem;
  background: linear-gradient(180deg, #fff8eaee, #f7edd7ee);
  border: 3px solid var(--paper-edge);
  border-radius: 1.4rem;
  box-shadow: 0 1rem 2.4rem var(--shadow);
}
.setup-title { margin: 0; text-align: center; font-size: 1.4rem; }
.intro { margin: 0; font-size: 0.85rem; text-align: center; }
.setup-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; }
.field {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem 0.2rem;
  background: #fffdf7cc;
  border: 2px solid #e0d0ab;
  border-radius: 1rem;
}
.field label { font-size: 0.75rem; font-weight: 700; text-align: center; }
.stepper { display: flex; align-items: center; gap: 0.2rem; max-width: 100%; }
.step,
.toggle-btn,
.start-btn,
.lang-btn {
  border: 2px solid #9daa7f;
  border-radius: 1rem;
  background: linear-gradient(180deg, #fffdf4, #efe2c2);
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
.lang-btn { padding: 0.5rem 0.9rem; opacity: 1; }
.lang-btn.active { background: linear-gradient(180deg, #f6d779, var(--gold)); border-color: #9f7720; }
.step { flex: 0 0 auto; width: 1.9rem; height: 1.9rem; padding: 0; font-weight: 700; }
.step:disabled, .stepper input:disabled { opacity: 0.45; cursor: default; }
.stepper input {
  flex: 0 0 auto;
  width: 2.8rem;
  padding: 0.3rem 0;
  border: 2px solid #9daa7f;
  border-radius: 0.6rem;
  background: #fffefa;
  text-align: center;
  -moz-appearance: textfield;
  appearance: textfield;
}
.stepper input::-webkit-inner-spin-button,
.stepper input::-webkit-outer-spin-button { margin: 0; -webkit-appearance: none; }
.toggle-btn { min-height: 2.6rem; font-weight: 700; }
.toggle-btn[aria-pressed="true"] { background: linear-gradient(180deg, #f6d779, var(--gold)); border-color: #9f7720; }
.start-btn {
  width: 100%;
  min-height: max(44px, 2.8rem);
  padding: 0.5rem 1rem;
  font-size: 1.05rem;
  font-weight: 700;
  background: linear-gradient(180deg, #f4d86a, #d89a33);
  border-color: #9b6b18;
  box-shadow: 0 0.6rem 1rem #b3781c44;
}
.resume-btn { background: linear-gradient(180deg, #fffdf4, #efe2c2); border-color: #9daa7f; box-shadow: 0 0.4rem 0.8rem #00000024; }
.start-btn:active, .step:active, .toggle-btn:active { transform: scale(0.97); }
.start-btn:disabled { opacity: 0.6; cursor: progress; }
.setup-loading { margin: 0; font-weight: 700; text-align: center; }
.setup-error { margin: 0; color: var(--error); font-weight: 700; text-align: center; }

.winner-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem max(24px, env(safe-area-inset-right, 0px)) max(40px, calc(env(safe-area-inset-bottom, 0px) + 24px)) max(24px, env(safe-area-inset-left, 0px));
  background: rgba(0, 0, 0, 0.7);
}
.winner-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  width: min(100%, 26rem);
  padding: 1.4rem 1.6rem;
  border-radius: 1.6rem;
  background: radial-gradient(circle at top, #fff7e0, #ffe3b0);
  box-shadow: 0 1.6rem 3.6rem rgba(0, 0, 0, 0.45);
}
.winner-text {
  margin: 0;
  font-size: clamp(1.6rem, 6vw, 2.6rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #3b2a11;
  text-align: center;
}
.end-title { margin: 0; font-size: 1.3rem; }
.end-panel .winner-text { font-size: 1.4rem; }

:focus-visible,
html.tv :focus {
  outline: max(3px, 0.4dvh) solid #ffcc00;
  outline-offset: max(2px, 0.3dvh);
}
html.tv :focus { box-shadow: 0 0 0 max(6px, 0.8dvh) rgba(47, 40, 24, 0.75); }

/* Landscape phones are ~360px tall: the four settings go in one row. */
@media (orientation: landscape) and (max-height: 500px) {
  .game-nav { height: 44px; }
  .caf-shell { padding-top: 0; }
  .setup-card { width: min(100%, 44rem); gap: 0.35rem; padding: 0.5rem 0.8rem; }
  .setup-title { font-size: 1.1rem; }
  .intro { display: none; }
  .setup-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.35rem; }
  .field { padding: 0.25rem; }
  .step { width: 1.9rem; height: 1.9rem; }
  .stepper { gap: 0.2rem; }
  .stepper input { width: 3rem; padding-inline: 0; }
  .toggle-btn, .start-btn { min-height: 2.3rem; }
}

/* Desktop and TV, 960x540 up to 3840x2160: sizes follow the screen and
   everything stays 3% away from the edges (TV overscan). */
@media (min-width: 960px) and (min-height: 500px) {
  .game-nav {
    height: auto;
    padding: 3dvh max(3vw, env(safe-area-inset-right, 0px)) 1dvh max(3vw, env(safe-area-inset-left, 0px));
  }
  .back-button,
  .options-button {
    width: max(36px, 6dvh);
    height: max(36px, 6dvh);
    font-size: max(1rem, 3dvh);
  }
  .back-button span { font-size: inherit; }
  .back-button svg,
  .options-button svg { width: 50%; height: 50%; }
  .nav-banner { max-height: max(35px, 6dvh); max-width: 30vw; }
  .caf-shell { padding: 1dvh max(3vw, env(safe-area-inset-right, 0px)) max(40px, 4dvh) max(3vw, env(safe-area-inset-left, 0px)); }
  .setup-card { width: min(100%, 40rem); }
}
