:root{
  --bg:#f4f4f4;
  --card:#fff;
  --text:#111;
  --muted:#6b6b6b;
  --accent:#2e7d32;
  --accent2:#1565c0;
  --danger:#f44336;
  --border:#dedede;
  --shadow: 0 10px 30px rgba(0,0,0,0.06);
}

*{box-sizing:border-box}
body{margin:0;font-family:Arial, Helvetica, sans-serif;background:var(--bg);color:var(--text)}
a{color:inherit}
.muted{color:var(--muted)}

.topbar{
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding:14px 16px;
  background:var(--card);
  border-bottom:1px solid var(--border);
  position:sticky; top:0; z-index:5;
}
.brand{font-weight:800;font-size:18px}
.whoami{font-weight:400;color:var(--muted);margin-left:8px}
.top-actions{display:flex;gap:8px;align-items:center}

/* Topbar hamburger menu */
.top-actions{position:relative}
.hamburger {
  display:flex;
  flex-direction:column;
  display:none;
  width:44px;
  height:44px;
  border-radius:12px;
  border:1px solid var(--border);
  background:var(--card);
  cursor:pointer;
  align-items:center;
  justify-content:center;
  gap:4px;
  padding:0;
}
.hamburger span{
  display:block;
  width:18px;
  height:2px;
  background:#111;
  border-radius:999px;
}
.menu-panel{display:flex;gap:8px;align-items:center}

/* Mobile dropdown */
/* Show hamburger only on smaller screens */
@media (max-width: 900px){
  .hamburger{display:inline-flex}
  .menu-panel{
    display:none;
    position:absolute;
    right:0;
    top:52px;
    flex-direction:column;
    align-items:stretch;
    gap:8px;
    padding:10px;
    background:var(--card);
    border:1px solid var(--border);
    border-radius:18px;
    box-shadow: var(--shadow);
    min-width: 240px;
  }
  .top-actions.open .menu-panel{display:flex}
  .menu-panel .btn{width:100%; text-align:left}
}


.page{padding:16px; max-width:1200px; margin:0 auto}

