:root {
  --ink: #1c1c1a;
  --muted: #6b6a64;
  --line: #dddbd3;
  --paper: #faf9f5;
  --card: #ffffff;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --ok: #166534;
  --ok-bg: #e7f5ea;
  --warn: #92400e;
  --warn-bg: #fdf1dc;
  --bad: #b91c1c;
  --bad-bg: #fdecec;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Sarabun", "Noto Sans Thai", "Leelawadee UI", "Thonburi", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.6;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px calc(40px + env(safe-area-inset-bottom));
}

h1 { font-size: 1.45rem; line-height: 1.3; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 28px 0 10px; }
p { margin: 0 0 12px; }
.sub { color: var(--muted); margin-bottom: 20px; }
.loading, .center { text-align: center; color: var(--muted); padding: 48px 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.rules { margin: 0; padding-left: 22px; }
.rules li { margin-bottom: 6px; }

label, .field-label { display: block; font-weight: 600; margin: 14px 0 6px; }
input[type="text"], input[type="tel"], input[type="number"] {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  font: inherit;
  color: inherit;
  background: #fff;
  border: 1px solid #b9b7ae;
  border-radius: 8px;
}
input:focus-visible, button:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
.invalid input, input.invalid { border-color: var(--bad); background: var(--bad-bg); }
.field-error { color: var(--bad); font-size: 0.92rem; margin: 6px 0 0; }

.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; margin: 12px 0; }
.check input { width: 22px; height: 22px; margin-top: 3px; flex: none; }

.row { display: grid; gap: 8px; margin-bottom: 8px; align-items: center; }
.row.player { grid-template-columns: 52px minmax(0, 1fr) 62px 44px; }
.row.helper { grid-template-columns: 1fr 1fr; }
.row-head { color: var(--muted); font-size: 0.9rem; margin-bottom: 4px; }

button {
  min-height: 46px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid #b9b7ae;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
button.primary { width: 100%; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); margin-top: 20px; }
button.ghost { width: 100%; margin-top: 8px; }
button.icon { padding: 0; width: 44px; color: var(--muted); }
button:disabled { opacity: 0.55; cursor: default; }

.pay { background: var(--warn-bg); border-color: #f0d9a8; }
.pay .amount { font-size: 1.5rem; font-weight: 700; }
.bank { white-space: pre-line; }

.badge { display: inline-block; padding: 4px 12px; border-radius: 999px; font-weight: 700; font-size: 0.95rem; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.wait { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }

.alert { border-radius: 8px; padding: 12px 14px; margin-bottom: 16px; }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 4px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 0.9rem; }
td.num, th.num { text-align: right; width: 64px; }

.teams { margin: 0; padding-left: 22px; }
.slip { width: 100%; border: 1px solid var(--line); border-radius: 8px; }

.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.file-button {
  display: flex; align-items: center; justify-content: center;
  min-height: 46px; margin: 0 0 6px; padding: 10px 16px;
  border: 1px dashed #8f8d84; border-radius: 8px; background: #fff; cursor: pointer;
}
.file-button.invalid { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }
#slip:focus-visible + #slip-name { outline: 3px solid #f59e0b; outline-offset: 2px; }
#slip-name { margin-bottom: 0; word-break: break-all; }

/* ปุ่มรูปผู้เล่นในแถวของฟอร์ม */
.p-photo {
  display: flex; align-items: center; justify-content: center;
  width: 52px; height: 52px; margin: 0; padding: 0;
  border: 1px dashed #8f8d84; border-radius: 8px; background: #fff center / cover no-repeat;
  color: var(--muted); font-size: 0.8rem; font-weight: 600; line-height: 1.1; text-align: center; cursor: pointer;
}
.p-photo.done { border-style: solid; border-color: var(--ok); color: var(--ok); }
.p-photo.uploading { opacity: 0.6; font-size: 0.68rem; }
.p-photo.invalid { border-color: var(--bad); background-color: var(--bad-bg); color: var(--bad); }
.row.player.row-head { margin-bottom: 4px; }

.admin { margin-top: 28px; text-align: center; }
.admin a, .team-list a { color: var(--accent); font-weight: 600; }
.team-list .sub { margin: 0; font-size: 0.85rem; }

/* ใบรายชื่อทีม: โทนสว่าง ลายเส้นสนามบาสจาง ๆ */
.sheet {
  position: relative; overflow: hidden;
  background: linear-gradient(180deg, #fffdf8 0%, #fff4e2 100%);
  border: 1px solid #f1dcb9; border-radius: 16px;
  padding: 22px 14px 16px; margin-bottom: 16px;
}
.sheet::before, .sheet::after {
  content: ""; position: absolute; border: 3px solid rgba(194, 65, 12, 0.10); border-radius: 50%; pointer-events: none;
}
.sheet::before { width: 260px; height: 260px; right: -110px; top: -110px; }
.sheet::after { width: 340px; height: 340px; left: -170px; bottom: -190px; }
.sheet > * { position: relative; }
.sheet-head { text-align: center; margin-bottom: 18px; }
.sheet-kicker { margin: 0; color: var(--accent); font-size: 0.82rem; font-weight: 700; letter-spacing: 0.04em; }
.sheet-team { margin: 2px 0 6px; font-size: 1.7rem; font-weight: 800; line-height: 1.25; word-break: break-word; }
.sheet-meta { margin: 0; color: var(--muted); font-size: 0.88rem; }
.sheet-meta .badge { font-size: 0.8rem; padding: 2px 10px; }
.sheet-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px 10px; }
.sheet-card { margin: 0; text-align: center; }
.sheet-photo {
  display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover;
  border-radius: 10px; border: 3px solid #fff; background: #ece9df;
  box-shadow: 0 1px 5px rgba(60, 40, 10, 0.18);
}
.sheet-photo.empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 0.8rem; }
.sheet-no {
  display: inline-block; position: relative; margin-top: -14px; min-width: 34px; padding: 1px 9px;
  background: var(--accent); color: #fff; border: 2px solid #fff; border-radius: 999px; font-weight: 800; font-size: 0.95rem;
}
.sheet-name { display: block; margin-top: 2px; font-size: 0.82rem; font-weight: 600; line-height: 1.3; word-break: break-word; }
.sheet-foot {
  display: flex; justify-content: space-between; gap: 12px; margin-top: 18px; padding-top: 12px;
  border-top: 1px dashed #e2c594; font-size: 0.9rem;
}
.sheet-foot span { display: block; color: var(--muted); font-size: 0.78rem; }
.sheet-foot div:last-child { text-align: right; }

