/**********************************************
 * SECTION 1 — Reset & Base
 **********************************************/
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }

body {
  font-family: Arial, sans-serif;
  /* allow scrolling on the start/forms page; gameplay uses #gameBoard overflow */
  overflow: auto;
  background: url("../images/mount.jpg") no-repeat center center fixed;
  background-size: cover;
}

/* Make the [hidden] attribute reliably hide elements */
[hidden] { display: none !important; }

/**********************************************
 * SECTION 2 — Landing Highlight Animation (board)
 **********************************************/
.landed-glow {
  animation: landFlash 1.2s ease-out;
  position: relative;
  z-index: 10 !important;
  border: 3px solid white !important;
}
@keyframes landFlash {
  0%   { box-shadow: 0 0 0 0 rgba(255,255,255,0); }
  25%  { box-shadow: 0 0 20px 10px rgba(255,255,0,0.8); }
  50%  { box-shadow: 0 0 15px 5px rgba(255,255,0,0.5); }
  100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); }
}

/**********************************************
 * SECTION 3 — Initial Selection Page (start screen)
 **********************************************/
#initialPage {
  width: 100vw;
  min-height: 100vh;                /* content can grow & scroll */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;      /* content near top */
  gap: 16px;
  background-color: #fef6d8;
  border: 4px solid #d4af37;
  padding: 24px;
  box-shadow: 0 0 10px rgba(0,0,0,0.3);
  text-align: left;
}

/* keep all direct children centered to a readable column */
#initialPage > * {
  width: min(96vw, 880px);
  margin-inline: auto;
}

#initialPage h2 {
  margin-bottom: 8px;
  font-weight: 700;
}

/* Mode chooser (Criterium / Queen Stage) */
.mode-chooser,
.mode-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  margin: 4px 0 10px 0;
}
.mode-chooser .mode-btn {
  padding: 10px 14px;
  border: 2px solid #333;
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  transition: transform .08s ease, box-shadow .12s ease, background .12s ease;
}
.mode-chooser .mode-btn:active { transform: translateY(1px); }
.mode-chooser .mode-btn.is-active {
  background: #0f766e; color: #fff; border-color: #0d5f59;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}

/* Start form card */
.form-wrapper {
  background: #fff9e8;
  border: 2px solid #d4af37;
  border-radius: 10px;
  padding: 18px 16px;
  box-shadow: 2px 2px 8px rgba(0,0,0,0.18);
  width: 100%;
}

/* Each cyclist row — image on the left, controls on the right */
.cyclist-option {
  display: flex;                    /* matches original layout */
  flex-wrap: wrap;                  /* wraps on small screens */
  align-items: center;
  gap: 12px 16px;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: rgba(255,255,255,0.65);
  border: 1px solid #d4af37;
  border-radius: 8px;
}

/* Cyclist image sizing */
.cyclist-option img {
  width: 160px;                     /* consistent portrait size */
  height: auto;
  object-fit: contain;
  border: 1px solid #333;
  border-radius: 6px;
  flex: 0 0 auto;
}

/* Radio + label + name input live inline to the right of the image */
#initialPage input[type="radio"] { 
  transform: scale(1.1);
  margin-right: 6px;
}
#initialPage label { 
  margin-right: 10px; 
  font-weight: 600;
}

/* Name input */
.cyclist-name-input {
  padding: 6px 8px;
  border: 1px solid #bdbdbd;
  border-radius: 6px;
  min-width: 180px;
  max-width: 260px;
}

/* Start button */
#initialPage button {
  margin-top: 14px;
  padding: 10px 20px;
  background-color: #0f766e;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
}
#initialPage button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* Instruction box */
.instruction-box {
  font-family: Tahoma, sans-serif;
  font-style: italic;
  margin-top: 8px;
  padding: 14px;
  border: 2px solid #888;
  border-radius: 8px;
  background-color: #fce8d5;
  line-height: 1.5;
  text-align: justify;
}
.instruction-box-title {
  text-align: center;
  font-style: normal;
  margin-top: 0;
  font-weight: 700;
}

