/* KRUK GOLF CLUB — Scorecard App
   Dark, minimalist, Manors-Golf-inspired. Mobile-first. */

@font-face {
  font-family: "KrukTitle";
  src: url("assets/fonts/KCPixelHand.otf") format("opentype");
  font-display: swap;
}

@font-face {
  font-family: "KrukBody";
  src: url("assets/fonts/KCIllHand.otf") format("opentype");
  font-display: swap;
}

:root {
  --color-black: #0a0a0a;
  --color-offwhite: #f5f5f2;
  --color-green: #395e56;
  --color-green-light: #4f7a70;
  --color-gold: #c9a961; /* placeholder — TBD from footage sampling */

  --bg: var(--color-black);
  --fg: var(--color-offwhite);
  --fg-dim: #9a9a94;
  --surface: #141412;
  --surface-raised: #1c1c19;
  --border: #2a2a26;

  --font-title: "KrukTitle", ui-monospace, "SF Mono", Menlo, monospace;
  --font-body: "KrukBody", -apple-system, BlinkMacSystemFont, "Segoe UI",
    system-ui, sans-serif;

  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 8px;

  --tap-min: 56px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
}

/* Subtle grain/scanline texture — tasteful, not heavy-handed */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.035;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
}

.screen {
  display: none;
  flex-direction: column;
  gap: 20px;
  flex: 1;
  animation: fade-in 0.18s ease-out;
}

.screen.active {
  display: flex;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---- Typography ---- */

h1,
h2,
h3 {
  font-family: var(--font-title);
  letter-spacing: 0.02em;
  margin: 0;
  font-weight: 600;
}

.brand {
  text-align: center;
  padding: 32px 0 8px;
}

.brand .logo {
  width: auto;
  max-width: 220px;
  height: auto;
  max-height: 22vh;
  margin: 0 auto 10px;
  display: block;
}

.brand.brand-compact .logo {
  max-width: 140px;
  max-height: 96px;
}

.brand h1 {
  font-size: 1.5rem;
  color: var(--fg);
}

.brand h1.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.brand .tagline {
  color: var(--fg-dim);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  margin-top: 4px;
}

.screen-title {
  font-family: var(--font-title);
  font-size: 1.1rem;
  color: var(--fg);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.subtle {
  color: var(--fg-dim);
  font-size: 0.88rem;
}

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

button {
  font-family: var(--font-title);
  -webkit-appearance: none;
  border: none;
  cursor: pointer;
}

/* Player names/dates inside buttons are data, not button chrome —
   keep them in the body font for readability. */
.round-item .round-date,
.round-item .round-meta {
  font-family: var(--font-body);
}

.btn {
  min-height: var(--tap-min);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.08s ease, filter 0.15s ease;
  background: var(--surface-raised);
  color: var(--fg);
  border: 1px solid var(--border);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--color-green);
  border-color: var(--color-green-light);
  color: var(--color-offwhite);
  box-shadow: 0 0 0 1px rgba(79, 122, 112, 0.3), 0 4px 18px -6px rgba(57, 94, 86, 0.6);
}

.btn-gold {
  background: transparent;
  border: 1px solid var(--color-gold);
  color: var(--color-gold);
}

.btn-gold:active {
  background: rgba(201, 169, 97, 0.1);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
}

.btn-danger {
  background: transparent;
  border: 1px solid #6b3232;
  color: #d98c8c;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  min-height: 40px;
  padding: 8px 14px;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}

.btn:disabled {
  opacity: 0.35;
  pointer-events: none;
}

.btn-row {
  display: flex;
  gap: 10px;
}

.btn-row .btn {
  flex: 1;
}

/* ---- Inputs ---- */

input[type="text"],
input[type="number"],
input[type="password"] {
  width: 100%;
  min-height: var(--tap-min);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--fg);
  font-size: 1rem;
  padding: 12px 16px;
  font-family: var(--font-body);
}

input:focus {
  outline: none;
  border-color: var(--color-green-light);
}

label {
  font-family: var(--font-title);
  font-size: 0.8rem;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
  display: block;
}

.field {
  display: flex;
  flex-direction: column;
}

/* ---- Password gate ---- */

#screen-gate {
  justify-content: center;
  align-items: stretch;
}

.gate-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.gate-error {
  color: #d98c8c;
  font-size: 0.85rem;
  text-align: center;
  min-height: 1.2em;
}

