/* Play Nine Score Keeper
   Yellow like the box, green like the fairway, a little unhinged like game night. */

:root {
  --yellow: #FFD400;
  --yellow-deep: #F2B600;
  --yellow-pale: #FFF3A6;
  --turf: #2E8B3A;
  --turf-dark: #1B5E26;
  --turf-light: #6CC24A;
  --ink: #1E1E1A;
  --paper: #FFFDF2;
  --flag-red: #E23B2E;
  --sky: #2F80ED;
  --radius: 18px;
  --shadow: 0 6px 0 var(--turf-dark);
  --font-fun: "Luckiest Guy", "Arial Black", Impact, sans-serif;
  --font-body: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.45;
  color: var(--ink);
  background-color: var(--yellow);
  /* golf ball dimples */
  background-image:
    radial-gradient(circle at 25% 25%, rgba(255, 255, 255, 0.35) 0 3px, transparent 4px),
    radial-gradient(circle at 75% 75%, rgba(242, 182, 0, 0.45) 0 3px, transparent 4px);
  background-size: 28px 28px;
  overflow-x: hidden;
}

[hidden] {
  display: none !important;
}

button,
input {
  font: inherit;
  color: inherit;
}

/* ---------- Header ---------- */

.masthead {
  position: relative;
  padding: 14px 16px 28px;
  text-align: center;
  color: #fff;
  background:
    repeating-linear-gradient(90deg, var(--turf) 0 34px, #34A042 34px 68px);
  border-bottom: 6px solid var(--turf-dark);
  border-radius: 0 0 50% 50% / 0 0 28px 28px;
}

.back-link {
  position: absolute;
  top: 12px;
  left: 14px;
  font-weight: 900;
  font-size: 0.85rem;
  color: #fff;
  text-decoration: none;
  background: rgba(0, 0, 0, 0.22);
  padding: 6px 12px;
  border-radius: 999px;
}

.back-link:hover,
.back-link:focus-visible {
  background: rgba(0, 0, 0, 0.4);
}

.logo {
  display: inline-grid;
  grid-template-columns: auto auto;
  align-items: end;
  column-gap: 8px;
  margin-top: 36px;
  font-family: var(--font-fun);
  line-height: 0.9;
  transform: rotate(-3deg);
  animation: wobble 5s ease-in-out infinite;
}

.logo-flag {
  grid-row: 1 / span 2;
  font-size: 3.2rem;
  filter: drop-shadow(3px 3px 0 var(--turf-dark));
}

.logo-play {
  font-size: 1.6rem;
  color: var(--yellow);
  text-align: left;
  text-shadow: 3px 3px 0 var(--turf-dark);
}

.logo-nine {
  font-size: 3.4rem;
  color: #fff;
  text-shadow: 4px 4px 0 var(--flag-red), 7px 7px 0 var(--turf-dark);
  letter-spacing: 1px;
}

.logo-sub {
  grid-column: 1 / span 2;
  margin-top: 8px;
  justify-self: center;
  font-size: 1rem;
  letter-spacing: 3px;
  color: var(--ink);
  background: var(--yellow);
  padding: 6px 12px 3px;
  border-radius: 8px;
  transform: rotate(2deg);
  box-shadow: 3px 3px 0 var(--turf-dark);
}

.tagline {
  margin: 16px auto 0;
  max-width: 30ch;
  font-weight: 900;
  font-size: 0.95rem;
  min-height: 2.8em;
  text-shadow: 1px 1px 0 var(--turf-dark);
}

@keyframes wobble {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(2deg) scale(1.03); }
}

/* ---------- Layout ---------- */

.wrap {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px 8px;
}

.card {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  margin-bottom: 22px;
}

.card-tilt-left {
  transform: rotate(-0.8deg);
}

.card-tilt-right {
  transform: rotate(0.8deg);
}

.card-title {
  font-family: var(--font-fun);
  font-weight: 400;
  font-size: 1.8rem;
  line-height: 1.1;
  margin: 0 0 14px;
  color: var(--turf-dark);
}

.card-title-sm {
  font-size: 1.35rem;
}