/* Mobile polish for start page */
@media (max-width: 560px) {
  .cyclist-option img { width: 120px; }
  .cyclist-name-input { min-width: 150px; max-width: 100%; }
  #initialPage { padding: 16px; }
}

/**********************************************
 * SECTION 4 — Game Board Wrapper (gameplay pages)
 **********************************************/
#gameBoard {
  width: 100vw;
  height: 100vh;
  position: relative;
  /* confine overflow only during gameplay */
  overflow: hidden;
}
.title-square {
  font-family: Tahoma, sans-serif;
  font-size: 22px !important;
  font-weight: bold;
  color: #d4af37 !important;
  background-color: #fffbe6;
  border: 2px solid black !important;
  text-align: center;
  z-index: 1;
  position: relative;
}

.title-square {
  /* ...keep your existing properties... */
  -webkit-text-stroke: 0.6px #000;
  paint-order: stroke fill;
  text-shadow:
    0 0 0.5px #000,
    0.4px 0   0   #000,
   -0.4px 0   0   #000,
    0   0.4px 0   #000,
    0  -0.4px 0   #000;
}



/**********************************************
 * SECTION 5 — Grid & Squares (board)
 **********************************************/
#grid {
  display: grid;
  grid-template-columns: repeat(25, 1fr);
  grid-template-rows: repeat(15, 1fr); /* JS may override to 14 rows */
  width: 95vw;
  height: 90vh;
  margin: 20px auto 0 auto;
  border: 2px solid #444;
  gap: 2px;
  position: relative; /* anchor for absolute children */
  z-index: 1;
}

.square {
  background-color: transparent;
  border: 2px solid rgba(170,170,170,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
  color: transparent;
  position: relative;
  overflow: visible;
}

.square-count {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 10px;
  color: black;
  font-weight: bold;
  pointer-events: none;
}

.path-square.border-hide { border-color: transparent !important; }

/* Road look (+ blur layer) */
.path-square {
  color: transparent !important;
  font-size: 0 !important;
  border: 2px solid black !important;
}
.path-square::before,
.path-square.yellow::before,
.path-square.red::before,
.path-square.violet::before,
.path-square.green::before,
.path-square.black::before {
  content: "";
  position: absolute;
  inset: 0;
  backdrop-filter: blur(5px);
  z-index: -1;
  border-radius: inherit;
}

/* Flats & mountains (when not special colored) */
.path-square.flat-road:not(.yellow):not(.red):not(.violet):not(.green):not(.black) {
  background: rgba(200,200,200,0.3);
  box-shadow:
    inset 0 1px 2px rgba(255,255,255,0.5),
    inset 0 -1px 1px rgba(102,102,102,0.5);
}
.path-square.mountain-road:not(.yellow):not(.red):not(.violet):not(.green):not(.black) {
  background: rgba(180,140,80,0.3);
  box-shadow:
    inset 0 1px 2px rgba(255,240,208,0.5),
    inset 0 -1px 1px rgba(117,84,32,0.5);
}

/* Special squares: visible colors */
.path-square.yellow:not(.border-hide) { background-color: rgba(255,235,59,0.6) !important; }
.path-square.red:not(.border-hide)    { background-color: rgba(255,0,0,0.6) !important; }
.path-square.violet:not(.border-hide) { background-color: rgba(255,105,180,0.6) !important; }
.path-square.green:not(.border-hide)  { background-color: rgba(0,127,0,0.6) !important; }
.path-square.black:not(.border-hide)  { background-color: rgba(42,42,42,0.6) !important; }

/* Hide color when border is hidden (even squares rule) */
.path-square.border-hide { background-color: transparent !important; }

/* Rounded corners */
.round-top-left { border-top-left-radius: 12px; }
.round-top-right { border-top-right-radius: 12px; }
.round-bottom-left { border-bottom-left-radius: 12px; }
.round-bottom-right { border-bottom-right-radius: 12px; }

/* Fallback “special” classes (non-road usage) */
.yellow { background-color: rgba(255,235,59,0.6) !important; border: 2px solid black; opacity: .95; }
.red    { background-color: rgba(255,0,0,0.6) !important;    border: 2px solid black; opacity: .95; }
.violet { background-color: rgba(255,105,180,0.6) !important; border: 2px solid black; opacity: .95; }
.green  { background-color: rgba(0,127,0,0.6) !important;     border: 2px solid black; opacity: .95; }
.black  { background-color: rgba(42,42,42,0.6) !important;    border: 2px solid black; opacity: .95; }

/**********************************************
 * SECTION 6 — Cyclist Pieces & Micro-animations
 **********************************************/
.cyclist {
  width: 100%;
  height: 100%;
  max-width: 45px;
  max-height: 45px;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) rotate(0deg);
  object-fit: contain;
  transition: transform .3s ease, left .3s, top .3s;
  z-index: 5;
  pointer-events: none;
  will-change: transform;
  transform-origin: 50% 60%;
}
.cyclist::after {
  content: "";
  position: absolute;
  left: 50%; top: 70%;
  width: 28px; height: 10px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: rgba(0,0,0,0.28);
  filter: blur(3px);
  pointer-events: none;
  z-index: -1;
}

