/* Night Match theme. Mobile-first; desktop layout kicks in at 900px. */

:root {
  --bg: #07130f;
  --panel: #0e211a;
  --border: #1d3a2e;
  --ink: #eaf5ee;
  --muted: #9db8a9;
  --lime: #c6f432;
  --lime-ink: #0a1a08;
  --coral: #ff7a59;
  --coral-ink: #2a0d05;
  --gutter: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'IBM Plex Sans Thai', system-ui, sans-serif;
  overflow-x: hidden;
  width: 100%;
}

/* Root cause of the mobile overflow bug: Thai script has no spaces between words, so long runs
   of Thai text (or a mixed Thai+ASCII token like a club/player name) have no natural break point.
   Inside a flex/grid item the default `min-width: auto` sizes to that unbreakable content, which
   can exceed the viewport. `overflow-wrap: anywhere` lets the browser break anywhere as a last
   resort (after trying normal word breaks first), and `min-width: 0` on flex children removes the
   auto-content-based minimum so they can actually shrink to fit. */
* { min-width: 0; }
body { overflow-wrap: anywhere; }

/* Owner addition 1: textured background — layered CSS/SVG, no raster image, kept behind content
   via a dedicated fixed layer (not `background-attachment: fixed` on body, which repaints on
   scroll on iOS). Contrast of foreground text is unaffected — the layer sits at z-index -1 while
   `.app-shell` content sits at z-index 1 on the opaque `--bg` colour. */
.bg-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-color: var(--bg);
  background-image:
    radial-gradient(700px 500px at -5% -10%, rgba(198, 244, 50, 0.22), transparent 55%),
    radial-gradient(600px 500px at 105% 105%, rgba(46, 196, 182, 0.14), transparent 55%),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.045) 0 1px, transparent 1px 6px),
    repeating-linear-gradient(0deg, rgba(198,244,50,0.06) 0 1px, transparent 1px 48px),
    repeating-linear-gradient(90deg, rgba(198,244,50,0.06) 0 1px, transparent 1px 48px),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Ccircle cx='2' cy='2' r='1' fill='%23c6f432' fill-opacity='0.10'/%3E%3C/svg%3E");
}

h1, h2, h3, h4, .xpts-num, .btn, .step-icon {
  font-family: 'Chakra Petch', system-ui, sans-serif;
}

.app-shell { max-width: 480px; margin: 0 auto; padding: 0 var(--gutter) 40px; box-sizing: border-box; overflow-x: clip; position: relative; z-index: 1; }

.view { padding-top: 20px; }

.site-header { text-align: center; margin-bottom: 12px; position: relative; }
.icon-btn {
  position: absolute; top: 0; right: 0;
  width: 44px; height: 44px; min-height: 44px;
  border-radius: 50%; border: 1px solid var(--border); background: var(--panel);
  color: var(--ink); font-weight: 700; font-size: 1.1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }
.site-title { font-size: 1.4rem; font-weight: 700; margin: 0; letter-spacing: 0.02em; }
.season-tag, .gw-deadline { color: var(--muted); font-size: 0.85rem; margin: 4px 0 0; }

/* ---------- Input state ---------- */
.input-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.field-label { font-size: 0.9rem; color: var(--muted); }

#team-id-input {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--ink);
  font-size: 1.5rem;
  padding: 14px 16px;
  min-height: 48px;
  text-align: center;
  letter-spacing: 0.05em;
}
#team-id-input:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}
#team-id-input.shake { animation: shake 0.5s; border-color: var(--coral); }

.input-error {
  color: var(--coral);
  background: var(--coral-ink);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.85rem;
  margin: 0;
}

.btn {
  min-height: 48px;
  border-radius: 12px;
  border: none;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  padding: 0 20px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-primary { background: var(--lime); color: var(--lime-ink); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--panel); color: var(--ink); border: 1px solid var(--border); }
.btn:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }

.remember-row { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--muted); }
.remember-row input { width: 20px; height: 20px; }
.saved-line { color: var(--muted); font-size: 0.85rem; margin: 0; }

