:root{
  --navy:#1B365D; --navy-2:#122842; --gold:#D4AF37; --red:#DC2626;
  --bg:#EEF2F7; --card:#FFFFFF; --ink:#0F172A; --muted:#64748B;
  --line:#CBD5E1; --row1:#F8FAFC; --input:#FEF9C3; --ok:#15803D;
  --shadow:0 4px 18px rgba(15,23,42,.08);
}
*{box-sizing:border-box}
html,body{margin:0;padding:0}
body{
  font-family:'Segoe UI',Roboto,Helvetica,Arial,system-ui,sans-serif;
  background:var(--bg); color:var(--ink); -webkit-text-size-adjust:100%;
  padding-bottom:92px;
}
.app-header{
  position:sticky; top:0; z-index:20;
  background:linear-gradient(135deg,var(--navy),var(--navy-2));
  color:#fff; padding:14px 16px; display:flex; align-items:center; gap:12px;
  justify-content:space-between; box-shadow:var(--shadow);
}
.brand{display:flex; align-items:center; gap:12px; min-width:0}
.ball{font-size:30px; filter:drop-shadow(0 2px 3px rgba(0,0,0,.3))}
.brand h1{font-size:18px; margin:0; letter-spacing:.5px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis}
.sub{margin:2px 0 0; font-size:12px; opacity:.75}
.icon-btn{
  background:rgba(255,255,255,.12); color:#fff; border:1px solid rgba(255,255,255,.25);
  font-size:20px; width:42px; height:42px; border-radius:12px; cursor:pointer; flex:0 0 auto;
}
.icon-btn:active{transform:scale(.96)}

/* bố cục 2 cột: TRÁI = lịch thi đấu, PHẢI = xếp hạng */
.layout{
  max-width:1400px; margin:0 auto; padding:12px;
  display:grid; grid-template-columns:minmax(0,1.4fr) minmax(0,1fr); gap:14px; align-items:start;
}
.col-left,.col-right{min-width:0; display:flex; flex-direction:column; gap:14px}

