/* 大会 — trang /taikai (static/taikai.html + tournament.js), dùng token màu của app.css. */

html.tour-open, html.tour-open body { overflow: hidden; background: var(--bg); }

.tour {
  position: fixed; inset: 0; z-index: 45; background: var(--bg); display: flex; flex-direction: column;
  padding-top: var(--safe-top); animation: fadein .15s;
}
.tour__head {
  display: flex; align-items: center; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.tour__title { flex: 1; min-width: 0; display: grid; }
.tour__title b { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tour__title span { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tour__body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(32px + var(--safe-bottom)); width: 100%; max-width: 860px; margin: 0 auto;
}
.tour__empty { color: var(--muted); text-align: center; padding: 40px 0; }
.tour__new { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 6px; }
.tour__new .btn { height: 42px; }
.tour .hint.tour__newhint { margin: 0 0 14px; }
.tour__view { display: flex; width: 100%; }
.tour__view button { flex: 1; padding: 6px 4px; font-size: 13px; }
.tour__tabs { display: flex; width: 100%; margin-bottom: 14px; }
.tour__tabs button { flex: 1; padding: 7px 4px; font-size: 13px; }
.tour__pane { display: grid; gap: 14px; }
.tour__pane > * { min-width: 0; }
.tour__bar { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.tour__del { justify-self: start; }
.tour .hint { margin: 0; }
.tour .link { background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; font: inherit; }

.tour__head a.iconbtn { display: inline-grid; place-items: center; color: inherit; }
.tour__head a.iconbtn[hidden] { display: none; }
.tour__gate { display: grid; gap: 8px; text-align: center; padding: 28px 18px; margin-top: 24px; }
.tour__gate b { font-size: 16px; }
.tour__gate p { margin: 0; color: var(--muted); font-size: 13.5px; }
.tour .tour__me { margin-top: 18px; text-align: center; }

/* 運営メンバー (link mời, chỉ admin) */
.tinv { margin-top: 18px; display: grid; gap: 10px; }
.tinv__row { display: flex; align-items: center; gap: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.tinv__row > div { flex: 1; min-width: 0; display: grid; }
.tinv__row span { font-size: 12px; color: var(--muted); }
.tinv__link { display: grid; gap: 8px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--accent-soft); }
.tinv__copy, .tinv__new { display: flex; gap: 8px; }
.tinv__copy input, .tinv__new input {
  flex: 1; min-width: 0; height: 36px; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px; outline: none;
}

/* 一覧 */
.tlist { display: grid; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
.tlist__row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto; gap: 2px 10px; align-items: center;
  padding: 12px 14px; border: 0; border-top: 1px solid var(--border); background: transparent; color: var(--text);
  text-align: left; font: inherit; cursor: pointer;
}
.tlist__row:first-child { border-top: 0; }
.tlist__row b { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tlist__row > span:nth-child(2) { grid-row: 2; font-size: 12.5px; color: var(--muted); }
.tlist__row .pill { grid-row: 1 / span 2; grid-column: 2; }
@media (hover: hover) { .tlist__row:hover { background: var(--surface-2); } }

/* thẻ */
.tcard { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.tcard__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.tcard__head b { font-size: 14px; display: flex; align-items: center; gap: 8px; }
.tcard__head b::before { content: ""; width: 3px; height: 14px; background: var(--accent); }
.trules { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 13px; color: var(--text-2); }
.tnote { font-size: 12.5px; color: var(--muted); margin: 0; }
.tnote--warn { color: var(--amber-ink); background: var(--amber-soft); padding: 8px 12px; border-radius: var(--radius-sm); }

/* 設定 */
.tform { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.tform__wide { grid-column: span 2; }
.tform .field input, .tform .field select { width: 100%; min-width: 0; color: var(--text); font: inherit; }
.tform .field select { height: 38px; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); }
.tform .field input:disabled, .tform .field select:disabled { opacity: .55; }
.tform .field input[type="time"] { -webkit-appearance: none; appearance: none; }
.tform__act { grid-column: 1 / -1; display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.tform__act .hint { flex: 1; }

/* ペア */
.tpairs { display: grid; gap: 8px; }
.tpair { display: grid; grid-template-columns: 28px minmax(0, 1fr) minmax(0, 1fr) 34px; gap: 8px; align-items: center; }
.tpairs.is-lock .tpair { grid-template-columns: 28px minmax(0, 1fr) minmax(0, 1fr) auto; }
.tpair.is-out input, .tplayer.is-out input { text-decoration: line-through; opacity: .55; }
.tpair i, .tp i {
  font-style: normal; font-weight: 700; font-size: 12px; display: inline-grid; place-items: center;
  border-radius: 7px; background: var(--accent-soft); color: var(--accent-ink);
}
.tpair i { width: 28px; height: 28px; }
.tpair input {
  height: 38px; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; min-width: 0; outline: none;
}
.tpair input:focus { border-color: var(--text-2); }
.tplayers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px; }
.tplayer { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 8px; align-items: center; min-width: 0; }
.tplayer i {
  width: 28px; height: 28px; font-style: normal; font-weight: 700; font-size: 12px; display: inline-grid; place-items: center;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink);
}
.tplayer input {
  height: 38px; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; min-width: 0; outline: none;
}
.tplayer input:focus { border-color: var(--text-2); }
.tcheck { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }

/* tên cặp: chữ cái + tên */
.tp { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.tp i { min-width: 20px; height: 20px; padding: 0 4px; flex: none; }

/* 対戦表 */
.tslots { display: grid; gap: 12px; }
.tslot { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.tslot.is-now { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tslot.is-done .tslot__head { opacity: .7; }
.tslot__head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface-2); font-size: 13px; }
.tslot__head span:not(.pill) { color: var(--muted); }
.tslot__head .pill { margin-left: auto; }
.tm {
  width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); grid-template-rows: auto auto;
  gap: 4px 10px; align-items: center; padding: 10px 12px; border: 0; border-top: 1px solid var(--border);
  background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.tm:first-of-type { border-top: 0; }
@media (hover: hover) { .tm:hover { background: var(--surface-2); } }
.tm__court { grid-row: 1; grid-column: 1; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.tm__label { grid-row: 1; grid-column: 3; justify-self: end; font-size: 11px; font-weight: 600; color: var(--muted); }
.tm__label.is-ko { color: var(--accent-ink); }
.tm__side { grid-row: 2; font-size: 13.5px; min-width: 0; display: flex; overflow: hidden; }
.tm__side:last-child { justify-content: flex-end; }
.tp > span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; min-width: 0; }
.tm__side.is-win { font-weight: 700; }
.tm__score { grid-row: 2; grid-column: 2; display: inline-flex; gap: 4px; align-items: baseline; font-variant-numeric: tabular-nums; }
.tm__score b { font-size: 17px; }
.tm__score span { color: var(--muted); }
.tm.is-next { opacity: .7; }
.tcourts .tm__court { grid-column: 1 / span 2; }
.tm__wait { display: block; font-style: normal; font-weight: 600; color: var(--amber-ink); }
.tm__wo { font-size: 12px; font-weight: 700; color: var(--muted); }
.tslot__rest { padding: 8px 12px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--muted); }
.tcourt__empty { margin: 0; padding: 12px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--border); }
.tslot__head + .tcourt__empty { border-top: 0; }
.tm__in { font-size: 12px; font-weight: 600; color: var(--accent-ink); border: 1px dashed var(--accent); border-radius: 7px; padding: 2px 8px; }

/* nhập tỉ số */
#tour-score { z-index: 55; }
.tscore { gap: 14px; }
.tscore__head { display: grid; }
.tscore__head span { font-size: 12.5px; color: var(--muted); }
.tscore__row { display: grid; gap: 6px; }
.tscore__name { font-weight: 600; font-size: 14px; }
.tscore__chips { display: flex; gap: 6px; flex-wrap: wrap; }
.tscore__chips button {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-weight: 700; font-size: 16px; cursor: pointer; font-variant-numeric: tabular-nums;
}
.tscore__wo { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.tscore__wo .btn.on { border-color: var(--red, #c33); color: var(--red, #c33); }
.tscore__chips button.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent, #fff); }

/* 順位 */
.tcard .tablewrap { overflow-x: auto; margin: 0 -14px; }
.ttable { font-size: 13px; }
.ttable th, .ttable td { padding: 8px 6px; }
.ttable th:last-child, .ttable td:last-child { padding-right: 14px; }
.ttable td.left { max-width: 0; width: 100%; }
.ttable td.left .tp { max-width: 100%; }
.ttable th:first-child, .ttable td:first-child { padding-left: 14px; width: 24px; }
.ttable th.left { text-align: left; }
.tcard .tablewrap:last-child { margin-bottom: -12px; }
.ttable tbody tr:last-child td { border-bottom: 0; }
.ttable td.left small { display: block; font-size: 10.5px; color: var(--muted); }
.ttable tbody tr:first-child td { font-weight: 600; }
.tpodium__row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--border); font-size: 14px; }
.tpodium__row:first-of-type { border-top: 0; }
.tpodium__place { width: 52px; font-size: 12px; font-weight: 700; color: var(--muted); }
.tpodium__row.is-top .tpodium__place { color: var(--accent-ink); }
.tpodium__row.is-top { font-weight: 700; }

@media (max-width: 860px) {
  .tour__body { padding: 12px 16px calc(32px + var(--safe-bottom)); }
  .tform { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tform__act { flex-wrap: wrap; }
  .tpair { grid-template-columns: 24px minmax(0, 1fr) minmax(0, 1fr) 30px; gap: 6px; }
  .tpairs.is-lock .tpair { grid-template-columns: 24px minmax(0, 1fr) minmax(0, 1fr) auto; }
  .tplayers { grid-template-columns: 1fr; }
  .ttable__gf { display: none; }
  .tpair i { width: 24px; height: 24px; }
  .tscore__chips button { width: 38px; height: 38px; }
}

/* 印刷: chỉ in màn hình 大会 (tab đang mở) */
@media print {
  body > *:not(#tour) { display: none !important; }
  html.tour-open, html.tour-open body { overflow: visible !important; height: auto; }  /* không thì chỉ in được 1 trang */
  .tour { position: static; display: block; background: #fff; color: #000; animation: none; }
  .tour__head .iconbtn, .tour__tabs, .tour__view, .tour__bar, .tour__del, .tm__in, .tpair__out, .tinv, .tour__me,
  #tour-copy-games, #tour-copy-rules { display: none !important; }
  .tour__body { overflow: visible; max-width: none; padding: 0; }
  .tslot, .tcard { break-inside: avoid; }
}
