/* ==========================================================================
   Karikot Onam Games — shared design system
   Palette borrows from the kasavu mundu (cream + gold) and the pookalam
   (marigold, chethi red, thumba white, deep green).
   ========================================================================== */

:root {
  --cream:        #FBF3E2;
  --cream-deep:   #F2E4C6;
  --paper:        #FFFDF7;
  --gold:         #C08A1E;
  --gold-light:   #E8C56A;
  --green:        #0E5135;
  --green-deep:   #07301E;
  --marigold:     #EF9A1E;
  --chethi:       #C62828;
  --purple:       #7B2D8E;
  --ink:          #2B1F12;
  --muted:        #7C6A50;
  --line:         rgba(43, 31, 18, 0.14);

  --shadow-sm: 0 1px 2px rgba(43, 31, 18, .08), 0 2px 8px rgba(43, 31, 18, .06);
  --shadow-md: 0 4px 10px rgba(43, 31, 18, .10), 0 12px 28px rgba(43, 31, 18, .10);
  --shadow-lg: 0 10px 24px rgba(43, 31, 18, .14), 0 28px 60px rgba(43, 31, 18, .16);

  --radius:    18px;
  --radius-sm: 12px;

  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-body:    "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mal:     "Baloo Chettan 2", "Noto Sans Malayalam", sans-serif;

  --wrap: 1080px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background-color: var(--cream);
  background-image:
    radial-gradient(circle at 12% -10%, rgba(239, 154, 30, .18), transparent 42%),
    radial-gradient(circle at 92% 4%, rgba(123, 45, 142, .12), transparent 38%),
    radial-gradient(circle at 50% 108%, rgba(14, 81, 53, .14), transparent 46%);
  background-attachment: fixed;
  line-height: 1.55;
}

/* The gold kasavu stripe that edges the page, top and bottom. */
body::before,
body::after {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  height: 8px;
  z-index: 50;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    var(--gold) 0 6px, var(--gold-light) 6px 10px, var(--gold) 10px 16px,
    transparent 16px 22px
  ) repeat-x;
  background-size: 22px 100%;
  box-shadow: 0 0 0 1px rgba(192, 138, 30, .35) inset;
}
body::before { top: 0; }
body::after  { bottom: 0; }

/* --- typography ---------------------------------------------------------- */

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 800;
  line-height: 1.12;
  margin: 0;
  letter-spacing: -0.015em;
}

.mal {
  font-family: var(--font-mal);
  font-weight: 500;
  letter-spacing: 0;
}

.eyebrow {
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--gold);
}

.lede  { color: var(--muted); font-size: 1.02rem; }
.muted { color: var(--muted); }

a { color: var(--green); }

/* --- layout -------------------------------------------------------------- */

.wrap {
  width: min(var(--wrap), 100% - 2rem);
  margin-inline: auto;
}

