/* Pichenette — a French school courtyard, late morning. Chalk on the ground,
   ink on Seyès notebook paper, the teacher's red pen. */

:root {
  --chalk: #fffdf5;
  --ink: #26306f;
  --ink-soft: rgba(38, 48, 111, 0.62);
  --red: #cf3b2e;
  --paper: #fffdf7;
  --dirt: #c99a63;
  --seyes-main: rgba(122, 104, 204, 0.42);
  --seyes-fine: rgba(122, 104, 204, 0.16);
  --margin-red: rgba(226, 84, 84, 0.62);
  --cursive: "Playwrite FR Moderne", "Segoe Script", "Comic Sans MS", cursive;
  --ui: "Nunito", "Trebuchet MS", system-ui, sans-serif;
  --hand: 255px 16px 225px 16px / 16px 225px 16px 255px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: var(--dirt) center / cover no-repeat fixed;
  color: var(--ink);
  font-family: var(--ui);
  font-weight: 700;
}

/* late-morning sun: warm light from the top-left, a touch of shade bottom-right */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 12% 0%, rgba(255, 238, 196, 0.32), transparent 55%),
    radial-gradient(ellipse at 100% 100%, rgba(70, 38, 12, 0.28), transparent 60%);
  z-index: 0;
}

/* plane-tree shade drifting over the whole courtyard */
#shade {
  position: fixed;
  inset: -90px;
  pointer-events: none;
  background-size: 1100px auto;
  mix-blend-mode: multiply;
  opacity: 0.17;
  filter: blur(2px);
  animation: breeze 38s ease-in-out infinite alternate;
  z-index: 0;
}
@keyframes breeze {
  0% { transform: translate(0, 0); }
  50% { transform: translate(28px, 16px); }
  100% { transform: translate(-18px, 30px); }
}

#app {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: 100dvh;
  max-width: 1440px;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 12px max(8px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#hud { width: 100%; max-width: 1180px; flex: none; }
#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
#game {
  display: block;
  touch-action: none;
  cursor: grab;
  border-radius: 7px;
  box-shadow: 0 14px 30px rgba(70, 40, 12, 0.32), 0 3px 8px rgba(70, 40, 12, 0.28);
}
#game:active { cursor: grabbing; }
#fx { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 40; }

/* ---- chalk ------------------------------------------------------------------ */

