@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@500;600;700&family=IBM+Plex+Sans+Thai:wght@400;500;600&display=swap');

:root {
  --concrete: #ECEDF0;
  --concrete-deep: #DCDEE3;
  --surface: #FFFFFF;
  --ink: #1B2028;
  --ink-soft: #616977;
  --line: #C9CCD4;
  --line-soft: #E2E4E9;
  --gold: #BE9412;
  --silver: #8D95A1;
  --bronze: #A0633A;
  --focus: #1B2028;
  --pad: clamp(16px, 4vw, 32px);
  --wrap: 1100px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--concrete);
  color: var(--ink);
  font-family: 'IBM Plex Sans Thai', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

h1, h2, h3, .num, .chip, .lane__rank, .tabs button, .btn {
  font-family: 'Kanit', system-ui, sans-serif;
}

h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 600; }

a { color: inherit; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.wrap {
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 0 var(--pad);
}

/* ── แถบหัวเว็บ ─────────────────────────────────────────── */

.topbar {
  background: var(--ink);
  color: #F4F5F7;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  padding-block: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Kanit', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: .01em;
  text-decoration: none;
}

.brand__logo {
  height: 40px;
  width: auto;
  flex-shrink: 0;
}

.brand__text {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.brand span {
  font-weight: 500;
  font-size: .8rem;
  color: #A7AEBC;
}

@media (max-width: 640px) {
  .brand { font-size: .9rem; }
  .brand__logo { height: 32px; }
  .brand span { font-size: .75rem; }
}

.nav {
  display: flex;
  gap: 4px;
  margin-inline-start: auto;
  flex-wrap: wrap;
}

.nav a {
  text-decoration: none;
  font-size: .92rem;
  padding: 6px 12px;
  border-radius: 2px;
  color: #C6CBD5;
}

.nav a:hover { color: #fff; background: #2C323C; }

.nav a[aria-current='page'] {
  color: var(--ink);
  background: #F4F5F7;
  font-weight: 600;
}

/* แถบสีคณะใต้ header */
.stripe {
  display: flex;
  height: 5px;
}
.stripe i { flex: 1; }

/* ── ส่วนหัวหน้า ───────────────────────────────────────── */

.masthead {
  padding: clamp(28px, 6vw, 52px) 0 clamp(20px, 4vw, 32px);
}

.masthead h1 {
  font-size: clamp(2rem, 7vw, 3.4rem);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.masthead p {
  margin: 8px 0 0;
  color: var(--ink-soft);
  max-width: 60ch;
}

.meta {
  margin-top: 14px;
  font-size: .9rem;
  color: var(--ink-soft);
}

/* ── ลู่วิ่ง: ตารางอันดับคณะสี ─────────────────────────── */

.lanes {
  border-top: 2px solid var(--ink);
  background: var(--surface);
}

.lane {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  align-items: center;
  gap: 0 14px;
  padding: 14px 16px 14px 0;
  border-bottom: 1px solid var(--line-soft);
  position: relative;
}

.lane::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 8px;
  background: var(--lane-color);
}

.lane__rank {
  font-size: 1.7rem;
  font-weight: 700;
  text-align: center;
  color: var(--ink);
  padding-inline-start: 8px;
}

.lane--leader .lane__rank { color: var(--gold); }

.lane__body { min-width: 0; }

.lane__name {
  font-family: 'Kanit', sans-serif;
  font-weight: 600;
  font-size: 1.1rem;
}

.lane__track {
  height: 10px;
  background: var(--concrete-deep);
  margin-top: 6px;
  overflow: hidden;
}

.lane__fill {
  height: 100%;
  background: var(--lane-color);
  width: 0;
  transition: width .5s ease;
}

@media (prefers-reduced-motion: reduce) {
  .lane__fill { transition: none; }
}

.lane__counts {
  display: flex;
  gap: 10px;
  text-align: center;
}

.count {
  min-width: 42px;
}

.count b {
  display: block;
  font-family: 'Kanit', sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.1;
}

.count span {
  font-size: .72rem;
  color: var(--ink-soft);
}

.count--gold b { color: var(--gold); }
.count--silver b { color: var(--silver); }
.count--bronze b { color: var(--bronze); }

/* ── แท็บ ──────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 28px 0 12px;
}

.tabs button {
  font-size: .92rem;
  font-weight: 500;
  padding: 8px 16px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  border-radius: 2px;
}

.tabs button[aria-selected='true'] {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

/* ── ตาราง ─────────────────────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  margin-bottom: 28px;
}

.panel__head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
}

.panel__head h2 { font-size: 1.1rem; }

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

th, td {
  padding: 10px 12px;
  text-align: start;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

thead th {
  font-family: 'Kanit', sans-serif;
  font-weight: 500;
  font-size: .85rem;
  color: var(--ink-soft);
  background: #F5F6F8;
}

tbody tr:hover { background: #FAFAFB; }

td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; }

.ev-no {
  font-family: 'Kanit', sans-serif;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.ev-sport { font-weight: 500; }
.ev-cat { color: var(--ink-soft); font-size: .88rem; }

.scroller { overflow-x: auto; }

/* ── ชิปคณะสี ──────────────────────────────────────────── */

.chip {
  display: inline-block;
  padding: 3px 10px;
  background: var(--chip-bg);
  color: var(--chip-fg);
  font-weight: 600;
  font-size: .85rem;
  border-radius: 2px;
  white-space: nowrap;
}

.chip--lg { font-size: 1rem; padding: 5px 14px; }

.chip--empty {
  background: transparent;
  color: #9AA1AC;
  border: 1px dashed var(--line);
  font-weight: 400;
}

.pill {
  font-size: .75rem;
  padding: 2px 8px;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  border-radius: 999px;
  white-space: nowrap;
}

.pill--live {
  border-color: #C0392B;
  color: #C0392B;
  font-weight: 600;
}

.pill--done { border-color: var(--line); color: #8D95A1; }

/* ── ตัวกรอง ───────────────────────────────────────────── */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

input[type='search'], input[type='text'], input[type='email'],
input[type='password'], input[type='number'], select, textarea {
  font-family: inherit;
  font-size: .95rem;
  padding: 9px 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 2px;
}

input[type='search'] { min-width: min(300px, 100%); }

label.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: .85rem;
  color: var(--ink-soft);
}

/* ── ปุ่ม ──────────────────────────────────────────────── */

.btn {
  font-size: .92rem;
  font-weight: 500;
  padding: 9px 18px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  border-radius: 2px;
}

.btn:hover { background: #2C323C; }

.btn--ghost {
  background: transparent;
  color: var(--ink);
}

.btn--ghost:hover { background: var(--concrete-deep); }

.btn--danger { border-color: #A93226; background: #A93226; }
.btn--danger:hover { background: #8E2A20; }

.btn[disabled] { opacity: .45; cursor: not-allowed; }

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

/* ── สายการแข่งขัน ─────────────────────────────────────── */

.bracket {
  display: grid;
  gap: 18px;
  padding: 16px;
}

@media (min-width: 760px) {
  .bracket { grid-template-columns: repeat(3, 1fr); align-items: start; }
  .bracket__col--finals { grid-column: 3; }
  /* E-Sport ไม่มีรอบแรก จึงเหลือสองคอลัมน์ */
  .bracket--two { grid-template-columns: repeat(2, 1fr); }
  .bracket--two .bracket__col--finals { grid-column: 2; }
}

.bracket__col { display: grid; gap: 14px; align-content: start; }

.round-label {
  font-family: 'Kanit', sans-serif;
  font-size: .8rem;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 4px;
}

.match {
  border: 1px solid var(--line);
  background: var(--surface);
}

.match--final { border-width: 2px; border-color: var(--ink); }

.match__side {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-inline-start: 6px solid var(--side-color, transparent);
}

.match__side + .match__side { border-top: 1px solid var(--line-soft); }

.match__side b {
  font-family: 'Kanit', sans-serif;
  font-weight: 500;
  flex: 1;
}

.match__side .score {
  font-family: 'Kanit', sans-serif;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1.05rem;
}

.match__side--won { background: #F7F8F5; }
.match__side--won b { font-weight: 700; }
.match__side--lost { color: #949BA6; }

.match__foot {
  padding: 6px 12px;
  font-size: .78rem;
  color: var(--ink-soft);
  border-top: 1px solid var(--line-soft);
  background: #FAFAFB;
}

/* ── หน้าแอดมิน ────────────────────────────────────────── */

.login {
  max-width: 380px;
  margin: 60px auto;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  padding: 28px;
}

.login h2 { margin-bottom: 6px; }
.login p { color: var(--ink-soft); font-size: .9rem; margin-top: 0; }

.stack { display: grid; gap: 14px; }

.editor-row td { padding-block: 8px; }

.editor-row select { width: 100%; min-width: 196px; }

.hint { font-size: .85rem; color: var(--ink-soft); }

.banner {
  background: #A93226;
  color: #fff;
  padding: 10px var(--pad);
  font-size: .9rem;
}

.toast {
  position: fixed;
  inset-block-end: 20px;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 20px;
  border-radius: 2px;
  font-size: .9rem;
  z-index: 50;
}

.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--ink-soft);
}

footer.site {
  padding: 32px 0 48px;
  color: var(--ink-soft);
  font-size: .85rem;
}

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

@media (max-width: 560px) {
  .lane { grid-template-columns: 42px 1fr; }
  .lane__counts { grid-column: 1 / -1; margin-top: 10px; padding-inline-start: 8px; justify-content: start; }
}

/* ตารางกรอกผลในหน้าแอดมิน: กันชื่อรายการตกบรรทัด */
.editor-row td:nth-child(2) { min-width: 190px; }
.editor-row .hint { display: block; text-align: center; }

/* ชื่อสีกำกับใต้ชื่อคณะในแถบลู่วิ่ง */
.lane__color {
  font-family: 'IBM Plex Sans Thai', sans-serif;
  font-weight: 400;
  font-size: .82rem;
  color: var(--ink-soft);
  margin-inline-start: 8px;
}

/* ── รอบเก็บคะแนนของ E-Sport ───────────────────────────── */

.stage { padding: 16px; }

.stage h3 { font-family: 'Kanit', sans-serif; font-weight: 600; }

tr.row--through { background: #F6F9F4; }

.stage-list {
  border: 1px solid var(--line-soft);
}

.stage-match {
  padding-inline: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 6px 0;
}

.stage-list .stage-match + .stage-match { border-top: 1px solid var(--line-soft); }

.stage-match__no {
  font-family: 'Kanit', sans-serif;
  font-size: .85rem;
  color: var(--ink-soft);
  min-width: 52px;
}

.stage-match__vs {
  font-size: .8rem;
  color: var(--ink-soft);
}

.stage-match select { min-width: 178px; }

.stage-side { font-family: 'Kanit', sans-serif; font-weight: 500; }
.stage-side--won { font-weight: 700; }
.stage-side--lost { color: #949BA6; }

.stage-fixtures { margin-top: 18px; }
tr.row--through td { font-weight: 500; }

.pill--through {
  border-color: #1E7A46;
  color: #1E7A46;
  font-weight: 600;
}

.seed-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  counter-reset: seed;
}

.seed-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border: 1px solid var(--line-soft);
  counter-increment: seed;
}

.seed-list li::before {
  content: counter(seed);
  font-family: 'Kanit', sans-serif;
  font-weight: 700;
  color: var(--ink-soft);
  min-width: 18px;
}

.seed-list li.seed--through {
  border-color: #1E7A46;
  background: #F6F9F4;
}

.seed-list li.seed--through::before { color: #1E7A46; }

.seed-points {
  margin-inline-start: auto;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  font-size: .9rem;
}

/* ชื่อรอบบนหัวการ์ดคู่แข่ง */
.match__head {
  padding: 6px 12px;
  font-family: 'Kanit', sans-serif;
  font-size: .8rem;
  color: var(--ink-soft);
  background: #FAFAFB;
  border-bottom: 1px solid var(--line-soft);
}

.match--final .match__head { color: var(--ink); font-weight: 500; }


/* ── เลือกคณะด้วยการแตะสี ในตารางผลเหรียญของหน้ากรรมการ ── */

.swatches {
  display: flex;
  gap: 5px;
}

.swatch {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 4px;
  background: var(--sw);
  opacity: .55;
  cursor: pointer;
  transition: opacity .12s ease;
  /* ให้แตะติดทันทีบนมือถือ ไม่ต้องรอตรวจดับเบิลแท็ป */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.swatch:hover { opacity: .85; }

.swatch--on {
  opacity: 1;
  border-color: var(--ink);
  box-shadow: inset 0 0 0 3px #fff;
}

.swatch--taken { opacity: .16; }

.swatch:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .swatch { transition: none; }
}

@media (max-width: 640px) {
  .swatch { width: 48px; height: 48px; }
}


/* ── สรุปผลในตาราง และหน้าต่างบันทึกผล ─────────────────── */

.editor-row td:last-child { white-space: nowrap; }
.editor-row td:last-child .btn { white-space: nowrap; }

.await-bracket {
  display: flex;
  align-items: center;
  gap: 10px;
}

.result-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.result-slot {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.result-slot i {
  font-family: 'Kanit', sans-serif;
  font-style: normal;
  font-size: .78rem;
  color: var(--ink-soft);
}

.modal {
  width: min(460px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 22px;
  background: var(--surface);
  color: var(--ink);
}

.modal::backdrop { background: rgba(20, 24, 32, .55); }

.modal__head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.modal__head h2 { font-size: 1.15rem; }
.modal__head .hint { margin: 2px 0 0; }
.modal__head button { margin-inline-start: auto; flex-shrink: 0; }

.place-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 0;
}

.place-row + .place-row { border-top: 1px solid var(--line-soft); }

.place-row__label {
  font-family: 'Kanit', sans-serif;
  font-weight: 500;
  font-size: .92rem;
  min-width: 104px;
}

.modal .swatches {
  width: 100%;
  gap: 8px;
}

.modal .swatch {
  flex: 1 1 0;
  min-width: 0;
  max-width: 80px;
  height: 60px;
}

.modal .place-row__label { flex-basis: 100%; }

.modal .toast { position: absolute; inset-block-end: 14px; }


@media (max-width: 480px) {
  .modal { padding: 18px 14px; }
  .modal .swatch { height: 64px; }
  .modal__head h2 { font-size: 1.05rem; }
}