.card{background:var(--card); border-radius:14px; box-shadow:var(--shadow); padding:14px}
.card h2{font-size:15px; margin:2px 0 10px; color:var(--navy); text-transform:uppercase; letter-spacing:.6px}
.head-row{display:flex; align-items:center; justify-content:space-between; gap:8px; flex-wrap:wrap; margin-bottom:10px}
.head-row h2{margin:0}
.hint{font-size:12.5px; color:var(--muted); margin:0 0 10px}
.legend{font-size:12px; color:var(--muted); margin:10px 2px 0}
.chip-in{background:var(--input); border:1px solid #E7D98A; border-radius:5px; padding:0 5px}

.table-wrap{overflow-x:auto; -webkit-overflow-scrolling:touch; border-radius:10px; border:1px solid var(--line)}
.data-table{border-collapse:collapse; width:100%; min-width:460px; font-size:13.5px}
.data-table th{
  background:var(--navy); color:#fff; font-weight:600; text-align:center;
  padding:9px 8px; position:sticky; top:0; white-space:nowrap;
}
.data-table td{padding:6px 7px; text-align:center; vertical-align:middle; border-bottom:1px solid var(--line); white-space:nowrap}
.data-table tbody tr:nth-child(odd){background:var(--row1)}
.data-table tbody tr:last-child td{border-bottom:0}
.data-table td.name{text-align:left; font-weight:700; color:var(--navy)}
.data-table td.gd-pos{color:var(--ok); font-weight:600}
.data-table td.gd-neg{color:var(--red); font-weight:600}
.data-table td.pts{font-weight:800; color:var(--navy); background:rgba(27,54,93,.06)}
.data-table tr.leader td{box-shadow:inset 3px 0 0 var(--gold)}
.data-table .rank-badge{
  display:inline-flex; align-items:center; justify-content:center; vertical-align:middle; min-width:24px; height:24px;
  border-radius:8px; font-weight:800; background:#E2E8F0; color:var(--navy); padding:0 6px
}
.data-table tr.leader .rank-badge{background:var(--gold); color:#3b2f00}

.score-in{
  width:52px; text-align:center; font-size:16px; font-weight:700; padding:6px 4px;
  border:1.5px solid #E7D98A; background:var(--input); border-radius:9px; color:var(--ink);
}
.score-in:focus{outline:2px solid var(--gold); border-color:var(--gold)}
.score-in::-webkit-outer-spin-button,.score-in::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}
.score-in[type=number]{-moz-appearance:textfield; appearance:textfield}
.note-in{width:100%; min-width:78px; border:1px solid var(--line); border-radius:8px; padding:6px 8px; font-size:13px; text-align:center; background:#fff}
.team-sel{
  border:1px solid var(--line); border-radius:8px; padding:6px 6px; font-size:13px; font-weight:600;
  background:#fff; color:var(--navy); max-width:130px;
}
.res-cell{font-weight:800; white-space:nowrap}
.res-win{color:var(--red)}       /* "Tạ Tùng thắng" — chữ ĐỎ */
.res-draw{color:#B45309}

.del-btn{
  border:0; background:#FEE2E2; color:var(--red); width:28px; height:28px; border-radius:8px;
  cursor:pointer; font-size:13px; font-weight:700; line-height:1;
}
.del-btn:active{transform:scale(.94)}
.row-actions{margin-top:10px; display:flex; gap:8px}
.btn.small{padding:8px 12px; font-size:12.5px; flex:0 0 auto}

/* Chọn giải + bảng đội */
.league-sel{padding:8px 10px; border:1px solid var(--line); border-radius:10px; font-size:14px; background:#fff; color:var(--ink); font-weight:700; max-width:100%; font-family:inherit}
.data-table td.name{cursor:text}
.data-table td.row-btns{white-space:nowrap}
.data-table td.row-btns .p-btn{margin-left:4px}

/* Lượt bốc + lịch sử quay */
.wheel-turn{font-size:14.5px; color:var(--navy); font-weight:700; text-align:center; margin:2px 0 6px}
.wheel-turn .turn-count{color:var(--muted); font-weight:600}
.mini-title{font-size:13px; color:var(--navy); text-transform:uppercase; letter-spacing:.6px; margin:16px 0 8px}
.history-table{font-size:13px; min-width:320px}
.history-table td.name{text-align:left; font-weight:600}

/* Bảng quay chọn đội */
.col-full{min-width:0}
@media (min-width:1025px){ .col-full{grid-column:1 / -1} }
.wheel-controls{display:flex; flex-wrap:wrap; gap:12px 18px; align-items:flex-end; margin-bottom:10px}
.fld-inline{display:flex; flex-direction:column; gap:4px; font-size:12.5px; color:var(--muted); font-weight:600}
.fld-inline select{padding:8px 10px; border:1px solid var(--line); border-radius:10px; font-size:14px; background:#fff; color:var(--ink); min-width:190px; font-family:inherit}
.chk{display:flex; align-items:center; gap:7px; font-size:13px; color:var(--ink); font-weight:600; padding-bottom:8px}
.chk input{width:18px; height:18px}
.wheel-stage{display:flex; justify-content:center; padding:8px 0 4px}
.wheel-holder{position:relative; width:min(88vw, 440px)}
#wheelCanvas{width:100%; height:auto; display:block; filter:drop-shadow(0 6px 16px rgba(15,23,42,.18))}
.wheel-pointer{position:absolute; top:-8px; left:50%; transform:translateX(-50%); font-size:30px; color:var(--navy); text-shadow:0 1px 2px rgba(0,0,0,.25); pointer-events:none; z-index:2}
.wheel-spin-btn{position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); width:76px; height:76px; border-radius:50%; border:3px solid #fff; background:var(--gold); color:#3b2f00; font-weight:900; font-size:15px; letter-spacing:.5px; cursor:pointer; box-shadow:0 4px 14px rgba(0,0,0,.3); z-index:3}
.wheel-spin-btn:disabled{opacity:.55; cursor:default}
.wheel-spin-btn:active{transform:translate(-50%,-50%) scale(.96)}
.wheel-result{text-align:center; font-size:17px; min-height:26px; margin-top:10px; color:var(--navy); font-weight:700}
.wheel-result b{font-weight:900; color:var(--red)}
.wheel-participants{display:flex; flex-wrap:wrap; gap:6px; justify-content:center; margin-top:10px}
.w-chip{padding:5px 11px; border-radius:999px; font-size:13px; font-weight:700; color:#0F172A; border:1px solid rgba(15,23,42,.08)}
.w-empty{color:var(--muted); font-size:13px}
.wheel-actions{display:flex; justify-content:center; margin-top:12px}
.wheel-actions .btn{flex:0 0 auto; padding:9px 16px}

/* Danh sách người chơi */
.players-list{list-style:none; margin:0 0 10px; padding:0; display:flex; flex-direction:column; gap:6px}
.p-item{display:flex; align-items:center; gap:8px; background:#F8FAFC; border:1px solid var(--line); border-radius:10px; padding:7px 10px}
.p-idx{width:20px; height:20px; flex:0 0 auto; display:inline-flex; align-items:center; justify-content:center; background:#E2E8F0; color:var(--navy); border-radius:6px; font-size:12px; font-weight:700}
.p-name{flex:1; font-weight:700; color:var(--navy); overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
.p-actions{display:flex; gap:6px; flex:0 0 auto}
.p-btn{border:1px solid var(--line); background:#fff; color:var(--navy); width:28px; height:28px; border-radius:8px; cursor:pointer; font-size:13px; line-height:1}
.p-btn.del{color:var(--red); border-color:#FCA5A5; background:#FEF2F2}
.p-btn:active{transform:scale(.94)}
.p-empty{color:var(--muted); font-size:13px; padding:6px 2px; list-style:none}
.add-player{display:flex; gap:8px}
.add-player input{flex:1; min-width:0; padding:9px 10px; border:1px solid var(--line); border-radius:10px; font-size:14px; font-family:inherit}

/* Danh hiệu (Vua phá lưới / Vua nhặt bóng) */
.titles-grid{display:grid; grid-template-columns:1fr 1fr; gap:14px}
.card.mini{padding:12px}
.mini-head{display:flex; align-items:center; gap:8px; margin-bottom:6px}
.mini-head h3{margin:0; font-size:12.5px; color:var(--navy); text-transform:uppercase; letter-spacing:.5px}
.mini-ic{font-size:20px}
.mini-name{font-size:16px; font-weight:800; color:var(--navy); line-height:1.25; word-break:break-word}
.mini-sub{font-size:11.5px; color:var(--muted); margin-top:2px}

/* Ô Đương kim vô địch */
.champ-card{background:linear-gradient(160deg,#1B365D,#122842); color:#fff}
.champ-head{display:flex; align-items:center; gap:10px}
.champ-head h2{color:#fff; margin:0; font-size:14px}
.cup{font-size:26px; filter:drop-shadow(0 2px 3px rgba(0,0,0,.4))}
.champ-body{display:flex; align-items:center; gap:14px; margin:12px 0 6px}
.champ-photo{
  width:96px; height:96px; border-radius:16px; flex:0 0 auto; overflow:hidden;
  background:rgba(255,255,255,.10); border:2px solid var(--gold);
  display:flex; align-items:center; justify-content:center; font-size:40px;
}
.champ-photo img{width:100%; height:100%; object-fit:cover; display:block}
.champ-name{font-size:20px; font-weight:800; letter-spacing:.4px; line-height:1.25; min-width:0; word-break:break-word}
.champ-actions{display:flex; gap:8px; margin-top:10px}
.champ-actions .btn, .champ-actions .btn.ghost{
  background:rgba(0,0,0,.30); color:#fff; border:1px solid rgba(255,255,255,.42); font-weight:700;
}
.champ-actions .btn:hover{background:rgba(0,0,0,.42)}

.app-footer{
  position:fixed; left:0; right:0; bottom:0; z-index:20;
  display:flex; gap:8px; padding:10px 12px calc(10px + env(safe-area-inset-bottom));
  background:rgba(255,255,255,.94); backdrop-filter:blur(8px); border-top:1px solid var(--line);
  max-width:1400px; margin:0 auto;
}
.btn{
  flex:1; border:0; border-radius:11px; padding:11px 8px; font-size:13px; font-weight:600; cursor:pointer;
  background:#E2E8F0; color:var(--navy); white-space:nowrap;
}
.btn:active{transform:scale(.98)}
.btn.primary{background:var(--navy); color:#fff}
.btn.danger{background:#FEE2E2; color:var(--red)}
.btn.ghost{background:#F1F5F9}

.modal{position:fixed; inset:0; background:rgba(15,23,42,.5); display:none; align-items:center; justify-content:center; z-index:40; padding:16px}
.modal.open{display:flex}
.modal-card{background:#fff; border-radius:16px; padding:18px; width:100%; max-width:440px; box-shadow:0 20px 50px rgba(0,0,0,.3)}
.modal-card h3{margin:0 0 14px; color:var(--navy)}
.fld{display:block; margin-bottom:12px}
.fld>span{display:block; font-size:13px; font-weight:600; color:var(--muted); margin-bottom:5px}
.fld em{font-weight:400; font-style:normal; opacity:.8}
.fld input,.fld textarea,.fld select{
  width:100%; padding:10px; border:1px solid var(--line); border-radius:10px; font-size:14px; font-family:inherit
}
.warn{font-size:12px; color:#B45309; background:#FFFBEB; padding:8px 10px; border-radius:9px; margin:0 0 12px}
.modal-actions{display:flex; gap:8px}

.toast{
  position:fixed; left:50%; bottom:92px; transform:translateX(-50%) translateY(12px);
  background:var(--navy); color:#fff; padding:10px 16px; border-radius:11px; font-size:13.5px;
  opacity:0; pointer-events:none; transition:.2s; z-index:60; max-width:90vw; text-align:center;
}
.toast.show{opacity:1; transform:translateX(-50%) translateY(0)}

/* Xuống 1 cột trên màn nhỏ (điện thoại): lịch thi đấu nằm trên, xếp hạng bên dưới */
@media (max-width:1024px){
  .layout{grid-template-columns:1fr}
}
@media print{
  .app-header,.app-footer,.hint,.toast,.row-actions,.champ-actions,#btnAddPlayer,.del-btn,.add-player,.p-actions,.wheel-stage,.wheel-actions,.wheel-controls,.row-btns{display:none!important}
  .layout{grid-template-columns:1fr 1fr; max-width:none; padding:0}
  body{background:#fff; padding:0}
  .card{box-shadow:none; border:1px solid var(--line); page-break-inside:avoid}
  .score-in{border:1px solid var(--line); background:#fff}
}