.chalk {
  color: var(--chalk);
  filter: url(#chalk-rough);
  text-shadow: 0 0 1px rgba(255, 255, 255, 0.5), 1px 2px 0 rgba(90, 55, 20, 0.18);
}

.chalk-btn {
  font-family: var(--cursive);
  font-weight: 400;
  font-size: 22px;
  color: var(--chalk);
  background: rgba(255, 253, 245, 0.04);
  border: 3px solid rgba(255, 253, 245, 0.92);
  border-radius: var(--hand);
  padding: 8px 30px 12px;
  cursor: pointer;
  filter: url(#chalk-rough);
  text-shadow: 1px 2px 0 rgba(90, 55, 20, 0.2);
  transition: transform 0.12s ease, background 0.12s ease;
}
.chalk-btn:hover { background: rgba(255, 253, 245, 0.16); transform: rotate(-1deg) scale(1.03); }
.chalk-btn:active { transform: scale(0.97); }
.chalk-btn.primary { font-size: 36px; padding: 10px 60px 16px; border-width: 4px; }

.hint {
  flex: none;
  min-height: 1.5em;
  text-align: center;
  font-family: var(--ui);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.01em;
  color: var(--chalk);
  text-shadow: 0 1px 2px rgba(60, 30, 8, 0.55), 0 0 10px rgba(60, 30, 8, 0.25);
}

/* ---- Seyès notebook paper ----------------------------------------------------- */

.seyes {
  background-color: var(--paper);
  background-image:
    linear-gradient(90deg, transparent 42px, var(--margin-red) 42px, var(--margin-red) 44px, transparent 44px),
    repeating-linear-gradient(0deg, transparent 0 31px, var(--seyes-main) 31px 32px),
    repeating-linear-gradient(0deg, transparent 0 7px, var(--seyes-fine) 7px 8px),
    repeating-linear-gradient(90deg, transparent 0 31px, var(--seyes-fine) 31px 32px);
  box-shadow: 0 10px 22px rgba(60, 35, 10, 0.28), 0 1px 3px rgba(60, 35, 10, 0.25);
  border-radius: 3px;
}

/* ---- HUD -------------------------------------------------------------------------- */

.hud-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr 44px;
  align-items: center;
  gap: 2px 8px;
  min-height: 52px;
  padding: 4px 6px 4px 52px;
}
.hud-hint {
  grid-column: 1 / -1;
  text-align: center;
  font-family: var(--ui);
  font-weight: 800;
  font-size: 14px;
  color: var(--ink);
  min-height: 1.35em;
  line-height: 1.35;
  border-top: 1px dashed rgba(122, 104, 204, 0.35);
  padding-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-hint.event { color: var(--red); font-family: var(--cursive); font-weight: 400; font-size: 15px; animation: pop 0.3s ease; }
@keyframes pop { 0% { transform: scale(0.92); opacity: 0.3; } 100% { transform: none; opacity: 1; } }
.hud-bar.seyes, .hud-bar { /* the strip is always paper */ }
#hud .hud-bar {
  background-color: var(--paper);
  background-image:
    linear-gradient(90deg, transparent 40px, var(--margin-red) 40px, var(--margin-red) 42px, transparent 42px),
    repeating-linear-gradient(0deg, transparent 0 7px, var(--seyes-fine) 7px 8px),
    repeating-linear-gradient(90deg, transparent 0 31px, var(--seyes-fine) 31px 32px);
  box-shadow: 0 6px 16px rgba(60, 35, 10, 0.25);
  border-radius: 4px;
}
.hud-player { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hud-player.right { flex-direction: row-reverse; }
.hud-player canvas { width: 30px; height: 30px; flex: none; }
.hud-player .who { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.hud-player.right .who { align-items: flex-end; }
.hud-player .name {
  font-family: var(--cursive);
  font-weight: 400;
  font-size: 17px;
  color: var(--ink);
  padding: 0 4px 3px;
  white-space: nowrap;
}
.hud-player.turn .name {
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='8' viewBox='0 0 120 8'%3E%3Cpath d='M2 5 C30 2 60 7 118 3' stroke='%23cf3b2e' stroke-width='2.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") bottom / 100% 7px no-repeat;
}
.pot-ok { font-family: var(--cursive); font-weight: 400; color: var(--red); font-size: 12px; padding: 0 4px; }
.hud-mid { text-align: center; display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.hud-mid small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turn-label { font-family: var(--cursive); font-weight: 400; font-size: 19px; color: var(--ink); }
.hud-mid small { font-size: 11px; color: var(--ink-soft); font-weight: 700; }
.hud-menu {
  width: 40px; height: 40px;
  display: flex; flex-direction: column; justify-content: center; gap: 5px;
  padding: 0 9px;
  background: none; border: 2px solid var(--ink-soft); border-radius: var(--hand);
  cursor: pointer;
}
.hud-menu i { display: block; height: 2.5px; background: var(--ink); border-radius: 2px; }
.hud-menu i:nth-child(2) { width: 80%; }

/* ---- menu ------------------------------------------------------------------------- */

#menu, #over { position: absolute; inset: 0; display: none; }
#menu.show {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 18px 16px 28px;
  z-index: 10;
}
#app.menuing #game, #app.menuing #hud, #app.menuing #hint { visibility: hidden; }

.menu-box {
  width: min(1000px, 100%);
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.menu-head { text-align: center; }
.menu-head .title {
  margin: 0;
  font-family: var(--cursive);
  font-weight: 400;
  font-size: clamp(54px, 8.5vw, 104px);
  line-height: 1.25;
  transform: rotate(-2deg);
}
.menu-head .sub { margin: -4px 0 0; font-family: var(--cursive); font-weight: 300; font-size: clamp(17px, 2.2vw, 24px); }

.menu-grid {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 34px;
  align-items: center;
}
.cloth-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.cloth {
  position: relative;
  width: min(100%, 360px);
  min-height: 190px;
  padding: 30px 26px;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 14px 18px;
  background-color: #fff4ec;
  background-image:
    linear-gradient(90deg, rgba(204, 44, 44, 0.5) 50%, transparent 50%),
    linear-gradient(rgba(204, 44, 44, 0.5) 50%, transparent 50%);
  background-size: 26px 26px;
  border-radius: 4px 9px 5px 8px;
  outline: 2px dashed rgba(255, 255, 255, 0.75);
  outline-offset: -9px;
  box-shadow: 0 14px 24px rgba(60, 30, 8, 0.3), 0 2px 4px rgba(60, 30, 8, 0.3);
  transform: rotate(-3deg);
}
.pick { position: relative; width: 78px; height: 78px; cursor: pointer; transition: transform 0.15s ease; }
.pick canvas { width: 78px; height: 78px; display: block; pointer-events: none; }
.pick input, .tick input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  margin: 0; opacity: 0; cursor: pointer; z-index: 1;
}
.pick::before {
  content: ""; position: absolute; inset: 4px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0) 70%);
  opacity: 0; transition: opacity 0.15s ease;
}
.pick:has(input:checked) { transform: translateY(-5px) scale(1.16); }
.pick:has(input:checked)::before { opacity: 1; }
.pick:hover { transform: translateY(-2px) scale(1.06); }
.pick:has(input:focus-visible) { outline: 2px solid var(--chalk); border-radius: 50%; }
.pick-name { margin: 0; font-family: var(--cursive); font-weight: 400; font-size: 20px; }

.page {
  position: relative;
  padding: 18px 22px 16px 62px;
  transform: rotate(1.2deg);
  color: var(--ink);
}
/* binder holes */
.page::before {
  content: ""; position: absolute; left: 14px; top: 0; bottom: 0; width: 14px;
  background:
    radial-gradient(circle at 7px 25%, rgba(120, 80, 40, 0.55) 0 5px, transparent 6px),
    radial-gradient(circle at 7px 75%, rgba(120, 80, 40, 0.55) 0 5px, transparent 6px);
}
.opt-group { margin: 0 0 10px; }
.opt-group h2 {
  display: inline-block;
  margin: 0 0 6px;
  font-family: var(--cursive);
  font-weight: 400;
  font-size: 17px;
  color: var(--ink);
  padding-bottom: 1px;
  border-bottom: 2px solid var(--red);
}
.opts { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.tick {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 2px;
  font-size: 16px;
  color: var(--ink);
  cursor: pointer;
}
.tick .box {
  width: 17px; height: 17px; flex: none;
  border: 2px solid var(--ink);
  border-radius: 2px 3px 2px 4px;
  transform: rotate(-3deg);
  background: center / 130% no-repeat;
}
.tick:has(input:checked) .box {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M3 10 L8 15 L18 2' stroke='%23cf3b2e' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.tick:has(input:focus-visible) .txt { outline: 2px dashed var(--ink-soft); outline-offset: 2px; }
.stake { margin: 8px 0 0; font-family: var(--cursive); font-weight: 400; font-size: 15px; line-height: 2.1; color: var(--ink); }

/* ---- how to play ------------------------------------------------------------------------------------ */

#howto { display: none; }
#howto.show {
  position: fixed; inset: 0; z-index: 35;
  display: flex; align-items: center; justify-content: center;
  padding: 14px;
  background: rgba(60, 35, 12, 0.35);
}
.howto-box {
  position: relative;
  width: min(820px, 100%);
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  padding: 14px 22px 18px 62px;
  color: var(--ink);
  transform: rotate(-0.6deg);
  animation: drop-in 0.4s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.howto-box h1 { margin: 0 0 4px; font-family: var(--cursive); font-weight: 400; font-size: 30px; line-height: 1.6; }
.howto-steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 22px; }
.howto-steps li { display: flex; gap: 12px; align-items: center; }
.howto-steps svg { width: 112px; height: 60px; flex: none; }
.howto-steps h2 { margin: 0; font-family: var(--cursive); font-weight: 400; font-size: 16px; border-bottom: 2px solid var(--red); display: inline-block; }
.howto-steps p { margin: 2px 0 0; font-size: 14px; line-height: 1.35; font-weight: 700; }
.howto-box .chalk-btn {
  white-space: nowrap;
  display: block; margin: 12px auto 0;
  color: var(--ink); border-color: var(--ink); filter: none; text-shadow: none;
  background: rgba(255, 255, 255, 0.6); font-size: 22px; padding: 6px 26px 10px;
}
.chalk-link {
  font-family: var(--cursive); font-weight: 400; font-size: 17px;
  color: var(--chalk); background: none; border: none; cursor: pointer;
  text-decoration: underline wavy rgba(255, 253, 245, 0.7);
  text-underline-offset: 6px;
  filter: url(#chalk-rough);
  padding: 4px 8px;
}

/* ---- settings sheet ---------------------------------------------------------------------- */

#side {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(360px, 92vw);
  z-index: 30;
  transform: translateX(105%);
  transition: transform 0.25s ease;
}
#side.open { transform: translateX(0); }
.tuning-box { height: 100%; overflow-y: auto; padding: 16px 18px 24px 60px; color: var(--ink); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.tuning-box h2 { margin: 0; font-family: var(--cursive); font-weight: 400; font-size: 26px; }
.tuning-box h3 { margin: 16px 0 6px; font-family: var(--cursive); font-weight: 400; font-size: 16px; border-bottom: 2px solid var(--red); display: inline-block; }
.sheet-close { font-size: 26px; line-height: 1; background: none; border: none; color: var(--ink); cursor: pointer; padding: 4px 8px; }
.pill {
  font-family: var(--ui); font-weight: 800; font-size: 14px; color: var(--ink);
  background: rgba(255, 255, 255, 0.6);
  border: 2px solid var(--ink); border-radius: var(--hand);
  padding: 6px 14px; margin: 8px 0 0; cursor: pointer;
}
.pill.on { background: rgba(38, 48, 111, 0.12); box-shadow: inset 0 0 0 1px var(--ink); }
.fine { margin-top: 16px; }
.fine summary { font-family: var(--cursive); font-weight: 400; font-size: 15px; cursor: pointer; }
.tuning-row { margin: 8px 0; font-size: 13px; }
.tuning-row label { display: block; }
.tuning-row input[type="range"] { width: 100%; accent-color: var(--red); }
.acts { margin-top: 18px; }
#coll { display: none; }

/* ---- game over ------------------------------------------------------------------------------ */

#over.show {
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}
.over-box {
  position: relative;
  width: min(440px, 92%);
  padding: 24px 26px 20px 66px;
  transform: rotate(-1.5deg);
  animation: drop-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes drop-in {
  0% { transform: translateY(-40px) rotate(-6deg); opacity: 0; }
  100% { transform: rotate(-1.5deg); opacity: 1; }
}
.over-box h1 { margin: 0 0 6px; font-family: var(--cursive); font-weight: 400; font-size: 34px; line-height: 1.5; color: var(--ink); }
.over-box p { margin: 4px 0; font-size: 16px; }
.over-box .muted { color: var(--ink-soft); font-size: 13px; }
.red-pen {
  position: absolute; right: 16px; top: -12px;
  font-family: var(--cursive); font-weight: 400; font-size: 20px; color: var(--red);
  transform: rotate(-9deg);
}
.won { display: flex; align-items: center; gap: 12px; margin: 6px 0; }
.won canvas { width: 54px; height: 54px; flex: none; animation: roll-in 0.9s 0.3s cubic-bezier(0.25, 1.3, 0.5, 1) both; }
@keyframes roll-in { 0% { transform: translateX(160px) rotate(300deg); opacity: 0; } 100% { transform: none; opacity: 1; } }
.over-acts { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; align-items: center; }
.over-box .chalk-btn {
  color: var(--ink); border-color: var(--ink); filter: none; text-shadow: none;
  background: rgba(255, 255, 255, 0.5); font-size: 19px; padding: 6px 18px 10px;
}
.over-box .chalk-btn.primary { font-size: 21px; padding: 7px 22px 11px; border-width: 3px; }
.over-box .chalk-btn:hover { background: rgba(38, 48, 111, 0.08); }

/* ---- phones and narrow windows --------------------------------------------------------------------- */

@media (max-width: 760px) {
  .menu-grid { grid-template-columns: 1fr; gap: 18px; }
  .cloth { min-height: 0; padding: 22px 18px; width: min(100%, 330px); }
  .page { padding: 12px 14px 10px 54px; }
  .menu-box { gap: 10px; }
}
@media (max-width: 600px) {
  #app { padding-left: 8px; padding-right: 8px; gap: 6px; }
  .hud-bar { min-height: 46px; padding: 3px 4px 3px 44px; gap: 4px; grid-template-columns: 1fr auto 1fr 38px; }
  #hud .hud-bar { background-position: -6px 0, 0 0, 0 0; }
  .hud-player canvas { width: 24px; height: 24px; }
  .hud-player .name { font-size: 14px; }
  .turn-label { font-size: 15px; }
  .hud-mid small { font-size: 10px; }
  .hud-menu { width: 36px; height: 36px; padding: 0 8px; }
  .hud-hint { font-size: 12.5px; }
  .hud-hint.event { font-size: 13px; }
  .howto-steps { grid-template-columns: 1fr; }
  .howto-steps svg { width: 92px; height: 50px; }
  .howto-steps p { font-size: 13px; }
  .howto-box { padding: 10px 14px 14px 52px; }
  .howto-box .chalk-btn, .howto-box .chalk-btn.primary { font-size: 19px; padding: 5px 20px 9px; }
  .howto-box h1 { font-size: 26px; }
  .pick, .pick canvas { width: 62px; height: 62px; }
  .menu-head .title { font-size: 50px; }
  .hud-mid small .long { display: none; }

  .tick { font-size: 15px; }
  .opts { gap: 2px 12px; }
  .chalk-btn.primary { font-size: 30px; padding: 6px 48px 12px; }
  .over-box { padding: 20px 18px 16px 58px; }
  .over-box h1 { font-size: 28px; }
  .over-box .chalk-btn, .over-box .chalk-btn.primary { font-size: 17px; padding: 5px 14px 8px; }
}