.hint {
  margin: -8px 0 10px;
  font-size: 0.85rem;
  color: #5b5b50;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 52px;
  padding: 10px 20px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  font-weight: 900;
  font-size: 1.05rem;
  cursor: pointer;
  background: #fff;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}

.btn:focus-visible,
.count-btn:focus-visible,
.hole-jump:focus-visible,
.dot-btn:focus-visible {
  outline: 4px solid var(--sky);
  outline-offset: 2px;
}

.btn-go {
  background: var(--turf);
  color: #fff;
  text-shadow: 1px 1px 0 var(--turf-dark);
}

.btn-big {
  width: 100%;
  min-height: 62px;
  font-family: var(--font-fun);
  font-weight: 400;
  font-size: 1.5rem;
  letter-spacing: 1px;
}

.btn-ghost {
  background: var(--yellow-pale);
}

.btn-link {
  display: block;
  margin: 0 auto 12px;
  min-height: 44px;
  border: none;
  box-shadow: none;
  background: none;
  text-decoration: underline;
  font-weight: 700;
  color: #5b4a00;
}

.btn-link:active {
  transform: none;
  box-shadow: none;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 12px;
  margin-top: 16px;
}

.btn-stack {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

/* ---------- Setup ---------- */

.field {
  border: none;
  margin: 0 0 20px;
  padding: 0;
}

.field-label {
  display: block;
  padding: 0;
  margin-bottom: 8px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.85rem;
}

.count-picker {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.count-btn {
  min-height: 56px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  aspect-ratio: 1;
  background: #fff;
  font-family: var(--font-fun);
  font-size: 1.6rem;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.count-btn[aria-checked="true"] {
  background: var(--turf);
  color: #fff;
  transform: scale(1.08) rotate(-6deg);
}

.name-list {
  display: grid;
  gap: 10px;
}

.name-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.name-badge {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  font-family: var(--font-fun);
  font-size: 1.1rem;
  color: #fff;
  padding-top: 3px;
}

.text-input,
.score-input {
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  font-size: 1.1rem; /* 16px+ keeps iOS from zooming */
  font-weight: 700;
}

.text-input:focus,
.score-input:focus {
  outline: none;
  border-color: var(--turf);
  box-shadow: 0 0 0 4px var(--turf-light);
}

.form-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--flag-red);
  color: #fff;
  font-weight: 900;
}

/* ---------- Game ---------- */

.hole-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 4px 0 12px;
}

.hole-flag {
  position: relative;
  width: 44px;
  height: 64px;
}

.hole-flag::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 0;
  width: 5px;
  height: 64px;
  background: var(--ink);
  border-radius: 3px;
}

.hole-flag span {
  position: absolute;
  left: 11px;
  top: 3px;
  width: 32px;
  height: 22px;
  background: var(--flag-red);
  border: 3px solid var(--ink);
  border-left: none;
  border-radius: 0 6px 6px 0;
  transform-origin: left center;
  animation: flap 1.2s ease-in-out infinite;
}

@keyframes flap {
  0%, 100% { transform: skewY(0deg) scaleX(1); }
  50% { transform: skewY(-8deg) scaleX(0.85); }
}

.hole-text {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--font-fun);
}

.hole-label,
.hole-of {
  font-size: 1.5rem;
  color: var(--turf-dark);
}

.hole-number {
  font-size: 4.2rem;
  line-height: 1;
  color: #fff;
  text-shadow: 4px 4px 0 var(--turf-dark);
}

.hole-number.pop {
  animation: pop 0.45s cubic-bezier(0.3, 1.8, 0.5, 1);
}

@keyframes pop {
  0% { transform: scale(0.3) rotate(-30deg); }
  100% { transform: scale(1) rotate(0); }
}

.hole-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  list-style: none;
  padding: 0;
  margin: 0 0 18px;
}

.dot-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: #fff;
  font-weight: 900;
  font-size: 0.8rem;
  cursor: pointer;
}

.dot-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.dot-btn.is-done {
  background: var(--turf-light);
}

.dot-btn.is-current {
  background: var(--flag-red);
  color: #fff;
  transform: scale(1.2);
}

.hole-inputs {
  display: grid;
  gap: 12px;
}

.score-row {
  display: grid;
  grid-template-columns: auto 1fr 96px;
  align-items: center;
  gap: 10px;
}

.score-who {
  min-width: 0;
}

