/* The badminton game, in a dialog opened from the footer's racket
   (js/rally.js). A warm card over a dimmed page; the court is pixel art,
   scaled with sharp pixels; all text is HTML. */

.rally {
  width: min(1280px, calc(100vw - 24px));
  max-width: none;
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 0;
  border-radius: clamp(14px, 1.6vw, 22px);
  background: linear-gradient(to bottom, #EEE6DA, #E5D8C6);
  color: var(--ink);
  box-shadow: 0 40px 90px -40px rgba(20, 16, 12, 0.6);
  overflow: auto;
}
.rally::backdrop {
  background: rgba(36, 34, 31, 0.55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.rally[open] { animation: rally-in 0.45s var(--ease-out); }
.rally[open]::backdrop { animation: rally-fade 0.35s ease; }
@keyframes rally-in { from { opacity: 0; translate: 0 18px; scale: 0.98; } }
@keyframes rally-fade { from { opacity: 0; } }

.rally__card { padding: clamp(18px, 3vw, 32px); }
.rally__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}
.rally__title {
  font-family: var(--display);
  font-weight: 400;
  font-size: var(--t-h2);
  line-height: 1;
  letter-spacing: -0.02em;
}
.rally__close {
  padding: 6px 10px;
  border: 1px solid rgba(36, 34, 31, 0.15);
  border-radius: 8px;
  background: transparent;
  font: inherit;
  font-size: var(--t-small);
  color: var(--ink);
  cursor: pointer;
}
.rally__close:hover { border-color: rgba(36, 34, 31, 0.35); }
.rally button:focus-visible { outline: 2px solid var(--terra); outline-offset: 2px; }

.rally__game { margin-top: 14px; outline: none; }
.rally__score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 18px;
  margin-bottom: 12px;
  font-size: var(--t-small);
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.rally__score b {
  display: inline-block;
  min-width: 1.2em;
  font-family: var(--display);
  font-weight: 400;
  font-size: var(--t-h2);
  letter-spacing: 0;
  color: var(--ink);
  text-align: center;
}
.rally__side { display: inline-flex; align-items: baseline; gap: 8px; }
.rally__side--gs b { color: var(--terra); }
.rally__to { font-size: var(--t-label); color: rgba(36, 34, 31, 0.45); }

.rally__holder { position: relative; display: grid; justify-items: center; }
.rally__stage {
  position: relative;
  max-width: 100%;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(36, 34, 31, 0.1), 0 6px 0 rgba(36, 34, 31, 0.06);
}
.rally[data-playing] .rally__stage { box-shadow: 0 0 0 1.5px rgba(182, 106, 75, 0.55), 0 6px 0 rgba(36, 34, 31, 0.06); }
.rally__court {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: manipulation;
}
.rally__msg {
  position: absolute;
  left: 50%;
  top: 12px;
  translate: -50% -6px;
  padding: 6px 12px 7px;
  border-radius: 8px;
  background: rgba(36, 34, 31, 0.86);
  color: var(--paper);
  font-size: var(--t-small);
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, translate 0.3s var(--ease-out);
}
.rally__msg[data-on] { opacity: 1; translate: -50% 0; }
.rally__paused {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(243, 239, 231, 0.6);
  color: var(--ink);
  font: inherit;
  font-size: var(--t-small);
  font-weight: 500;
  cursor: pointer;
}
.rally__paused[hidden] { display: none; }

.rally__panel {
  position: absolute;
  left: 50%;
  top: 5%;
  translate: -50% 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 16px 20px 14px;
  border-radius: 12px;
  background: rgba(243, 239, 231, 0.94);
  box-shadow: 0 0 0 1px rgba(36, 34, 31, 0.08), 0 16px 30px -20px rgba(60, 40, 28, 0.5);
}
.rally__panel[hidden] { display: none; }
.rally__panel-title {
  font-family: var(--display);
  font-size: var(--t-h3);
  line-height: 1.1;
  text-align: center;
}
.rally__start {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-size: var(--t-small);
  font-weight: 500;
  cursor: pointer;
}
.rally__start::after {
  content: "";
  width: 7px;
  height: 7px;
  background: var(--terra);
  transition: translate 0.35s var(--ease-out);
}
.rally__start:hover::after { translate: 3px 0; }
.rally__looks {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 12px;
  font-size: var(--t-label);
}
.rally__looks-label { color: var(--ink-soft); }
.rally__looks-set { display: inline-flex; gap: 4px; }
.rally__looks button {
  padding: 4px 8px 5px;
  border: 1px solid rgba(36, 34, 31, 0.14);
  border-radius: 7px;
  background: transparent;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
}
.rally__looks button[aria-pressed="true"] { background: rgba(216, 200, 180, 0.7); border-color: rgba(182, 106, 75, 0.5); }
.rally__looks .rally__swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 6px;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(36, 34, 31, 0.15);
}
.rally__looks .rally__swatch[aria-pressed="true"] { background: var(--c); box-shadow: 0 0 0 2px #F3EFE7, 0 0 0 3.5px var(--terra); border-color: transparent; }

.rally__keys {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 18px;
  margin: 14px auto 0;
  font-size: var(--t-small);
  color: var(--ink-soft);
  text-align: center;
}
.rally__keys kbd {
  display: inline-block;
  min-width: 1.6em;
  margin-right: 3px;
  padding: 1px 5px 2px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: inset 0 0 0 1px rgba(36, 34, 31, 0.14), 0 1px 0 rgba(36, 34, 31, 0.12);
  font: inherit;
  font-size: var(--t-label);
  color: var(--ink);
}
.rally__tip { flex-basis: 100%; }

.rally__touch { display: none; }
@media (pointer: coarse) {
  .rally__touch {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 14px;
    user-select: none;
    -webkit-user-select: none;
  }
  .rally__pad { display: flex; gap: 10px; }
  .rally__touch button {
    min-width: 58px;
    height: 54px;
    padding: 0 14px;
    border: 0;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.6);
    box-shadow: inset 0 0 0 1px rgba(36, 34, 31, 0.12), 0 2px 0 rgba(36, 34, 31, 0.1);
    font: inherit;
    font-size: var(--t-small);
    font-weight: 500;
    color: var(--ink);
    touch-action: none;
  }
  .rally__touch .rally__hit { background: var(--ink); color: var(--paper); min-width: 160px; height: 60px; }
}

.rally__turn { display: none; }

/* ---------- phones: the game takes the whole screen ---------- */

@media (max-width: 640px), (pointer: coarse) and (max-height: 500px) {
  .rally {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    border-radius: 0;
  }
  .rally__card {
    padding: max(16px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  .rally__stage { border-radius: 6px; }
}
@media (max-width: 640px) {
  .rally__panel { position: static; translate: none; margin-top: 12px; max-width: 100%; }
  /* upright, the court can only be as wide as the phone: edge to edge */
  .rally__holder { margin: 0 calc(-1 * max(12px, env(safe-area-inset-left))); }
  .rally__stage { border-radius: 0; box-shadow: 0 1px 0 rgba(36, 34, 31, 0.1), 0 -1px 0 rgba(36, 34, 31, 0.1); }
  .rally__score { margin: 18px 0 16px; }
  .rally__score b { font-size: var(--t-h2); }
  .rally__touch .rally__hit { min-width: 0; width: min(100%, 320px); height: 76px; font-size: var(--t-body); }
}
/* holding the phone upright: a nudge to turn it */
@media (pointer: coarse) and (orientation: portrait) {
  .rally__turn {
    display: block;
    margin-top: 12px;
    font-size: var(--t-small);
    color: var(--ink-soft);
    text-align: center;
  }
  .rally__keys { display: none; }
}
/* sideways: the court fills the height, the Hit button sits beside it */
@media (pointer: coarse) and (max-height: 500px) and (orientation: landscape) {
  .rally__card { padding-top: 10px; padding-bottom: 10px; }
  .rally__head { position: absolute; top: 10px; right: max(12px, env(safe-area-inset-right)); z-index: 2; }
  .rally__title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .rally__game {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "score score" "court hit";
    align-items: center;
    gap: 6px 16px;
    margin-top: 0;
  }
  .rally__score { grid-area: score; margin-bottom: 0; }
  .rally__score b { font-size: var(--t-h3); }
  .rally__holder { grid-area: court; }
  .rally__panel { position: absolute; top: 8%; margin: 0; translate: -50% 0; max-width: calc(100% - 24px); }
  .rally__touch { grid-area: hit; margin: 0; }
  .rally__touch .rally__hit { min-width: 0; width: 112px; height: 112px; border-radius: 50%; }
  .rally__keys { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .rally[open], .rally[open]::backdrop { animation: none; }
}