.btn{
  display:inline-block;
  padding:9px 12px;
  border-radius:12px;
  text-decoration:none;
  border:1px solid var(--border);
  background:var(--card);
  cursor:pointer;
}
.btn:hover{filter:brightness(0.98)}
.btn.danger{background:var(--danger);border-color:var(--danger);color:#fff}
.btn.tiny{padding:6px 10px;border-radius:10px;font-size:12px}

.card{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:18px;
  box-shadow: var(--shadow);
  padding:14px;
}

.toast{
  position:fixed;
  left:50%;
  transform:translateX(-50%);
  bottom:18px;
  background:#111;
  color:#fff;
  padding:10px 12px;
  border-radius:999px;
  opacity:0;
  pointer-events:none;
  transition:opacity .2s ease, transform .2s ease;
  z-index:10;
}
.toast.show{opacity:0.95; transform:translateX(-50%) translateY(-4px);}

.board-skeleton{
  background:rgba(255,255,255,0.7);
  border:1px dashed var(--border);
  border-radius:16px;
  padding:20px;
}

.board{display:flex;flex-direction:column;gap:12px}
.board-head{display:flex;flex-direction:column;gap:4px}
.board-title{font-weight:800}
.board-sub{color:var(--muted);font-size:13px}



.table-wrap{
  position: relative;
  overflow-x:auto;
  overflow-y:visible;
  border-radius:18px;
  border:1px solid var(--border);
  background:var(--card);
  box-shadow: var(--shadow);
}

.ownership{width:100%;border-collapse:separate;border-spacing:0;table-layout:fixed}
.ownership th, .ownership td{border-bottom:1px solid #eee; padding:12px; vertical-align:top; background:var(--card)}

/* Board column sizing (JS sets --games-col-w and --fam-col-w) */
.ownership th.games-col, .ownership td.game-cell{width:var(--games-col-w, 320px);}
.ownership th.family-col, .ownership td.family-col{width:var(--fam-col-w, 150px);}

/* When columns are squeezed, tighten padding a bit */
.ownership.compact th, .ownership.compact td{padding:10px;}
.sticky-left{position:sticky; left:0; border-right:1px solid var(--border)}

/* NOTE: Sticky headers are implemented via a JS-created fixed overlay header.
   This avoids the CSS sticky + overflow-x conflict that prevents sticking. */
.ownership thead th{background:var(--card)}

/* The "Games" column is sticky-left in the body; keep it above other body cells. */
.ownership tbody .sticky-left{z-index:2;}

/* Fixed overlay header (created in script.js) */
.ownership-sticky-wrap{
  position:fixed;
  display:none;
  z-index:4; /* below topbar (z-index:5) */
  pointer-events:none;
  border-radius:0;
  overflow:hidden;
  background:transparent;
}
.ownership-sticky-left,
.ownership-sticky-right{position:absolute; top:0; bottom:0;}

.ownership-sticky-left{left:0;}
.ownership-sticky-right{left:0; overflow:hidden;}
.ownership-sticky-right-inner{will-change:transform;}

.ownership-sticky-wrap .ownership{
  border-collapse:separate;
  border-spacing:0;
  table-layout:fixed;
}
.ownership-sticky-wrap th{
  border-bottom:1px solid #eee;
  background:var(--card);
}

/* Darker divider under the family headers (right section) */
.ownership-sticky-right th{
  border-bottom:2px solid #555;
}

/* Ensure the fixed "Games" header cell stays above the moving family headers */
.ownership-sticky-left th{position:relative; z-index:2;}

.family-col{
  text-align:center;
  border-right:1px solid #eeeeeead;
  min-width:var(--fam-col-w, 150px);
}
.family-name{font-weight:800}
.family-sub{color:var(--muted);font-size:12px;margin-top:4px}

.game-card{display:flex;flex-direction:column;gap:6px;align-items:stretch}
.game-main{display:flex;gap:12px;align-items:center}
.game-bottom{display:flex;gap:10px;align-items:center;justify-content:space-between}
.game-meta{min-width:0}
.game-img{
  width:56px;height:56px;border-radius:14px;object-fit:cover;
  cursor:grab; transition:transform .15s ease, box-shadow .15s ease, outline .15s ease;
}
.game-img:hover{transform:scale(1.03); box-shadow:0 10px 24px rgba(0,0,0,0.14)}
.game-img:active{cursor:grabbing}
.game-img.selected{outline:3px solid var(--accent); box-shadow:0 10px 24px rgba(46,125,50,0.20)}
.game-name{font-weight:800}
.game-top{display:flex;align-items:center;justify-content:space-between;gap:10px}
.game-actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.game-actions .official-link{margin-left:0}

.game-hint{color:var(--muted);font-size:12px;margin-top:0;white-space:nowrap}

.family-drop{transition:transform .12s ease, box-shadow .12s ease, background .12s ease, outline .12s ease}
.family-drop.over{outline:2px dashed var(--accent); background:#f3fff5; box-shadow:0 10px 26px rgba(46,125,50,0.10); transform:translateY(-1px)}
.own-cell{min-height:84px}
.own-cell.owner{background:#f3fff5}
.owner-badge{
  display:inline-block;
  padding:4px 8px;
  border-radius:999px;
  background:rgba(46,125,50,0.12);
  color:var(--accent);
  font-weight:800;
  font-size:12px;
}
.owner-small{margin-top:8px;color:var(--muted);font-size:12px}
.date-label{font-weight:700;color:#444}
.played{display:flex;align-items:center;gap:8px;margin-top:10px;font-weight:700}
.played input{transform:scale(1.1)}
.admin-date{margin-top:10px;padding-top:10px;border-top:1px dashed #ddd}
.admin-date label{display:block;color:var(--muted);font-size:12px;margin-bottom:6px}
.admin-date input{padding:8px 10px;border:1px solid var(--border);border-radius:12px}

.dropping{animation:pulse .25s ease}
@keyframes pulse{
  from{transform:scale(1)}
  to{transform:scale(1.01)}
}

.fade-in{animation:fadeIn .25s ease}
.fade-out{opacity:0.55}
@keyframes fadeIn{
  from{opacity:0; transform:scale(0.99)}
  to{opacity:1; transform:scale(1)}
}

/* Admin timeline filters */
.filter-card{margin-bottom:12px}
.filters{display:grid; grid-template-columns: 1fr 1fr 1fr 1fr auto; gap:10px; align-items:end}
.filter label{display:block;font-size:12px;color:var(--muted);margin-bottom:6px}
.filter select, .filter input{
  width:100%;
  padding:10px 12px;
  border:1px solid var(--border);
  border-radius:12px;
  background:#fff;
}
.filter-actions{display:flex;gap:8px;justify-content:flex-end}

.timeline{padding:14px}
.timeline-inner{display:flex;flex-direction:column;gap:10px}
.timeline-title{font-weight:800}
.timeline-sub{color:var(--muted);font-size:13px;margin-bottom:6px}
.timeline-day{margin-top:10px;font-weight:800;color:#333}
.timeline-event{display:flex;gap:10px;align-items:flex-start}
.timeline-event .dot{
  width:10px;height:10px;border-radius:999px;background:var(--accent2);margin-top:6px;flex:0 0 auto
}
.event-main{font-weight:800}
.event-arrow{margin:0 6px;color:var(--muted)}
.event-sub{font-size:12px;margin-top:4px}

/* Login */
.login-page{display:flex;min-height:100vh;align-items:center;justify-content:center;padding:18px}
.login-card{width:min(420px, 100%); padding:18px}
.login-card h1{margin:0 0 12px 0;font-size:22px}
.login-form{display:flex;flex-direction:column;gap:10px}
.login-form input{
  padding:10px 12px;
  border-radius:12px;
  border:1px solid var(--border);
  font-size:14px;
}
.login-form button{
  padding:10px 12px;
  border-radius:12px;
  border:none;
  background:var(--accent);
  color:#fff;
  font-weight:800;
  cursor:pointer;
}
.login-form button:hover{filter:brightness(0.95)}
.hint{margin-top:10px;color:var(--muted);font-size:13px}
.error{background:#ffe9e9;border:1px solid #ffb7b7;color:#8a1f1f;padding:10px 12px;border-radius:12px;margin-bottom:10px}

/* Mobile */
@media (max-width: 980px){
  .filters{grid-template-columns: 1fr 1fr; }
  .filter-actions{grid-column:1 / -1; justify-content:flex-start}
}
@media (max-width: 520px){
  .whoami{display:none}
}


/* Played status shown for everyone */
.played-row{margin-bottom:8px}
.played-lite{
  font-size:12px;
  color: var(--muted);
  opacity: 0.85;
}
.played-lite.yes{color: var(--accent); opacity: 0.75;}
.played-lite.no{color: var(--muted); opacity: 0.75;}
.played-toggle-label{
  display:flex;
  align-items:center;
  gap:8px;
  font-weight:700;
  font-size:12px;
  color:#333;
}
.played-toggle-label input{transform:scale(1.05)}
.played-toggle-label .played-text{color: var(--muted); font-weight:700}

/* Admin manage games */
.form-grid{
  display:grid;
  grid-template-columns: 1fr 1fr auto;
  gap:10px;
}

/* Profile page: keep fields consistent and avoid the admin 3-column grid */
.profile-grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:10px;
}
.text-input{
  width:100%;
  padding:10px 12px;
  border:1px solid var(--border);
  border-radius:12px;
  background:#fff;
}
.text-input:disabled{
  background:#faefe1; /* slightly muted (still readable) */
  border-color:#ddd;
  color:#555;
  cursor:default;
  font-style: italic;
}
.simple-table{width:100%;border-collapse:collapse}
.simple-table th,.simple-table td{padding:10px;border-top:1px solid #eee;text-align:left}
.simple-table thead th{border-top:none}

/* Click-to-sort headers (admin overview) */
.simple-table th.sortable{cursor:pointer;user-select:none;position:relative;padding-right:24px}
.simple-table th.sortable::after{
  content:"";
  position:absolute;
  right:10px;
  top:50%;
  transform:translateY(-50%);
  width:0;height:0;
  border-left:5px solid transparent;
  border-right:5px solid transparent;
  opacity:.25;
}
.simple-table th.sortable[data-sort-dir="asc"]::after{border-bottom:7px solid currentColor;opacity:.75}
.simple-table th.sortable[data-sort-dir="desc"]::after{border-top:7px solid currentColor;opacity:.75}
.btn.tiny.danger{background:var(--danger);border-color:var(--danger);color:#fff}
@media (max-width: 720px){
  .form-grid{grid-template-columns:1fr}
  .profile-grid{grid-template-columns:1fr}
}



/* Phase 1: make Games column thinner on mobile so families are easier to see */
@media (max-width: 720px){
  .games-col{width:190px;}
  .game-card{gap:8px;}
  .game-img{width:44px;height:44px;border-radius:12px;}
  .game-name{font-size:13px;}
  .game-hint{display:none;}
  .ownership th, .ownership td{padding:10px;}
}
@media (max-width: 420px){
  .games-col{width:160px;}
  .game-img{width:40px;height:40px;}
  .family-col{min-width:150px;}
}



/* Phase 2: admin upload input */
.file-input{
  width:100%;
  padding:10px 12px;
  border:1px dashed var(--border);
  border-radius:12px;
  background:#fff;
}
.phase2-grid{grid-template-columns: 1fr 1fr 1fr auto;}
@media (max-width: 980px){
  .phase2-grid{grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px){
  .phase2-grid{grid-template-columns: 1fr; }
}



/* Phase 3: Change password form */
.pw-grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:10px;
  align-items:end;
}
.pw-grid > div:nth-child(3){grid-column:1 / -1;}
@media (max-width: 720px){
  .pw-grid{grid-template-columns:1fr;}
  .pw-grid > div:nth-child(3){grid-column:auto;}
}



/* Phase 4: categories UI */
.cat-badge{
  display:inline-block;
  margin-left:10px;
  padding:4px 10px;
  border-radius:999px;
  background:rgba(21,101,192,0.10);
  color:var(--accent2);
  font-weight:800;
  font-size:12px;
  border:1px solid rgba(21,101,192,0.18);
}
.cat-grid{
  display:grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap:10px;
  margin-top:10px;
}
.cat-card{
  text-align:left;
  border:1px solid var(--border);
  background:#fff;
  border-radius:16px;
  padding:14px;
  cursor:pointer;
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
}
.cat-card:hover{transform:translateY(-1px); box-shadow:0 14px 34px rgba(0,0,0,0.08);}
.cat-name{font-weight:900}
.cat-sub{margin-top:6px;font-size:12px}
@media (max-width: 720px){
  .cat-grid{grid-template-columns:1fr;}
}
.official-link{
  margin-left:8px;
  font-size:12px;
  font-weight:400;
  color:var(--accent2);
  text-decoration:none;
}
.official-link:hover{text-decoration:underline;}



/* Phase 5: manage families */
.fam-grid{grid-template-columns: 1fr 1fr 1fr auto;}
@media (max-width: 980px){
  .fam-grid{grid-template-columns: 1fr 1fr;}
}
@media (max-width: 720px){
  .fam-grid{grid-template-columns: 1fr;}
}
.tick-grid{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap:8px;
  padding:10px;
  border:1px solid var(--border);
  border-radius:12px;
  background:#fff;
}
.tick{display:flex;align-items:center;gap:8px;font-weight:700;font-size:13px;color:#333;}
.tick input{transform:scale(1.05)}
.overview-filter{
  display:flex;
  gap:10px;
  align-items:end;
  max-width:520px;
}
@media (max-width: 720px){
  .tick-grid{grid-template-columns:1fr;}
  .overview-filter{flex-direction:column;align-items:stretch;}
}



/* Phase 6: edit families + played matrix */
.edit-panel{
  border:1px solid var(--border);
  border-radius:16px;
  padding:12px;
  background:#fbfbff;
}
.edit-grid{
  display:grid;
  grid-template-columns: 1fr 1.2fr;
  gap:12px;
}
.reset-row{
  display:flex;
  gap:8px;
  align-items:center;
}
.btn.ghost{
  background:#fff;
  border-color: var(--border);
  color:#333;
}
.matrix td.owner{
  background: rgba(21,101,192,0.08);
}
.pill{
  display:inline-block;
  padding:4px 10px;
  border-radius:999px;
  font-size:12px;
  font-weight:800;
  border:1px solid rgba(0,0,0,0.06);
}
.pill.yes{background: rgba(46,125,50,0.10); color: rgba(46,125,50,0.95);}
.pill.no{background: rgba(0,0,0,0.05); color: rgba(0,0,0,0.55);}
@media (max-width: 720px){
  .edit-grid{grid-template-columns:1fr;}
  .reset-row{flex-direction:column; align-items:stretch;}
}



/* Phase 7: remember-me checkbox */
.remember-row{
  display:flex;
  align-items:center;
  gap:10px;
  margin:10px 0 14px;
  font-weight:800;
  color:#333;
  font-size:13px;
  user-select:none;
}
.remember-row input{transform:scale(1.05)}



/* Phase 7: lists / archives */
.list-grid{grid-template-columns: 1fr 2fr auto;}
@media (max-width: 720px){
  .list-grid{grid-template-columns:1fr;}
}



/* Phase 9: modal + drag list */
.modal{
  position:fixed; inset:0;
  background:rgba(0,0,0,0.35);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:16px;
  z-index:9999;
}
.modal-card{
  width:min(720px, 100%);
  background:#fff;
  border-radius:18px;
  padding:14px;
  border:1px solid var(--border);
  box-shadow:0 20px 50px rgba(0,0,0,0.22);
  max-height:90vh;
  overflow:auto;
}
.drag-list{list-style:none;padding:0;margin:0;display:flex;flex-direction:column;gap:8px;}
.drag-item{display:flex;align-items:center;gap:10px;padding:10px 12px;border:1px solid var(--border);border-radius:14px;background:#fff;cursor:grab;}
.drag-item.dragging{opacity:0.6}
.drag-handle{font-weight:900;color:#555}



/* Game info modal */
.gi-grid{
  display:grid;
  grid-template-columns: 120px 1fr;
  gap:12px;
  align-items:start;
  margin-top:6px;
}
.gi-img{
  width:120px;
  height:120px;
  object-fit:cover;
  border-radius:16px;
  border:1px solid var(--border);
  background:#fff;
}
.gi-img-placeholder{
  width:120px;
  height:120px;
  display:flex;
  align-items:center;
  justify-content:center;
  border-radius:16px;
  border:1px dashed var(--border);
  background:#fff;
  font-size:12px;
}
.gi-meta{border:1px solid var(--border);border-radius:16px;padding:10px;background:#fff;}
.gi-row{display:flex;justify-content:space-between;gap:10px;padding:6px 0;border-bottom:1px solid var(--border);}
.gi-row:last-child{border-bottom:none;}
.gi-label{font-size:12px;color:var(--muted);}
.gi-value{font-size:13px;font-weight:600;}
.gi-section{margin-top:12px;border-top:1px solid var(--border);padding-top:12px;}
.gi-section-title{font-size:12px;color:var(--muted);margin-bottom:6px;text-transform:uppercase;letter-spacing:.04em;}
.gi-info{white-space:pre-wrap;line-height:1.4;}
@media (max-width: 520px){
  .gi-grid{grid-template-columns: 1fr; }
  .gi-img, .gi-img-placeholder{width:100%; height:180px;}
}



/* Mobile: keep Games column narrower and allow wrapping */
@media (max-width: 820px){
  .ownership{
    --games-col-w: clamp(200px, 30vw, 350px);   /* clamp for mobile */nership td.game-cell,
  .ownership th.games-col{
    max-width: 350px;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  .ownership td.game-cell a{
    display: inline-block;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  .ownership td.game-cell .game-card{
    align-items: flex-start;
  }
}


/* Busy buttons */
button.busy{ opacity:0.7; pointer-events:none; }


/* UKGE column (thinner) */
th.ukge-col, td.ukge-col { width: 64px; min-width: 64px; max-width: 64px; }


/* --- Ownership Board games column hard clamp (v4) --- */
.ownership th.games-col, .ownership td.game-cell{
  width: clamp(200px, var(--games-col-w, 320px), 350px);
  min-width: 200px;
  max-width: 350px;
  box-sizing: border-box;
}



/* "New ##" pill badge used on category tiles */
.new-badge{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #d11 !important;
  background-color: #d11 !important;
  color: #fff !important;
  font-weight: 700;
  font-size: 11px;
  line-height: 1;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,0.06);
  margin-left: 8px;
  white-space: nowrap;
}