/* Subtle idle/move effects */
.moving { animation: enlargeShrink 1s infinite; max-width: 50px; max-height: 50px; }
@keyframes enlargeShrink { 0%,100% { transform: translate(-50%, -50%) scale(1); } 50% { transform: translate(-50%, -50%) scale(1.2); } }
.cyclist.anticipate { animation: anticipateForward 90ms ease-out; }
@keyframes anticipateForward { 0% { transform: translate(-50%, -50%) scale(1); } 100% { transform: translate(calc(-50% + 2px), calc(-50% - 1px)) scale(1.02); } }
.cyclist.wobble { animation: wobbleSide 320ms ease-in-out infinite; }
@keyframes wobbleSide { 0%,100% { transform: translate(-50%,-50%) rotate(0deg); } 50% { transform: translate(-50%,-50%) rotate(2deg); } }
.cyclist.cadence { animation: pedalBob 220ms linear infinite; }
@keyframes pedalBob { 0%,100% { transform: translate(-50%,-50%); } 50% { transform: translate(-50%, calc(-50% - 1.5px)); } }
.cyclist.tilt-climb { transform: translate(-50%, -50%) rotate(-3deg); }
.cyclist.tuck-sprint { transform: translate(-50%, calc(-50% + 1px)) scale(1.02); }
.square.land-pop { animation: landPop 140ms ease-out; }
@keyframes landPop { 0% { box-shadow: 0 0 0 rgba(0,0,0,0); } 100% { box-shadow: 0 0 10px rgba(0,0,0,0.25); } }

/* Bigger while moving */
.cyclist.moving-big {
  max-width: 62px;
  max-height: 62px;
  transition: max-width 120ms ease, max-height 120ms ease;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.28));
}

/**********************************************
 * SECTION 7 — Info Table (HUD)
 **********************************************/
#infoTable {
  position: absolute;
  top: 20px;
  left: 10px;
  background: white;
  border: 4px solid black;
  padding: 10px;
  width: 160px;
  text-align: left;
  box-shadow: 2px 2px 10px rgba(0,0,0,0.2);
  z-index: 10;
}

/* Clamp and portrait (JS also adds this class) */
#infoTable #infoCyclistImage { width: 80px; height: auto; display: block; }
.rider-portrait {
  width: 100px;
  height: auto;
  object-fit: contain;
  border: 2px solid #000;
  background: #fff;
  border-radius: 6px;
  display: block;
}

/**********************************************
 * SECTION 8 — Dice Styles
 **********************************************/