.stack   { display: flex; flex-direction: column; }
.row     { display: flex; align-items: center; gap: .6rem; }
.spread  { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.center  { text-align: center; }

/* --- buttons ------------------------------------------------------------- */

.btn {
  --btn-bg: var(--green);
  --btn-fg: #FFF8E7;
  appearance: none;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .78rem 1.35rem;
  min-height: 48px;
  border-radius: 999px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: inherit;
  font-weight: 700;
  font-size: .96rem;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .12s ease, box-shadow .18s ease, background-color .18s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover  { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(1px); box-shadow: var(--shadow-sm); }
.btn:focus-visible { outline: 3px solid var(--marigold); outline-offset: 3px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.btn--gold  { --btn-bg: var(--marigold); --btn-fg: #3A2405; }
.btn--ghost {
  --btn-bg: transparent;
  --btn-fg: var(--ink);
  box-shadow: inset 0 0 0 2px var(--line);
}
.btn--ghost:hover { background: rgba(255, 253, 247, .7); }
.btn--sm { padding: .5rem .95rem; min-height: 40px; font-size: .86rem; }

/* --- chips (game pages, the leaderboard picker, board sizes) ------------- */

.chips { display: flex; flex-wrap: wrap; gap: .4rem; }

.chip {
  border: 0;
  padding: .45rem .8rem;
  min-height: 40px;
  border-radius: 999px;
  background: var(--cream-deep);
  color: var(--ink);
  font: inherit;
  font-size: .86rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
.chip:hover { background: var(--gold-light); }
.chip[aria-pressed="true"] { background: var(--green); color: #FFF8E7; }

/* --- surfaces ------------------------------------------------------------ */

.panel {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(192, 138, 30, .22);
  padding: 1.25rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .22rem .6rem;
  border-radius: 999px;
  background: rgba(192, 138, 30, .14);
  color: #8A6413;
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .04em;
}

/* --- game chrome (shared by every game page) ----------------------------- */

.topbar {
  position: sticky;
  top: 8px;
  z-index: 20;
  padding: .7rem 0;
  backdrop-filter: blur(10px);
  background: linear-gradient(var(--cream) 60%, rgba(251, 243, 226, 0));
}

.topbar__inner { display: flex; align-items: center; gap: .9rem; }

.back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  background: var(--paper);
  color: var(--green);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  font-size: 1.2rem;
  transition: transform .12s ease;
}
.back:hover { transform: translateX(-2px); }

.topbar__title { min-width: 0; }
.topbar__title h1 { font-size: clamp(1.05rem, 3.6vw, 1.4rem); }
.topbar__title .mal { display: block; font-size: .84rem; color: var(--muted); }

/* Heads-up display: a row of live stat tiles above the play area. */
.hud {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin: 0 0 1rem;
}
.hud__tile {
  flex: 1 1 0;
  min-width: 70px;
  padding: .55rem .7rem;
  border-radius: var(--radius-sm);
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  text-align: center;
}
.hud__label {
  display: block;
  font-size: .66rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.hud__value {
  display: block;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

/* Four tiles have to share a phone screen, so tighten the labels there. */
@media (max-width: 460px) {
  .hud { gap: .4rem; }
  .hud__tile { padding: .5rem .35rem; }
  .hud__label { font-size: .6rem; letter-spacing: .06em; }
  .hud__value { font-size: 1.25rem; }
}

.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* Tall enough that the start/result overlay always fits inside it, even on a
     narrow phone where the artwork itself scales down to almost nothing. */
  min-height: 340px;
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(192, 138, 30, .22);
  overflow: hidden;
}

.hint {
  margin: .9rem 0 0;
  text-align: center;
  font-size: .88rem;
  color: var(--muted);
}

.game-page { padding-bottom: 3rem; }

/* --- overlay shown before a round starts and after it ends --------------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  overflow: auto;
  padding: 1.5rem;
  text-align: center;
  background: rgba(251, 243, 226, .93);
  backdrop-filter: blur(3px);
  transition: opacity .25s ease;
}
.overlay[hidden] { display: none; }
/* auto margins centre the panel but still let it scroll when it is too tall,
   which flex/grid centring alone would clip. */
.overlay__inner { max-width: 34ch; margin: auto; }
.overlay h2 { font-size: clamp(1.4rem, 5vw, 2rem); margin-bottom: .5rem; }
.overlay p  { color: var(--muted); margin: 0 0 1.25rem; }

/* How to play, in both languages: Malayalam first because that is the house
   language, English under it a size down for whoever needs it. */
.rules { margin: 0 0 1.25rem; }
.rules__mal {
  display: block;
  font-family: var(--font-mal);
  font-size: 1.06em;
  line-height: 1.5;
  color: var(--ink);
}
.rules__en {
  display: block;
  margin-top: .45rem;
  font-size: .86em;
  line-height: 1.45;
  color: var(--muted);
}

.result-score {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.6rem, 12vw, 4rem);
  line-height: 1;
  color: var(--green);
  font-variant-numeric: tabular-nums;
}

/* --- misc ---------------------------------------------------------------- */

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* --- petal burst (see shared.js petalBurst) ------------------------------ */

.petal-layer {
  position: fixed;
  inset: 0;
  z-index: 60;
  overflow: hidden;
  pointer-events: none;
}
.petal-layer i {
  position: absolute;
  top: -6vh;
  width: 12px;
  height: 16px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  opacity: .95;
  animation: petal-fall linear forwards;
}
@keyframes petal-fall {
  to {
    transform: translate(var(--drift, 0), 112vh) rotate(var(--spin, 480deg));
    opacity: .2;
  }
}

/* --- party poppers (see shared.js popper) --------------------------------
   Paper fired up and inward from the bottom corners. The arc is faked with a
   single keyframe and an ease-out curve: fast out of the cone, slowing as it
   rises, then gone — close enough to a real popper at this speed. */

.popper-layer {
  position: fixed;
  inset: 0;
  z-index: 61;
  overflow: hidden;
  pointer-events: none;
}
.popper-layer i {
  position: absolute;
  bottom: -4vh;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  opacity: 0;
  animation: popper-fly cubic-bezier(.16, .74, .4, 1) forwards;
}
@keyframes popper-fly {
  0%   { opacity: 1; transform: translate(0, 0) rotate(0deg); }
  70%  { opacity: 1; }
  100% {
    opacity: 0;
    transform: translate(var(--fly-x, 40vw), var(--fly-y, -60vh)) rotate(var(--spin, 600deg));
  }
}

/* --- saving a result to the family leaderboard ---------------------------- */

.save-slot { margin-top: 1.1rem; }
.save-slot:empty { display: none; }

.save-score {
  display: flex;
  gap: .4rem;
  justify-content: center;
  flex-wrap: wrap;
}

.name-input {
  flex: 1 1 150px;
  max-width: 220px;
  min-height: 44px;
  padding: .55rem .9rem;
  border: 0;
  border-radius: 999px;
  background: var(--cream-deep);
  box-shadow: inset 0 0 0 2px rgba(192, 138, 30, .3);
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
}
.name-input::placeholder { color: var(--muted); font-weight: 500; }
.name-input:focus {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--green);
  background: var(--paper);
}

.save-note {
  margin: .6rem 0 0;
  min-height: 1.2rem;
  font-size: .88rem;
  color: var(--muted);
}
.save-note.is-bad { color: var(--chethi); }
.save-link { color: var(--green); font-weight: 700; }

/* --- who is playing, asked before the round rather than after -------------
   The name goes in first so the score can save itself at the end; nobody has
   to spot a form on the results screen to get on the board. */

/* Shown in place of a game's start button once play has closed. */
.closed-note {
  margin: 0 0 1.1rem;
  padding: .9rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--cream-deep);
  border: 1px dashed var(--gold);
}
.closed-note__mal {
  display: block;
  font-family: var(--font-mal);
  font-size: 1.02em;
  line-height: 1.5;
  color: var(--ink);
}
.closed-note__en {
  display: block;
  margin-top: .35rem;
  font-size: .86em;
  line-height: 1.45;
  color: var(--muted);
}

.name-slot { margin-top: 1.2rem; }

.name-first {
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.name-first__row {
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.name-first__label {
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
}
.name-first .name-input {
  flex: none;
  max-width: none;
  width: 100%;
}
.name-first .btn {
  width: 100%;
  margin-top: .2rem;
}

/* Link out to the leaderboard from the game chrome. */
.topbar__link {
  margin-left: auto;
  flex: none;
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--green);
  text-decoration: none;
  padding: .5rem .8rem;
  border-radius: 999px;
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}
.topbar__link:hover { background: var(--gold-light); }

/* --- overall standings (see scores.js standingsTable) ---------------------
   In base.css rather than board.css because the homepage shows this beside the
   champion and the results page shows it on its own, and only one of those
   loads the board stylesheet. */

.standings {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  background: var(--paper);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.standings th {
  padding: .6rem .7rem;
  text-align: left;
  font-size: .66rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.standings td {
  padding: .6rem .7rem;
  border-bottom: 1px solid rgba(43, 31, 18, .07);
}
.standings tr:last-child td { border-bottom: 0; }

.standings .col-place { width: 3.2rem; }
.standings .col-name { font-weight: 700; overflow-wrap: anywhere; }
.standings .col-num { text-align: right; width: 4.2rem; }
.standings th.col-num { text-align: right; }

.standings .rank-pill {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  padding: 0 .35rem;
  border-radius: 999px;
  background: var(--cream-deep);
  font-weight: 800;
  font-size: .85rem;
}
.standings .place-1 { background: rgba(239, 154, 30, .10); }
.standings .place-1 .rank-pill { background: var(--marigold); color: #3A2405; }
.standings .place-2 .rank-pill { background: #DFD6C2; }
.standings .place-3 .rank-pill { background: #E8CFAE; }

.standings .joint {
  margin-left: .35rem;
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--gold);
}

/* The date column is the first thing worth losing on a narrow phone; here it
   is the games count, which matters least of the three numbers. */
@media (max-width: 460px) {
  .standings th:last-child, .standings td:last-child { display: none; }
  .standings th, .standings td { padding-inline: .5rem; }
}
