/* Shared controls, dialogs, and responsive primitives. */
:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17212b;
  --muted: #687684;
  --line: #dfe5ea;
  --brand: #176b57;
  --brand-dark: #105343;
  --good: #087a56;
  --bad: #c33d3d;
  --warn-bg: #fff8e8;
  --warn-line: #f0d78f;
}

* { box-sizing: border-box; }
html { touch-action: manipulation; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
.page { width: min(1100px, calc(100% - 32px)); margin: 36px auto 60px; }
.ocr-timing { margin: 0 0 10px; color: var(--muted); font-size: 13px; text-align: right; }
h1 { margin: 0; font-size: clamp(25px, 4vw, 36px); letter-spacing: -.5px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 4px 16px rgba(25, 38, 48, .05);
}
.panel + .panel { margin-top: 18px; }
.panel-title { margin: 0 0 16px; font-size: 18px; }
label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
input {
  width: 100%; height: 42px; padding: 0 12px;
  border: 1px solid #cfd7de; border-radius: 8px;
  background: #fff; color: var(--text); font: inherit; outline: none;
}
input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(23, 107, 87, .12); }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
select {
  width: 100%; height: 42px; padding: 0 12px; border: 1px solid #cfd7de;
  border-radius: 8px; background: #fff; color: var(--text); font: inherit;
}
.player-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.player-card { padding: 14px; background: #f8fafb; border: 1px solid var(--line); border-radius: 10px; }
.player-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.player-name { margin: 0; font-size: 15px; }
.odds-value {
  min-width: 58px; height: 34px; padding: 3px 8px; border: 1px solid #c8d4d0; border-radius: 6px;
  background: #e6f1ed; color: var(--brand-dark); text-align: center; font-weight: 700;
}
input[type="range"] {
  height: 24px; padding: 0; border: 0; border-radius: 0;
  background: transparent; box-shadow: none; accent-color: var(--brand); cursor: grab;
}
input[type="range"]:active { cursor: grabbing; }
.odds-control { display: grid; grid-template-columns: 38px 1fr 38px; align-items: center; gap: 7px; }
.step-button { padding: 0; height: 34px; border: 1px solid #c8d4d0; background: #eef5f2; color: var(--brand-dark); font-size: 20px; line-height: 1; }
.step-button:hover { background: #dcebe5; }
.range-scale { display: flex; justify-content: space-between; margin-top: 2px; color: #8a969f; font-size: 11px; }
button {
  border: 0; border-radius: 8px; padding: 11px 22px;
  background: var(--brand); color: white; font: 600 15px inherit; cursor: pointer;
}
button:hover { background: var(--brand-dark); }
button:disabled { opacity: .6; cursor: wait; }
.secondary-button { padding: 9px 13px; border: 1px solid #b9ccc5; background: #eef5f2; color: var(--brand-dark); font-size: 14px; }
.secondary-button:hover { background: #dcebe5; }
.odds-value:hover { background: #dcebe5; }
.error { color: var(--bad); font-size: 14px; }
.hidden { display: none !important; }
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.metric { padding: 15px; border: 1px solid var(--line); border-radius: 10px; }
.metric span { display: block; color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 5px; font-size: 22px; }
.positive { color: var(--good) !important; }
.negative { color: var(--bad) !important; }
.neutral { color: var(--text) !important; }
.status { margin: 15px 0 0; font-weight: 600; }
.table-wrap { overflow-x: auto; margin-top: 18px; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th { color: var(--muted); font-size: 13px; font-weight: 600; }
th:first-child, td:first-child { text-align: left; }
.stake { font-size: 17px; font-weight: 700; color: var(--brand); }
footer { color: var(--muted); font-size: 13px; margin-top: 18px; text-align: center; }

.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10, 20, 27, .62); }
.modal-card {
  position: relative; width: min(460px, 100%); max-height: min(760px, calc(100dvh - 32px)); overflow-y: auto;
  padding: 20px; border-radius: 16px; background: var(--panel); box-shadow: 0 18px 55px rgba(0, 0, 0, .25);
}
.modal-card.wide { width: min(680px, 100%); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.modal-header h2 { margin: 0; font-size: 19px; }
.modal-header-actions { display: flex; align-items: center; gap: 8px; }
.icon-button { width: 38px; height: 38px; padding: 0; border: 1px solid var(--line); background: #f4f6f8; color: var(--text); font-size: 22px; }
.icon-button:hover { background: #e8ecef; }
.keypad-display { height: 56px; margin-bottom: 12px; font-size: 25px; font-weight: 700; text-align: right; }
.keypad-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.keypad-key { min-height: 52px; padding: 8px; background: #eef5f2; color: var(--brand-dark); font-size: 20px; }
.keypad-key:hover { background: #dcebe5; }
.keypad-key.action { font-size: 15px; }
.keypad-actions, .ocr-actions { display: flex; gap: 10px; margin-top: 12px; }
.keypad-actions button, .ocr-actions button { flex: 1; }
.camera-stage { position: relative; overflow: hidden; width: 100%; aspect-ratio: 16 / 9; margin: 14px auto 0; border-radius: 10px; background: #10171c; }
.camera-stage video, .camera-stage img { display: block; width: 100%; height: 100%; object-fit: contain; }
.camera-stage.selecting { touch-action: none; cursor: crosshair; }
.scan-selection { position: absolute; border: 2px solid #72efb4; background: rgba(114,239,180,.12); pointer-events: none; }
.ocr-note, .ocr-status { margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.ocr-status { min-height: 21px; color: var(--brand-dark); }
.screen-monitor {
  position: sticky; top: 10px; z-index: 10; display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px; padding: 10px 14px; border: 1px solid #8fc5ad; border-radius: 12px;
  background: #eaf7ef; box-shadow: 0 6px 18px rgba(25, 38, 48, .12);
}
.screen-monitor[data-state="stopped"] { border-color: #dfc893; background: #fff8e8; }
.screen-monitor-indicator { width: 10px; height: 10px; flex: none; border-radius: 50%; background: #13845d; }
.screen-monitor[data-state="stopped"] .screen-monitor-indicator { background: #a06a17; }
.screen-monitor-copy { flex: 1; min-width: 0; }
.screen-monitor-copy strong { display: block; font-size: 14px; }
.screen-monitor-copy span { display: block; font-size: 12px; color: #415a51; }
.screen-monitor-clock { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 700; }
.screen-monitor button { padding: 7px 12px; font-size: 13px; white-space: nowrap; }
.screen-monitor .screen-monitor-dismiss { padding: 4px 8px; background: transparent; color: var(--text); font-size: 20px; }
.modal-open { overflow: hidden; }

@media (max-width: 820px) {
  .player-grid { grid-template-columns: repeat(2, 1fr); }
  .summary { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 540px) {
  .page { width: min(100% - 20px, 1100px); margin-top: 20px; }
  .panel { padding: 16px; }
  .player-grid { grid-template-columns: 1fr; }
  .metric strong { font-size: 19px; }
  input, select { font-size: 16px; }
  .modal { padding: 10px; align-items: end; }
  .modal-card { max-height: calc(100dvh - 20px); padding: 16px; border-radius: 16px 16px 10px 10px; }
  .screen-monitor { flex-wrap: wrap; top: 4px; }
  .screen-monitor-copy { flex-basis: calc(100% - 24px); }
}