/* ---- Home ---- */

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

.resume-banner {
  background: var(--surface);
  border: 1px solid var(--color-gold);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.player-row,
.par-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-row input,
.par-row .par-input {
  flex: 1;
}

.par-row .hole-label {
  width: 64px;
  color: var(--fg-dim);
  font-family: var(--font-title);
  font-size: 0.85rem;
  flex-shrink: 0;
}

.icon-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.list-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 40vh;
  overflow-y: auto;
  padding-right: 2px;
}

/* ---- Active hole / play screen ---- */

.round-name {
  text-align: center;
  font-family: var(--font-title);
  color: var(--color-gold);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.hole-header {
  text-align: center;
  padding: 10px 0 4px;
}

.hole-header .hole-num {
  font-family: var(--font-title);
  font-size: 3rem;
  line-height: 1;
  color: var(--fg);
}

.hole-header .hole-par {
  color: var(--color-gold);
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-top: 6px;
}

.player-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: opacity 0.15s ease, border-color 0.15s ease;
}

.player-card.done {
  opacity: 0.55;
  border-color: var(--color-green-light);
}

.player-card .player-info {
  flex: 1;
  min-width: 0;
}

.player-card .player-name {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-card .player-strokes {
  color: var(--fg-dim);
  font-size: 0.85rem;
  margin-top: 2px;
  font-family: var(--font-title);
}

.stroke-btn {
  width: var(--tap-min);
  height: var(--tap-min);
  border-radius: 50%;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--fg);
  font-size: 1.6rem;
  font-family: var(--font-title);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stroke-btn:active {
  background: var(--color-green);
  border-color: var(--color-green-light);
}

.holeout-btn {
  width: var(--tap-min);
  height: var(--tap-min);
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--color-gold);
  color: var(--color-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.holeout-btn svg {
  width: 22px;
  height: 22px;
}

.holeout-btn.active {
  background: var(--color-gold);
  color: var(--color-black);
}

.play-footer {
  display: flex;
  gap: 10px;
  margin-top: auto;
  padding-top: 10px;
}

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

.scorecard-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  -webkit-overflow-scrolling: touch;
}

table.scorecard {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}

table.scorecard th,
table.scorecard td {
  padding: 8px 10px;
  text-align: center;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

table.scorecard th {
  color: var(--fg-dim);
  font-weight: 500;
  font-family: var(--font-title);
  position: sticky;
  top: 0;
  background: var(--bg);
}

table.scorecard td.player-col,
table.scorecard th.player-col {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--bg);
  font-weight: 600;
}

table.scorecard td.total-col {
  font-weight: 700;
  color: var(--color-gold);
}

.score-mark {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  font-family: var(--font-title);
}

.score-mark.circle {
  border-radius: 50%;
  border: 1px solid var(--fg);
}

.score-mark.dbl-circle {
  border-radius: 50%;
  border: 1px solid var(--fg);
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 4px var(--fg);
}

.score-mark.square {
  border-radius: 3px;
  border: 1px solid var(--color-gold);
}

.score-mark.dbl-square {
  border-radius: 3px;
  border: 1px solid var(--color-gold);
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 4px var(--color-gold);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.75rem;
  color: var(--fg-dim);
  align-items: center;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---- History list ---- */

.round-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.round-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: stretch;
  width: 100%;
}

.round-item-main {
  flex: 1;
  min-width: 0;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  background: transparent;
  border: none;
}

.round-item .round-date {
  font-weight: 600;
}

.round-item .round-meta {
  color: var(--fg-dim);
  font-size: 0.8rem;
  margin-top: 2px;
}

.round-item .round-status {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-gold);
}

.round-item-delete {
  width: 52px;
  flex-shrink: 0;
  background: transparent;
  border: none;
  border-left: 1px solid var(--border);
  color: var(--fg-dim);
  font-size: 1.2rem;
}

.round-item-delete:active {
  color: #d98c8c;
}

.empty-state {
  text-align: center;
  color: var(--fg-dim);
  padding: 40px 16px;
  font-size: 0.9rem;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.top-bar .back-btn {
  color: var(--fg-dim);
  background: none;
  border: none;
  font-size: 0.9rem;
  padding: 8px 0;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-raised);
  border: 1px solid var(--color-gold);
  color: var(--fg);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--color-gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
