/* ============================================================
   Mexican Train (Solo) — styles.css
   Clean + commented
   Includes:
   - Base layout + panels
   - Rules modal styling
   - Pretty Domino renderer (robust square pip canvas)
   ============================================================ */

/* =========================
   1) Theme variables
   ========================= */
:root{
  --bg:#0f172a;
  --text:#e5e7eb;
  --muted:#9ca3af;
  --card:#162247;
  --border:rgba(255,255,255,0.12);

  /* Domino sizing */
  --domino-w: 80px;
  --domino-h: 44px;

  --domino-w-board: 66px;
  --domino-h-board: 36px;

  --domino-bg: #f8fafc;
  --domino-border: rgba(0,0,0,0.18);
  --domino-shadow: 0 8px 18px rgba(0,0,0,0.22);

  /* Pip sizing */
  --pip-gap: 2px;
}

/* =========================
   2) Reset + base
   ========================= */
*{ box-sizing:border-box; }

body{
  margin:0;
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  background:radial-gradient(1200px 700px at 20% 10%, #1f2a52, var(--bg));
  color:var(--text);
}

/* =========================
   3) Buttons / Inputs
   ========================= */
button, select, input{
  border-radius:10px;
  border:1px solid var(--border);
  background:rgba(255,255,255,0.06);
  color:var(--text);
}

button{
  padding:8px 10px;
  cursor:pointer;
}

button:hover{ background:rgba(255,255,255,0.10); }

button:disabled{
  opacity:0.5;
  cursor:not-allowed;
}

select, input{
  padding:7px 10px;
}

input::placeholder{ color:rgba(229,231,235,0.6); }

/* =========================
   4) Topbar
   ========================= */
.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:14px 18px;
  border-bottom:1px solid var(--border);
  background:rgba(0,0,0,0.2);
  backdrop-filter:blur(10px);
}

.topbar h1{
  margin:0;
  font-size:18px;
  letter-spacing:0.3px;
}

.controls{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}

.ctrl{
  display:flex;
  align-items:center;
  gap:6px;
  padding:6px 8px;
  border:1px solid var(--border);
  border-radius:12px;
  background:rgba(255,255,255,0.04);
}

.ctrl-label{
  font-size:12px;
  color:var(--muted);
}

/* =========================
   5) Layout + panels
   ========================= */
.layout{
  display:grid;
  grid-template-columns:1.6fr 1fr;
  grid-template-rows:auto auto;
  gap:14px;
  padding:14px;
}

.board, .hand, .status{
  background:rgba(0,0,0,0.18);
  border:1px solid var(--border);
  border-radius:16px;
  padding:12px;
}

.board{ grid-column:1 / 2; grid-row:1 / 3; }
.hand{ grid-column:2 / 3; grid-row:1 / 2; }
.status{ grid-column:2 / 3; grid-row:2 / 3; }

.board-area, .hand-area{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  padding:8px;
  min-height:120px;
  background:rgba(255,255,255,0.03);
  border-radius:12px;
  border:1px dashed rgba(255,255,255,0.12);
}

.line{
  padding:8px 10px;
  color:var(--muted);
  font-size:13px;
}

.muted{ color:var(--muted); font-weight:500; }

/* =========================
   6) Board dropzones
   ========================= */
.dropzone{
  width:100%;
  text-align:left;
  padding:10px 12px;
  border-radius:12px;
  border:1px solid var(--border);
  background:rgba(255,255,255,0.05);
  color:var(--text);
  margin-top:10px;
}

.dropzone:hover{ background:rgba(255,255,255,0.09); }

.dropzone.inactive{ opacity:0.45; }

.dropzone.active{
  opacity:1;
  outline:2px solid rgba(255,255,255,0.22);
  box-shadow:0 0 0 3px rgba(255,255,255,0.06) inset;
}

/* =========================
   7) Sidebar panels
   ========================= */
.boneyard-line{
  margin: 6px 0 10px 0;
  color: var(--muted);
  font-size: 13px;
}

.options-panel,
.score-panel,
.log-panel{
  border:1px solid var(--border);
  background:rgba(255,255,255,0.04);
  border-radius:14px;
  padding:10px 12px;
  margin-bottom:10px;
}

.options-title,
.score-title,
.log-title{
  font-weight:700;
  margin-bottom:6px;
}

.options-box{
  color:var(--text);
  opacity:0.95;
  font-size:13px;
  line-height:1.35;
}

.score-box{
  font-size:13px;
  line-height:1.35;
  color:var(--text);
  opacity:0.95;
  white-space:pre;
}

.log-controls{
  display:grid;
  grid-template-columns: 150px 1fr auto;
  gap:8px;
  margin-bottom:10px;
}

.status-box{
  margin:0;
  white-space:pre-wrap;
  color:var(--muted);
  font-size:12px;
  max-height:320px;
  overflow-y:auto;
  padding:10px 12px;
  border:1px solid var(--border);
  border-radius:14px;
  background:rgba(255,255,255,0.03);
}

/* =========================
   8) Modals (generic)
   ========================= */
.overlay{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,0.55);
  display:flex;
  align-items:center;
  justify-content:center;
  z-index:9999;
}

.overlay.hidden{ display:none; }

.modal{
  width:min(520px, 92vw);
  border-radius:18px;
  padding:16px 18px;
  background:rgba(20,20,24,0.95);
  border:1px solid rgba(255,255,255,0.12);
  box-shadow:0 18px 60px rgba(0,0,0,0.45);
  color:#fff;
}

.modal h2{
  margin:0 0 10px 0;
  font-size:20px;
}

.modal-body{
  white-space:pre-wrap;
  font-size:14px;
  line-height:1.35;
  opacity:0.95;
}

