:root {
  --gold: #d4a760;
  --iron: #1a1a1a !important;
  --paper: #f4eee1;
  --accent: #f59e0b; /* V1 Orange */
  --primary: #007bff; /* V1 Blue */
  --danger: #ef4444;
  --success: #22c55e;
  --bg: #0a0a0a !important;
  --card: #1e1e22 !important;
  --text: #ffffff;
  --border: #444;
  --hl: rgba(212, 167, 96, 0.25);
  --hl-focus: rgba(212, 167, 96, 0.6);
}

* { margin: 0; padding: 0; box-sizing: border-box; touch-action: manipulation; }
body { font-family: -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); overflow: hidden; height: 100dvh; display: flex; flex-direction: column; }

/* TAB NAVIGATION */
.tab-bar { display: flex; background: var(--iron); border-bottom: 2px solid var(--gold); flex-shrink: 0; z-index: 2000; }
.tab-btn { flex: 1; padding: 15px 5px; border: none; background: transparent; color: #bbb; font-weight: bold; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; cursor: pointer; }
.tab-btn .lucide { display: block; margin: 0 auto 4px; width: 18px; height: 18px; }
.tab-btn.active { color: var(--gold); background: rgba(212, 167, 96, 0.1); border-bottom: 3px solid var(--gold); }

.view-container { flex-grow: 1; position: relative; overflow: hidden; }
.view { position: absolute; width: 100%; height: 100%; display: none; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.view.active { display: block; }

#combat.view { display: none; }
#combat.view.active { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

#rules.view { display: none; }
#rules.view.active { display: flex; }


/* NEW RULES STYLES */
.main-content { flex: 1; display: flex; overflow: hidden; flex-direction: row; }
.table-view { flex: 1; overflow-y: auto; padding: 12px; display: none; }
.table-view.active { display: block; }

.sidebar { width: 80px; background: #111; border-left: 1px solid var(--border); overflow-y: auto; display: flex; flex-direction: column; }
.side-btn { padding: 18px 5px; border: none; background: transparent; color: #666; font-size: 9px; font-weight: 800; text-align: center; border-bottom: 1px solid #222; text-transform: uppercase; cursor: pointer; }
.side-btn.active { color: var(--text); background: var(--card); border-right: 4px solid var(--gold); }

.grid-table { width: 100%; border-collapse: collapse; background: var(--card); font-size: 12px; table-layout: fixed; margin-bottom: 10px; }
.grid-table th { background: #2a2a2e; color: var(--gold); padding: 6px 2px; border: 1px solid var(--border); font-size: 10px; }
.grid-table td { padding: 10px 2px; text-align: center; border: 1px solid var(--border); color: #ccc; }
.hl-row, .hl-col { background-color: var(--hl); }
.hl-cell { background-color: var(--hl-focus) !important; color: white !important; font-weight: bold; }

.rule-card { background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--gold); padding: 10px; margin-bottom: 12px; }
.rule-title { font-weight: bold; color: var(--gold); display: block; text-transform: uppercase; font-size: 12px; margin-bottom: 4px; }
.rule-desc { color: #ccc; font-size: 14px; line-height: 1.4; }

#rules h2 { color: var(--gold); font-size: 14px; margin: 15px 0 8px 0; text-transform: uppercase; border-left: 3px solid var(--gold); padding-left: 8px; }
#rules strong { color: var(--gold); }

/* SHARED COMPONENTS */
.label { font-size: 10px; font-weight: 800; text-transform: uppercase; opacity: 0.9; color: #ccc; }
.stepper { display: flex; align-items: center; justify-content: center; gap: 4px; }
.btn-step { width: 34px; height: 34px; background: #333; border: 1px solid #666; color: #fff; font-size: 20px; font-weight: bold; border-radius: 4px; }
.val-box { min-width: 36px; height: 34px; background: #000; border: 1px solid var(--gold); display: flex; align-items: center; justify-content: center; font-size: 18px; border-radius: 4px; color: white; cursor: pointer; }

/* COMBAT STYLES */

/* Top result bar */
.combat-top-bar {
  background: #000;
  border-bottom: 2px solid var(--gold);
  padding: 6px 8px;
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  align-items: center;
  flex-shrink: 0;
  min-height: 72px;
}
.combat-score-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.combat-score-side .side-label { font-size: 8px; font-weight: 800; text-transform: uppercase; color: #888; letter-spacing: 1px; }
.combat-score-side .score-val { font-size: 28px; font-weight: 900; color: var(--gold); line-height: 1; font-variant-numeric: tabular-nums; }
.combat-score-side.winner .score-val { color: var(--success); }
.combat-score-side.loser  .score-val { color: #555; }

.res-info { text-align: center; padding: 0 4px; }
#winner-text { color: var(--gold); font-size: 24px; font-weight: 800; display: block; line-height: 1.2; text-transform: uppercase; }
.break-text { font-size: 10px; opacity: 0.7; color: #fff; display: block; margin-top: 2px; }

#reset-combat-btn {
  background: #4f2020;
  color: #ffc2c2;
  padding: 12px 30px;
  border: 1px solid var(--danger);
  border-radius: 8px;
  font-weight: bold;
  font-size: 13px;
  text-transform: uppercase;
}

.combat-bottom-bar {
  padding: 8px;
  background: #000;
  border-top: 1px solid #333;
  display: flex;
  justify-content: center;
  flex-shrink: 0;
}

/* Battlefield two-column grid */
.battlefield { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 5px; flex-shrink: 0; }
.unit-card { background: var(--card); border: 1px solid #444; border-radius: 6px; padding: 6px; }
.unit-name { width: 100%; border: none; border-bottom: 1px solid #555; background: transparent; color: var(--gold); text-align: center; font-weight: bold; font-size: 12px; margin-bottom: 5px; padding-bottom: 3px; }

/* Compact stepper rows — two per row */
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 4px; }
.stat-cell { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stat-cell .label { font-size: 8px; }
.stat-cell .stepper { gap: 2px; }
.stat-cell .btn-step { width: 26px; height: 26px; font-size: 16px; }
.stat-cell .val-box { min-width: 28px; height: 26px; font-size: 14px; }

/* Chip grid */
.toggle-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; margin-top: 4px; }
.chip { display: block; padding: 5px 2px; border: 1px solid #555; border-radius: 4px; font-size: 8px; text-align: center; background: #2a2a2e; color: #eee; font-weight: bold; }
input[type="checkbox"] { display: none; }
input[type="checkbox"]:checked + .chip { background: var(--gold); color: #000; border-color: #fff; }

/* Score val used elsewhere */
.score-val { font-size: 20px; font-weight: bold; color: var(--gold); }

/* Break test panel — always visible */
#break-test-panel {
  flex-shrink: 0;
  background: #0d0d0d;
  border-top: 1px solid #2a2a2a;
  padding: 5px 8px;
}
.bt-title {
  font-size: 8px; font-weight: 800; text-transform: uppercase;
  letter-spacing: 1px; color: #555; text-align: center; margin-bottom: 4px;
}
.bt-rows { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 3px; }
.bt-row {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 4px 3px; border-radius: 4px; border: 1px solid transparent; text-align: center;
}
.bt-outcome { font-size: 7px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.3px; opacity: 0.8; margin-bottom: 2px; }
.bt-range { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.bt-gives  { background: #0e2a1a; border-color: #1a5c35; color: #4ade80; }
.bt-falls  { background: #2a1f00; border-color: #6b4f00; color: #f59e0b; }
.bt-breaks { background: #2a0a0a; border-color: #7f1d1d; color: #f87171; }
.bt-empty  { background: #111; border-color: #2a2a2a; color: #333; }
.bt-empty .bt-range { font-size: 9px; }

/* Optional label dimming */
.label-optional { opacity: 0.4; }

/* WHEEL STYLES */
#wheel-canvas { background: #000; width: 100%; height: 280px; border-bottom: 1px solid #333; display: block; touch-action: none; cursor: pointer; }
.wheel-canvas-wrapper { position: relative; }
.wheel-snap-strip {
    position: absolute;
    top: 50%;
    right: 8px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    z-index: 2;
    transform: translateY(-50%);
}
.wheel-snap-btn {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    border: 1px solid #555;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #eee;
    font-size: 11px;
    font-weight: 700;
    box-shadow: 0 0 4px rgba(0,0,0,0.8);
}
.wheel-snap-btn-max {
    border-color: var(--gold);
    color: var(--gold);
}
.wheel-res-box { padding: 15px; text-align: center; background: #0a0a0a; border-bottom: 1px solid #333; display: flex; justify-content: space-around; align-items: center; position: relative; }
.wheel-main-res { font-size: 36px; font-weight: 800; color: var(--success); }
.wheel-sub-res { font-size: 24px; font-weight: 600; color: var(--gold); }
#wheel-warning { 
    position: absolute; bottom: 0; left: 0; right: 0;
    color: var(--danger); font-size: 10px; font-weight: bold; 
    text-align: center; background: rgba(0, 0, 0, 0); 
    padding: 2px 0; display: none; pointer-events: none;
}
.wheel-controls { padding: 10px; }
.input-group { background: var(--card); border-radius: 8px; padding: 8px; margin-bottom: 8px; border: 1px solid #333; }
.preset-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-top: 5px; }
.preset-btn { background: #333; border: 1px solid #555; color: white; padding: 8px 0; border-radius: 4px; font-size: 12px; font-weight: bold; }
.wheel-row-3 { display: grid; grid-template-columns: 1.2fr 0.6fr 1.2fr; gap: 5px; margin-bottom: 8px; }

/* CHARGE STYLES */
.charge-panel { text-align: center; padding: 15px 0; background: #000; border-bottom: 1px solid #333; margin-bottom: 10px; }
#c-prob-val { font-size: 4rem; font-weight: 900; line-height: 1; margin: 10px 0; }
.charge-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; padding: 0 10px; }
.c-toggle { background: #2a2a2e; padding: 12px; border-radius: 8px; text-align: center; font-size: 10px; font-weight: bold; border: 1px solid #444; color: #ccc; margin-bottom: 6px; cursor: pointer; }
.c-toggle.active { border-color: var(--gold); color: #000; background: var(--gold); }

/* KEYPAD */
#keypad-modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); z-index: 3000; justify-content: center; align-items: center; }
.keypad-content { background: #1a1a1a; padding: 15px; border-radius: 12px; border: 2px solid var(--gold); width: 280px; }
.key-btn { padding: 20px; background: #333; border: 1px solid #555; border-radius: 8px; font-size: 20px; font-weight: bold; color: white; text-align: center; }

/* UTILITY CLASSES */
.btn-reset { background:#333; border:1px solid #666; color:#fff; font-weight:bold; font-size:10px; padding:30px 8px; margin-right:5px; border-radius:4px; }
.break-text { font-size:10px; opacity:0.8; color:#fff; }
.unit-stat-group { text-align:center; margin-bottom:10px; }
.grid-span-2 { grid-column: span 2; }
.val-box-sm { font-size:14px; }
.label-center { display:block; text-align:center; margin-bottom:4px; }
.march-container { display:flex; align-items:flex-end; justify-content:center; padding-bottom:25px; }
.march-chip { padding: 10px 0; font-size: 8px; }
.full-width { width:100%; }
.preset-btn-custom { color:var(--gold); }
.angle-slider { width:100%; accent-color:var(--gold); margin: 10px 0; }
.preset-btn-snap { background:var(--gold); color:black; }
.charge-stats-grid { display:grid; grid-template-columns: 1fr 1fr; margin-top:10px; }
.charge-stat-val { font-weight:bold; font-size:18px; color:white; }
.label-lg { font-size:14px; }
.val-box-lg { min-width: 60px; }
.charge-toggles-container { padding:0 10px; }
.keypad-title { text-align:center; color:var(--gold); font-size:12px; font-weight:bold; text-transform:uppercase; margin-bottom:10px; }
.keypad-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key-btn-danger { background:var(--danger); }
.key-btn-success { background:var(--success); color:black; }

/* ABOUT STYLES */
.about-content { padding: 15px; color: #ccc; }
.about-content h2 { color: var(--gold); font-size: 18px; margin-bottom: 10px; }
.about-content h3 { color: var(--gold); font-size: 16px; margin-top: 20px; margin-bottom: 8px; border-bottom: 1px solid #444; padding-bottom: 4px;}
.version-tag { background: var(--gold); color: #000; font-size: 10px; padding: 2px 6px; border-radius: 4px; font-weight: bold; vertical-align: middle; }
.about-overview { font-size: 14px; line-height: 1.5; }
.changelog { list-style-type: disc; padding-left: 20px; }
.changelog li { margin-bottom: 8px; font-size: 13px; }

/* === UI POLISH v1.2 ADDITIONS === */
.val-box,
.score-val,
.charge-stat-val,
#wheel-result,
#wheel-angle-res {
  font-variant-numeric: tabular-nums;
}

.btn-step,
.preset-btn,
.key-btn,
.c-toggle {
  transition: transform .08s ease, background .12s ease;
}

.btn-step:active,
.preset-btn:active,
.key-btn:active {
  transform: scale(.94);
}

.c-toggle:active {
  transform: scale(.97);
}

.val-box.editing {
  box-shadow: 0 0 0 2px var(--gold);
}

.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* --- ARTILLERY STYLES --- */
#artillery .container { margin: 0 auto; padding-bottom: 40px; }
#artillery .canvas-block { background: #0d0d0d; border-bottom: 1px solid var(--border); position: relative; }
#artillery #battlefield { display: block; width: 100%; height: 260px; cursor: crosshair; touch-action: none; }
#artillery .canvas-hint { position: absolute; bottom: 6px; left: 0; right: 0; text-align: center; font-size: 0.75rem; color: #888; pointer-events: none; text-transform: uppercase; letter-spacing: 0.05em; }
#artillery .results-row { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--border); background: var(--iron); }
#artillery .res-cell { padding: 10px 4px; text-align: center; border-right: 1px solid var(--border); }
#artillery .res-cell:last-child { border-right: none; }
#artillery .res-val { font-size: 1.75rem; font-weight: 700; line-height: 1; margin-bottom: 3px; font-variant-numeric: tabular-nums; }
#artillery .res-label { font-size: 0.55rem; text-transform: uppercase; letter-spacing: 0.07em; color: #aaa; line-height: 1.3; }
#artillery .res-cell.full .res-val { color: #c0392b; }
#artillery .res-cell.partial .res-val { color: #e67e22; }
#artillery .res-cell.total .res-val { color: var(--text); }
#artillery .note { padding: 8px 14px; font-size: 0.8rem; color: #aaa; text-align: center; border-bottom: 1px solid var(--border); min-height: 36px; background: var(--card); }
#artillery .section { padding: 12px 14px; border-bottom: 1px solid var(--border); background: var(--card); }
#artillery .section-label { font-size: 12px; text-transform: uppercase; color: #ccc; margin-bottom: 8px; font-weight: 800; text-align: center; }
#artillery .toggle-group { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
#artillery .tog { padding: 7px 11px; border: 1px solid var(--border); border-radius: 4px; background: #2a2a2e; color: #aaa; font-size: 0.78rem; font-weight: 500; cursor: pointer; transition: background 0.12s, color 0.12s, border-color 0.12s; -webkit-tap-highlight-color: transparent; user-select: none; white-space: nowrap; }
#artillery .tog.active { background: var(--gold); border-color: var(--gold); color: #000; font-weight: bold; }
#artillery .tog:hover:not(.active) { border-color: #777; color: var(--text); }
#artillery #customRow { display: none; align-items: center; gap: 8px; margin-top: 10px; }
#artillery #customRow label { font-size: 0.75rem; color: #aaa; }
#artillery #customRow input { width: 60px; background: #2a2a2e; border: 1px solid var(--border); color: var(--text); font-size: 0.9rem; padding: 7px 8px; border-radius: 4px; outline: none; text-align: center; }
#artillery #customRow input:focus { border-color: #777; }
#artillery #customRow span { font-size: 0.85rem; color: #aaa; }