@media (min-width: 640px) {
  .app { max-width: 760px; }
  .sheet { padding: 28px 28px 20px; }
  .sheet-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 22px 18px; }
  .sheet-name { font-size: 0.92rem; }
}

@media print {
  body { background: #fff; }
  .app { max-width: none; padding: 0; }
  .no-print { display: none !important; }
  .sheet { border: none; border-radius: 0; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px 16px; }
  .sheet-card { break-inside: avoid; }
}

/* ช่องรูปที่ยังโหลดไม่เสร็จ: พื้นเทาอ่อนขนาดเท่ารูปจริง หน้าไม่กระตุกเมื่อรูปมา */
img.sheet-photo:not([src]) { visibility: hidden; }
.sheet-card { position: relative; }
.sheet-card::before {
  content: ""; display: block; position: absolute; left: 0; right: 0; top: 0; aspect-ratio: 3 / 4;
  border-radius: 10px; background: #ece9df; z-index: 0;
}
.sheet-card > * { position: relative; z-index: 1; }

/* สีเสื้อ */
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; padding: 6px; border: 1px solid transparent; border-radius: 10px; }
.swatches.invalid { border-color: var(--bad); background: var(--bad-bg); }
.swatch { min-height: 46px; padding: 0; border: 1px solid #8f8d84; border-radius: 8px; }
.swatch[aria-pressed="true"] { outline: 3px solid var(--ink); outline-offset: 2px; }
.picked { font-weight: 400; color: var(--muted); }
.team-chip { display: inline-block; width: 0.8em; height: 0.8em; margin-right: 0.4em; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.35); vertical-align: baseline; }

/* ตารางแข่งและตารางคะแนน */
h3 { font-size: 1rem; margin: 20px 0 8px; }
.day-head { padding: 6px 10px; background: #f1ede2; border-radius: 8px; }
.empty-note { padding: 28px 12px; text-align: center; color: var(--muted); }
.standings { font-size: 0.92rem; }
.standings th.num, .standings td.num { width: auto; padding-left: 6px; padding-right: 6px; }
.standings .pts { font-weight: 800; }
.standings tr.mine td { background: #fff1dc; }
.match, .match-admin, .deposit-row {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px;
}
.match.mine { border-color: var(--accent); }
.match-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 0.82rem; margin-bottom: 4px; }
.match-line, .score-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 3px 0; }
.side { min-width: 0; word-break: break-word; }
.side.slot { color: var(--muted); font-style: italic; }
.side.won { font-weight: 800; }
.score { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
.note { margin: 4px 0 0; color: var(--muted); font-size: 0.82rem; }
.my-duty { border-color: #f0d9a8; background: var(--warn-bg); }
.my-duty ul { margin: 0 0 8px; padding-left: 20px; }
.my-duty .sub { margin: 0; font-size: 0.85rem; }

/* หน้าจัดการของผู้จัด */
.admin-links { margin-bottom: 8px; }
.admin-links a { color: var(--accent); font-weight: 600; }
.match-admin.done { background: #f6fbf6; border-color: #cfe6d2; }
.score-row input { width: 84px; flex: none; text-align: center; }
select {
  width: 100%; min-height: 46px; margin-top: 8px; padding: 8px 10px; font: inherit; color: inherit;
  background: #fff; border: 1px solid #b9b7ae; border-radius: 8px;
}
.duty { display: flex; align-items: center; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 0.9rem; }
.duty span { flex: 1; min-width: 0; }
.duty button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.duty .duty-absent[aria-pressed="true"] { background: var(--bad); border-color: var(--bad); }
.lot-label { font-weight: 400; font-size: 0.9rem; }