.face {
  position: absolute;
  width: 100%; height: 100%;
  background: white; border: 2px solid #444;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  backface-visibility: hidden;
}
.pip { width: 30%; height: 30%; background: black; border-radius: 50%; justify-self: center; align-self: center; }
.center { grid-column: 2; grid-row: 2; }
.top-left { grid-column: 1; grid-row: 1; }
.top-right { grid-column: 3; grid-row: 1; }
.center-left { grid-column: 1; grid-row: 2; }
.center-right { grid-column: 3; grid-row: 2; }
.bottom-left { grid-column: 1; grid-row: 3; }
.bottom-right { grid-column: 3; grid-row: 3; }

.face.front  { transform: rotateY(0deg) translateZ(40px); }
.face.back   { transform: rotateY(180deg) translateZ(40px); }
.face.right  { transform: rotateY(90deg) translateZ(40px); }
.face.left   { transform: rotateY(-90deg) translateZ(40px); }
.face.top    { transform: rotateX(90deg) translateZ(40px); }
.face.bottom { transform: rotateX(-90deg) translateZ(40px); }

@keyframes diceShake {
  0%   { transform: translate(0,0) rotateX(var(--x,0deg)) rotateY(var(--y,0deg)); }
  25%  { transform: translate(10px,-10px) rotateX(var(--x)) rotateY(var(--y)); }
  50%  { transform: translate(-10px,10px) rotateX(var(--x)) rotateY(var(--y)); }
  75%  { transform: translate(10px,10px) rotateX(var(--x)) rotateY(var(--y)); }
  100% { transform: translate(0,0) rotateX(var(--x)) rotateY(var(--y)); }
}
/* If you add .shaking in JS, this matches 2s dice spin */
.cube.shaking { animation: diceShake 2s ease-out; }

#dice {
  position: absolute;
  width: 60px; height: 60px;
  top: 50%; left: 40%;
  transform: translate(-50%, -50%);
  perspective: 600px;
  cursor: grab;
  z-index: 20;
}
.cube {
  width: 100%; height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transform: rotateX(0deg) rotateY(0deg);
  transition: transform 1s ease-out;
}

/**********************************************
 * SECTION 9 — Final Results Panel
 **********************************************/
#resultsTableContainer {
  /* no display:none here — [hidden] handles first load; JS unhides */
  background: #ffffffee;
  border: 2px solid #222;
  padding: 15px;
  margin-top: 15px;
  position: absolute;
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  border-radius: 8px;
  width: 300px;
  font-family: 'Arial', sans-serif;
}
#resultsTableContainer table { width: 100%; border-collapse: collapse; }
#resultsTableContainer th, #resultsTableContainer td {
  padding: 8px 12px; border-bottom: 1px solid #ccc; text-align: left;
}
#resultsTableContainer th { background-color: #f2f2f2; font-weight: bold; color: #333; }
#resultsTableContainer td { background-color: #fafafa; color: #111; }

/* anchor bottom-right INSIDE the grid when JS adds this class and moves node into #grid */
#resultsTableContainer.at-grid-bottom-right {
  position: absolute;
  right: 8px;
  bottom: 8px;
  left: auto;
  top: auto;
  transform: none;
  z-index: 25;
}

/* Pin the results panel at the board's bottom-right (overlay above the grid) */
#resultsTableContainer.at-board-bottom-right {
  position: absolute;
  right: 8px;
  bottom: 8px;
  left: auto;
  top: auto;
  transform: none;
  z-index: 25;

  /* keep your existing visual style */
  width: min(340px, 36%);
  max-height: 46vh;
  overflow: auto;
  background: #ffffffee;
  border: 2px solid #222;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  padding: 15px;
}





/**********************************************
 * SECTION 10 — Utility Badges
 **********************************************/
.info-number {
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 4px;
  margin: 0 2px;
  display: inline-block;
  background: #eee;
}

/**********************************************
 * SECTION 11 — Reveal-on-Land Helpers (high specificity)
 **********************************************/