.guide { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 12px 16px; }
.guide summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.guide-steps { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 16px; }
.guide-steps li { display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 4px 10px; align-items: start; }
.guide-steps li > :not(.guide-icon) { grid-column: 2; min-width: 0; }
.guide-icon { width: 40px; height: 40px; color: var(--lime); grid-column: 1; grid-row: 1 / -1; overflow: visible; }
.guide-icon-inv { fill: var(--panel); }
.guide-steps p { margin: 0; font-size: 0.9rem; }
.guide-steps strong.lime { color: var(--lime); font-weight: 700; }
.guide-shot { display: block; width: 100%; max-width: 420px; height: auto; margin: 8px 0 4px; border-radius: 10px; border: 1px solid var(--border); }
.guide-note { color: var(--muted); font-size: 0.8rem !important; }

/* ---------- Loading state ---------- */
.pitch-skeleton {
  height: 160px;
  border-radius: 22px;
  background: repeating-linear-gradient(180deg, #0f4a33 0 20px, #0c3f2b 20px 40px);
  position: relative;
  overflow: hidden;
  margin-top: 40px;
}
.skeleton-ball {
  width: 20px; height: 20px; border-radius: 50%; background: var(--lime);
  position: absolute; top: 50%; left: -20px;
  animation: roll 1.4s linear infinite;
}
@keyframes roll { to { left: 105%; transform: rotate(360deg); } }
.loading-text { text-align: center; color: var(--muted); margin-top: 16px; }

/* ---------- Result state ---------- */
.team-line { color: var(--muted); font-size: 0.9rem; text-align: center; margin: 4px 0; }
.result-h1 { font-size: 1.2rem; text-align: center; margin: 8px 0 4px; }
.result-h1-sub { font-size: 13px; color: var(--muted); text-align: center; margin: 0 0 16px; }

.xpts-strip { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 16px; }
.xpts-num { font-size: 1.6rem; font-weight: 600; color: var(--muted); }
.xpts-num-main { color: var(--ink); }
.xpts-arrow { color: var(--muted); }
.delta-pill { background: var(--lime); color: var(--lime-ink); border-radius: 999px; padding: 2px 10px; font-weight: 600; font-size: 0.85rem; }

.xpts-caption { text-align: center; color: var(--muted); font-size: 0.8rem; margin: 0 0 12px; }

/* ---------- Calculator, not a guru: notice card ---------- */
.calc-notice {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--lime);
  border-radius: 14px; padding: 14px; margin-bottom: 16px;
}
.calc-notice-icon { width: 26px; height: 26px; flex-shrink: 0; color: var(--lime); margin-top: 2px; }
.calc-notice-body { min-width: 0; flex: 1; }
.calc-notice-title { font-family: 'Chakra Petch', system-ui, sans-serif; font-size: 16px; font-weight: 700; margin: 0 0 6px; color: var(--ink); }
.calc-notice-lines { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.calc-notice-lines li { font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.calc-notice-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn-outline { background: transparent; color: var(--lime); border: 1.5px solid var(--lime); min-height: 44px; }
.link-btn {
  background: none; border: none; color: var(--muted); text-decoration: underline;
  min-height: 44px; padding: 0 4px; cursor: pointer; font-size: 0.85rem;
}
.link-btn:focus-visible, .btn-outline:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }

.segmented { display: flex; background: var(--panel); border-radius: 999px; padding: 4px; margin-bottom: 16px; border: 1px solid var(--border); }
.segmented-btn { flex: 1; background: transparent; border: none; color: var(--muted); min-height: 44px; border-radius: 999px; font-weight: 600; cursor: pointer; }
.segmented-btn[aria-pressed="true"] { background: var(--lime); color: var(--lime-ink); }

.pitches-wrap { display: flex; flex-direction: column; min-width: 0; }
.pitch-col { display: none; flex-direction: column; gap: 8px; min-width: 0; }
.pitches-wrap[data-active="current"] .pitch-col-current { display: flex; }
.pitches-wrap[data-active="recommended"] .pitch-col-recommended { display: flex; }

.pitch {
  background: repeating-linear-gradient(180deg, #0f4a33 0 62px, #0c3f2b 62px 124px);
  border-radius: 22px;
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  overflow: hidden;
  min-width: 0;
  border: 2px solid rgba(255,255,255,0.06);
}
.pitch::before {
  content: '';
  position: absolute; inset: 8px;
  border: 2px solid rgba(255,255,255,0.28);
  border-radius: 14px;
  pointer-events: none;
}
.pitch-row { display: flex; justify-content: center; gap: 6px; z-index: 1; min-width: 0; }

@keyframes shimmer-sweep {
  from { transform: translateX(-120%); }
  to { transform: translateX(120%); }
}
.pitch.fx-shimmer::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 40%, rgba(255,255,255,0.18) 50%, transparent 60%);
  animation: shimmer-sweep 900ms ease-out;
  pointer-events: none;
}