.score-name {
  display: block;
  font-weight: 900;
  font-size: 1.1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-thru {
  display: block;
  font-size: 0.85rem;
  color: #5b5b50;
}

.score-input {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 900;
  padding: 8px 6px;
  -moz-appearance: textfield;
  appearance: textfield;
}

.score-input::-webkit-outer-spin-button,
.score-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.score-input.is-invalid {
  border-color: var(--flag-red);
  box-shadow: 0 0 0 4px rgba(226, 59, 46, 0.35);
  animation: shake 0.35s;
}

@keyframes shake {
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.quip {
  margin: -6px 0 22px;
  padding: 14px 16px;
  border: 3px dashed var(--turf-dark);
  border-radius: var(--radius);
  background: var(--yellow-pale);
  font-weight: 900;
  font-size: 1.05rem;
  text-align: center;
  transform: rotate(-1deg);
  animation: slide-in 0.4s cubic-bezier(0.3, 1.6, 0.5, 1);
}

@keyframes slide-in {
  from { opacity: 0; transform: translateY(-12px) rotate(-4deg); }
  to { opacity: 1; transform: rotate(-1deg); }
}

/* ---------- Scorecard table ---------- */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.scorecard {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.95rem;
  text-align: center;
}

.scorecard th,
.scorecard td {
  padding: 6px 2px;
  border-bottom: 1px solid #e5dfb8;
}

.scorecard thead th {
  font-weight: 900;
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-bottom: 3px solid var(--ink);
}

.scorecard .col-hole {
  width: 48px;
}

.scorecard tbody td {
  font-weight: 700;
}

.scorecard tr.is-current td,
.scorecard tr.is-current th {
  background: var(--yellow-pale);
}

.scorecard tfoot td,
.scorecard tfoot th {
  border-top: 3px solid var(--ink);
  border-bottom: none;
  font-family: var(--font-fun);
  font-weight: 400;
  font-size: 1.3rem;
  padding-top: 8px;
}

.scorecard .is-best {
  color: var(--turf);
  font-weight: 900;
}

.scorecard .is-neg {
  color: var(--sky);
}

.hole-jump {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: #fff;
  font-weight: 900;
  cursor: pointer;
}

.hole-jump:disabled {
  border-color: #c9c3a0;
  color: #9a9480;
  cursor: default;
}

/* ---------- Final ---------- */

.winner-card {
  text-align: center;
  background:
    repeating-linear-gradient(45deg, var(--paper) 0 18px, #FFF8D6 18px 36px);
}

.winner-kicker {
  margin: 0;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.8rem;
}

.winner-title {
  font-family: var(--font-fun);
  font-weight: 400;
  font-size: 2.4rem;
  line-height: 1.05;
  margin: 8px 0 18px;
  color: var(--turf);
  text-shadow: 3px 3px 0 var(--yellow);
  overflow-wrap: anywhere;
  animation: pop 0.6s cubic-bezier(0.3, 1.8, 0.5, 1);
}

.podium {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
  text-align: left;
}

.podium-row {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #fff;
}

.podium-row.is-winner {
  background: var(--yellow);
  transform: scale(1.03) rotate(-1deg);
  box-shadow: 0 4px 0 var(--ink);
}

.podium-medal {
  font-size: 1.8rem;
  text-align: center;
}

.podium-name {
  font-weight: 900;
  font-size: 1.1rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.podium-title {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: #5b5b50;
}

.podium-total {
  font-family: var(--font-fun);
  font-size: 1.8rem;
}

/* ---------- Clubhouse stats ---------- */

.clubhouse {
  background: #fff;
}

.stats-empty {
  margin: 0;
  font-weight: 700;
}

.records {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 0.95rem;
}

.records th,
.records td {
  padding: 8px 4px;
  border-bottom: 1px solid #e8e8e0;
  text-align: center;
}

.records th:first-child,
.records td:first-child {
  text-align: left;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.records thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 3px solid var(--ink);
}

.records td:first-child {
  font-weight: 900;
}

.supers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.super {
  padding: 12px 10px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: var(--yellow-pale);
  text-align: center;
}

.super:nth-child(odd) {
  transform: rotate(-1.2deg);
}

.super:nth-child(even) {
  transform: rotate(1.2deg);
  background: #E4F5DC;
}

.super-emoji {
  display: block;
  font-size: 1.9rem;
  line-height: 1;
}

.super-title {
  display: block;
  margin-top: 6px;
  font-family: var(--font-fun);
  font-size: 1.05rem;
  color: var(--turf-dark);
}

.super-who {
  display: block;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.super-detail {
  display: block;
  font-size: 0.8rem;
  color: #5b5b50;
}

.section-sub {
  font-family: var(--font-fun);
  font-weight: 400;
  font-size: 1.2rem;
  margin: 0 0 10px;
  color: var(--turf-dark);
}

/* ---------- Footer & confetti ---------- */

.foot {
  padding: 8px 16px 32px;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: #5b4a00;
}

.foot p {
  margin: 4px 0;
}

#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

@media (max-width: 360px) {
  .logo-nine { font-size: 2.8rem; }
  .hole-number { font-size: 3.4rem; }
  .score-row { grid-template-columns: auto 1fr 80px; }
  .supers { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- Dealer indicator ---------- */

.dealer-callout {
  display: table;
  margin-bottom: 8px;
  padding: 5px 12px 2px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  color: var(--ink);
  font-size: 1rem;
  transform: rotate(-2deg);
  box-shadow: 2px 2px 0 var(--ink);
}

.dealer-chip {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--flag-red);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  vertical-align: 2px;
}