#grid .square.reveal-flat      { background-color: silver !important; }
#grid .square.reveal-mountain  { background-color: #b48c50 !important; }
#grid .square.reveal-yellow    { background-color: rgba(255,235,59,0.95) !important; }
#grid .square.reveal-red       { background-color: rgba(255,0,0,0.95) !important; }
#grid .square.reveal-violet    { background-color: rgba(255,105,180,0.95) !important; }
#grid .square.reveal-green     { background-color: rgba(0,127,0,0.95) !important; }
#grid .square.reveal-black     { background-color: rgba(42,42,42,0.95) !important; }

/**********************************************
 * SECTION 12 — Language Selector (start page)
 **********************************************/
.language-select {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  max-width: 300px;
}
.language-select label { font-weight: bold; white-space: nowrap; }
.language-select select { flex: 1; max-width: 150px; }


/* SECTION — Hide grid chrome but keep the road visible */
#grid { border: 0 !important; gap: 0 !important; } /* hide outer frame & gaps */

#grid .square:not(.path-square) {
  border: 0 !important;               /* remove lines on non-path cells */
}

#grid .square-count {
  display: none !important;            /* hide tiny index numbers */
}

/* Keep existing road look intact */
#grid .path-square {                   /* the road still shows its own border */
  border: 2px solid black !important;
}

/**********************************************
 * PATH DECOR — center dash + outer yellow outline
 **********************************************/
/* Tweakable dash variables */
:root{
  --rc-dash: 16px;   /* length of each dash segment */
  --rc-gap: 10px;    /* gap between dashes */
  --rc-line: 2px;    /* line thickness */
  --rc-pad: 6%;      /* inset from cell edge (keeps line off borders) */
  --rc-yellow: #ffea00;
}

/* Horizontal center line (terrain only, not specials) */
.path-square[data-dash="h"]:not(.yellow):not(.red):not(.violet):not(.green):not(.black)::after{
  content:"";
  position:absolute;
  left: var(--rc-pad);
  right: var(--rc-pad);
  top: 50%;
  height: var(--rc-line);
  transform: translateY(-50%);
  background:
    repeating-linear-gradient(
      to right,
      var(--rc-yellow) 0 calc(var(--rc-dash)),
      transparent      calc(var(--rc-dash)) calc(var(--rc-dash) + var(--rc-gap))
    );
  pointer-events:none;
  z-index:1;
}

/* Vertical center line (terrain only, not specials) */
.path-square[data-dash="v"]:not(.yellow):not(.red):not(.violet):not(.green):not(.black)::after{
  content:"";
  position:absolute;
  top: var(--rc-pad);
  bottom: var(--rc-pad);
  left: 50%;
  width: var(--rc-line);
  transform: translateX(-50%);
  background:
    repeating-linear-gradient(
      to bottom,
      var(--rc-yellow) 0 calc(var(--rc-dash)),
      transparent      calc(var(--rc-dash)) calc(var(--rc-dash) + var(--rc-gap))
    );
  pointer-events:none;
  z-index:1;
}


/* Outer-perimeter yellow border: draw only where there is NO neighbor.
   We paint a 3px stripe right on the outer edge of the path. */
.path-square.edge-top::before,
.path-square.edge-right::before,
.path-square.edge-bottom::before,
.path-square.edge-left::before {
  content: "";
  position: absolute;
  background: #ffea00;
  pointer-events: none;
  z-index: 2;
}

/* Each side sized/placed precisely on the outside rim */
.path-square.edge-top::before    { left: 0; right: 0; height: 3px; top: -1.5px; }
.path-square.edge-right::before  { top: 0; bottom: 0; width: 3px; right: -1.5px; }
.path-square.edge-bottom::before { left: 0; right: 0; height: 3px; bottom: -1.5px; }
.path-square.edge-left::before   { top: 0; bottom: 0; width: 3px; left: -1.5px; }

/* 4px border on START and END squares (doesn't affect the yellow outline) */
.path-square.is-start,
.path-square.is-end {
  border-width: 4px !important;
  border-color: #000 !important;
}