.player-card { display: flex; flex-direction: column; align-items: center; flex: 1 1 0; min-width: 0; max-width: 72px; position: relative; }
.badge { width: 38px; height: 38px; max-width: 100%; border-radius: 50%; overflow: hidden; background: var(--panel); display: flex; align-items: center; justify-content: center; }
.badge-img { width: 100%; height: 100%; object-fit: contain; }
.badge.kit { background: var(--kit-bg, #333); }
.kit-code { color: var(--kit-ink, #fff); font-size: 0.65rem; font-weight: 700; }
.cv-badge {
  position: absolute; top: -4px; right: 6px;
  background: var(--lime); color: var(--lime-ink); border-radius: 50%;
  width: 16px; height: 16px; font-size: 0.6rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.player-name { font-size: 0.65rem; color: var(--ink); margin-top: 4px; text-align: center; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-meta { font-size: 0.55rem; color: rgba(234,245,238,0.7); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 0.55rem; border-radius: 6px; padding: 1px 5px; margin-top: 2px; }
.tag-in { background: var(--lime); color: var(--lime-ink); }
.tag-out { background: var(--coral-ink); color: var(--coral); }
.tag-bench { background: rgba(255, 191, 0, 0.14); color: #ffbf00; }

@keyframes rise { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes pulse-in { 0% { box-shadow: 0 0 0 0 rgba(198,244,50,0.6); } 100% { box-shadow: 0 0 0 10px rgba(198,244,50,0); } }
@keyframes pulse-out { 0% { box-shadow: 0 0 0 0 rgba(255,122,89,0.6); } 100% { box-shadow: 0 0 0 10px rgba(255,122,89,0); } }
@keyframes pop { 0% { transform: scale(0.4); } 60% { transform: scale(1.2); } 100% { transform: scale(1); } }
.fx-rise { animation: rise 400ms ease-out; }
.fx-pulse-in .badge { animation: pulse-in 900ms ease-out; }
.fx-pulse-out { opacity: 0.6; }
.fx-dim { opacity: 0.6; }
.fx-pop { animation: pop 400ms ease-out; }
.fx-hl-in .badge { box-shadow: 0 0 0 3px var(--lime); }
.fx-hl-out .badge { box-shadow: 0 0 0 3px var(--coral); }

.bench { display: flex; justify-content: center; gap: 6px; background: var(--panel); border-radius: 14px; padding: 10px 8px; border: 1px solid var(--border); min-width: 0; }

.alerts-list { list-style: none; margin: 16px 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.alert-item { background: rgba(255, 191, 0, 0.12); color: #ffbf00; border-radius: 10px; padding: 8px 12px; font-size: 0.85rem; }

.section-title { font-size: 1rem; margin: 20px 0 10px; }
.fold { margin: 12px 0; }
.fold[hidden] { display: none; }
.fold-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; padding: 0 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; cursor: pointer; list-style: none; }
.fold-head::-webkit-details-marker { display: none; }
.fold-head::after { content: ''; width: 8px; height: 8px; flex-shrink: 0; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform 150ms ease-out; }
.fold[open] > .fold-head::after { transform: rotate(-135deg); }
.fold-head:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }
.fold-head .section-title { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.fold[open] > .fold-head { margin-bottom: 8px; }
.steps-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.step { display: flex; gap: 10px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; align-items: flex-start; }
.step-icon { font-size: 1.1rem; color: var(--lime); width: 24px; flex-shrink: 0; text-align: center; }
.step-do { font-weight: 600; font-size: 0.9rem; }
.step-why { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }

.moves-list { display: flex; flex-direction: column; gap: 10px; }
.move-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; position: relative; }
.move-side { display: inline-block; }
.move-arrow { display: inline-block; margin: 0 8px; color: var(--muted); }
.move-name { font-weight: 600; font-size: 0.9rem; }
.move-price { font-size: 0.8rem; color: var(--muted); }
.move-why { font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
.hit-badge { position: absolute; top: 8px; right: 12px; background: var(--coral-ink); color: var(--coral); border-radius: 6px; padding: 1px 6px; font-size: 0.75rem; font-weight: 700; }

.chip-note { background: var(--panel); border-left: 3px solid var(--lime); padding: 8px 12px; border-radius: 8px; font-size: 0.85rem; }

.donate-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 16px; text-align: center; margin: 20px 0; }
.donate-card p { margin: 0 0 12px; }
.donate-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 10; padding: 20px; }
.modal-panel { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 20px; max-width: 320px; width: 100%; text-align: center; position: relative; }
.modal-close { position: absolute; top: 8px; right: 8px; background: transparent; border: none; color: var(--ink); font-size: 1.4rem; cursor: pointer; width: 44px; height: 44px; }
.donate-qr-img { width: 100%; border-radius: 8px; margin: 10px 0; background: #fff; }

/* ---------- Big disclaimer box (bottom of page + inside method panel) ---------- */
.disclaimer-box {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--panel); border: 1.5px solid rgba(198, 244, 50, 0.35); border-radius: 14px;
  padding: 16px; margin: 20px 0;
}
.disclaimer-icon { width: 22px; height: 22px; flex-shrink: 0; color: var(--lime); margin-top: 1px; }
.disclaimer-text { margin: 0; font-size: 13.5px; line-height: 1.6; color: var(--muted); }
.disclaimer-text .disclaimer-lead { font-size: 15px; font-weight: 600; color: var(--ink); }

/* ---------- Method panel: bottom sheet (mobile) / centred modal (desktop) ---------- */
.modal-backdrop { position: absolute; inset: 0; }
.method-modal { padding: 0; align-items: flex-end; }
.method-sheet {
  position: relative; background: var(--panel); border: 1px solid var(--border);
  width: 100%; max-height: 85vh; border-radius: 22px 22px 0 0;
  display: flex; flex-direction: column; overflow: hidden;
}
.method-sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 10px auto 0; flex-shrink: 0; }
.method-sheet-body { overflow-y: auto; padding: 8px 20px 24px; }
.method-panel-title { font-size: 1.1rem; margin: 8px 0 12px; }
.method-lead { font-size: 15px; font-weight: 700; color: var(--ink); margin: 0 0 12px; line-height: 1.5; }
.method-list { margin: 0 0 16px; padding-left: 22px; display: flex; flex-direction: column; gap: 10px; }
.method-list li { font-size: 0.9rem; color: var(--ink); line-height: 1.5; }
.method-list li::marker { color: var(--lime); font-weight: 700; }
.method-divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.method-sub-title { font-size: 0.95rem; margin: 0 0 10px; }
.method-limits { margin: 0 0 4px; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.method-limits li { font-size: 0.85rem; color: var(--muted); line-height: 1.5; }

@media (min-width: 900px) {
  .method-modal { align-items: center; }
  .method-sheet { max-width: 560px; border-radius: 16px; max-height: 80vh; }
  .method-sheet-handle { display: none; }
}

.center-text { text-align: center; }
.result-footer { text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; margin-top: 20px; }
.footer-meta { color: var(--muted); font-size: 0.75rem; margin: 0; }

/* Reduced motion: kill all keyframe animation/transition globally */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Desktop ---------- */
@media (min-width: 900px) {
  .app-shell { max-width: 960px; }
  .segmented { display: none; }
  .pitches-wrap { flex-direction: row; gap: 20px; align-items: stretch; }
  .pitch-col { display: flex !important; flex: 1; max-width: 460px; margin: 0 auto; }
  .bench { align-items: stretch; }
  .player-name { font-size: 0.8rem; }
  .player-meta { font-size: 0.72rem; }
  .fold { max-width: 720px; margin-left: auto; margin-right: auto; }
}