.modal-actions{
  display:flex;
  gap:10px;
  justify-content:flex-end;
  align-items:center;
  margin-top:14px;
}

/* =========================
   9) Rules modal (compact)
   ========================= */
.icon-btn{
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover{ background: rgba(255,255,255,0.10); }

.modal-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.modal-rules{
  width: min(920px, 94vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.rules-body{
  padding-top: 4px;
  overflow-y: auto;
}

.rules-grid{
  display:grid;
  grid-template-columns: 0.85fr 1.15fr;
  gap: 10px;
}

@media (max-width: 820px){
  .rules-grid{ grid-template-columns: 1fr; }
}

.rules-panel{
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  border-radius: 12px;
  padding: 10px;
}

.rules-panel-title{
  font-weight: 800;
  margin-bottom: 6px;
  font-size: 14px;
}

.preset-list{
  display:flex;
  flex-direction:column;
  gap: 6px;
}

.preset-item{
  display:flex;
  gap: 8px;
  align-items:flex-start;
  padding: 8px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(0,0,0,0.16);
  border-radius: 10px;
  cursor: pointer;
}

.preset-item:hover{ background: rgba(0,0,0,0.24); }

.preset-item input{ margin-top: 2px; }

.preset-name{
  font-weight: 800;
  font-size: 13px;
  margin-bottom: 1px;
}

.preset-desc{
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.3;
}

.rules-note{
  margin-top: 6px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.3;
}

.toggles{
  display:flex;
  flex-direction:column;
  gap: 8px;
}

.toggle-group{
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(0,0,0,0.16);
  border-radius: 10px;
  padding: 8px;
}

.toggle-group-title{
  font-weight: 800;
  margin-bottom: 4px;
  font-size: 12.5px;
}

.toggle-row{
  display:flex;
  gap: 8px;
  align-items:flex-start;
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
}

.toggle-row:hover{ background: rgba(255,255,255,0.04); }

.toggle-row input{ margin-top: 2px; }

.toggle-text{
  display:flex;
  flex-direction:column;
  gap: 1px;
}

.toggle-name{
  font-weight: 700;
  font-size: 12.5px;
}

.toggle-desc{
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.25;
}

.toggles.disabled{
  opacity: 0.45;
  pointer-events: none;
}

/* =========================
   10) Tiles — TEXT MODE
   ========================= */
.tile.tile--text{
  width: 54px;
  height: 34px;
  border-radius:10px;
  border:1px solid var(--border);
  background:rgba(255,255,255,0.10);
  color:rgba(255,255,255,0.88);
  display:grid;
  place-items:center;
  font-weight:650;
  cursor:pointer;
  user-select:none;
}

.tile.tile--text:hover{ outline:2px solid rgba(255,255,255,0.18); }

.tile.tile--text.selected{
  outline:2px solid rgba(255,255,255,0.35);
  transform:translateY(-1px);
}

/* =========================
   11) Tiles — PRETTY DOMINO MODE
   Robust face logic:
   - Each half centers a PERFECT SQUARE pip canvas
   - 0–9 uses 3x3, 10–12 uses 3x4
   ========================= */

/* Button reset so the domino card is the visual */
.tile.tile--pretty{
  appearance: none;
  background: transparent;
  border: none;
  padding: 0;
  margin: 6px;
  cursor: pointer;
}

.tile.tile--pretty:disabled,
.tile.tile--pretty.disabled{
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

/* Selected tile glow */
.tile.tile--pretty.selected .domino{
  box-shadow: 0 0 0 3px rgba(255,255,255,0.35), 0 10px 20px rgba(0,0,0,0.25);
  transform: translateY(-1px);
}

/* Domino card */
.domino{
  width: var(--domino-w);
  height: var(--domino-h);
  background: var(--domino-bg);
  border: 1px solid var(--domino-border);
  border-radius: 6px;
  display: flex;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0,0,0,0.20);
}

/* Divider */
.domino-divider{
  width: 1px;
  background: rgba(0,0,0,0.18);
  margin: 4px 0;
}

/* Each half */
.domino-half{
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px; /* ✅ keeps pips away from rounded corners */
}

/* Micro nudge: give the RIGHT half a hair more breathing room */
.domino-half:last-child{
  padding-right: 7px; /* was effectively 4px */
}

.domino-half:first-child {
  padding-left: 3px;
}

/* The square pip canvas — ALWAYS a perfect square */
.pip-container-square{
  height: 100%;
  width: auto;
  aspect-ratio: 1 / 1;
  display: grid;
  gap: 2px;
}

/* 0–9: 3x3 */
.grid-3x3{
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}

/* 10–12: 3x4 */
.grid-3x4{
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(4, 1fr);
}

/* Cells center the pip */
.pip-cell{
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

/* Pip (circle) */
.pip{
  width: 80%;
  height: 80%;
  border-radius: 50%;
  box-shadow: inset 1px 1px 1px rgba(255,255,255,0.40);
}

/* Hover pop */
.tile.tile--pretty:not(:disabled):hover .domino{
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(0,0,0,0.26);
}

/* Board train tiles wrapper */
.train-tiles{
  display:flex;
  flex-wrap:wrap;
  gap: 2px;
  margin: 6px 0 14px;
}

/* Make onboard tiles smaller */
.tile.tile--onboard .domino{
  width: var(--domino-w-board);
  height: var(--domino-h-board);
}

/* =========================
   12) Mobile layout
   ========================= */
@media (max-width: 980px){
  .layout{
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }
  .board, .hand, .status{
    grid-column:auto;
    grid-row:auto;
  }
  .log-controls{
    grid-template-columns: 1fr;
  }
  .controls{
    justify-content:flex-start;
  }
}
