:root {
  --bg: #eef3f5;
  --surface: #ffffff;
  --surface-soft: #f7faf9;
  --ink: #111827;
  --muted: #637083;
  --line: #d9e2e7;
  --green: #078752;
  --red: #d43434;
  --black: #151b24;
  --gold: #d69c16;
  --blue: #1466b8;
  --teal: #0e9384;
  --shadow: 0 12px 32px rgba(17, 24, 39, 0.09);
  --shadow-soft: 0 8px 20px rgba(17, 24, 39, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(180deg, #e7f2ee 0, #eef3f5 310px, #eef3f5 100%),
    var(--bg);
  overflow-x: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-shell {
  width: min(1220px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 20px 0 40px;
}

.workspace {
  display: grid;
  gap: 16px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 18px;
  padding: 14px 0 8px;
}

.topbar > * {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 760px;
  font-size: clamp(2rem, 5vw, 4.2rem);
  line-height: 0.98;
  overflow-wrap: break-word;
}

h2 {
  font-size: 1rem;
  font-weight: 900;
}

.bankroll {
  display: grid;
  grid-template-columns: 120px 92px;
  gap: 10px;
  padding: 10px;
  border: 1px solid rgba(217, 226, 231, 0.85);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow-soft);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

input,
textarea,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input,
select {
  height: 42px;
  padding: 0 11px;
}

textarea {
  resize: vertical;
  padding: 10px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(14, 147, 132, 0.14);
}

.capture-grid,
.analysis-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, 0.85fr);
  gap: 16px;
}

.hidden-capture {
  display: none;
}

.capture-grid .history-panel {
  grid-column: 1 / -1;
}

.prediction-panel {
  grid-column: 1 / -1;
}

.panel {
  border: 1px solid rgba(217, 226, 231, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  padding: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  margin-bottom: 14px;
}

.icon-row,
.entry-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.icon-btn,
.primary-btn,
.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  box-shadow: 0 1px 0 rgba(17, 24, 39, 0.04);
}

.icon-btn {
  width: 42px;
  padding: 0;
}

.primary-btn,
.secondary-btn {
  padding: 0 14px;
}

.primary-btn {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.secondary-btn:hover,
.icon-btn:hover {
  border-color: #aebcc5;
  background: #f7faf9;
}

.danger {
  color: var(--red);
}

.entry-row {
  align-items: center;
  margin-bottom: 12px;
}

#numberInput {
  max-width: 96px;
  text-align: center;
  font-size: 1.45rem;
  font-weight: 900;
}

.quick-board {
  display: grid;
  grid-template-columns: repeat(13, minmax(38px, 1fr));
  gap: 6px;
  margin-bottom: 14px;
}

.num-btn,
.chip {
  aspect-ratio: 1;
  min-width: 0;
  border: 0;
  border-radius: 50%;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 950;
  line-height: 1;
}

.num-btn {
  font-size: 0.92rem;
}

.red {
  background: var(--red);
}

.black {
  background: var(--black);
}

.green {
  background: var(--green);
}

.paste-box {
  display: grid;
  gap: 8px;
}

.ocr-status {
  min-height: 38px;
  margin-top: 12px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

#screenVideo,
#captureCanvas {
  display: none;
}

.history-panel {
  display: grid;
  grid-template-columns: minmax(220px, 0.42fr) minmax(0, 1fr);
  grid-template-areas:
    "head head"
    "last strip"
    "last status"
    "last stats";
  align-items: center;
  gap: 12px 18px;
  overflow: hidden;
}

.history-panel .panel-head {
  grid-area: head;
  margin-bottom: 0;
}

.last-number {
  grid-area: last;
  width: min(220px, 100%);
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 50%;
  background: #b8c2c8;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: clamp(4rem, 12vw, 6.8rem);
  font-weight: 950;
  box-shadow:
    inset 0 0 0 11px rgba(255, 255, 255, 0.16),
    0 16px 34px rgba(17, 24, 39, 0.16);
}

.last-number.red {
  background: var(--red);
}

.last-number.black {
  background: var(--black);
}

.last-number.green {
  background: var(--green);
}

.history-strip {
  grid-area: strip;
  min-height: 96px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 7px;
}

.api-status {
  grid-area: status;
  min-height: 22px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.chip {
  width: 39px;
  height: 39px;
  font-size: 0.9rem;
  box-shadow: 0 4px 10px rgba(17, 24, 39, 0.12);
}

.stats-grid {
  grid-area: stats;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
}

.stats-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.stats-grid span {
  display: block;
  font-size: 1.35rem;
  font-weight: 950;
}

.stats-grid small {
  color: var(--muted);
  font-weight: 800;
}

.signal-list {
  display: grid;
  gap: 10px;
}

.signal {
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.signal:nth-child(2n) {
  border-left-color: var(--teal);
}

.signal:nth-child(3n) {
  border-left-color: var(--gold);
}

.signal strong {
  display: block;
  margin-bottom: 5px;
}

.signal p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.bar-list {
  display: grid;
  gap: 10px;
}

.prediction-meta {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
  text-align: right;
}

.prediction-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(76px, 1fr));
  gap: 9px;
}

.prediction-item {
  min-width: 0;
  min-height: 104px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.prediction-rank {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 950;
}

.prediction-item small {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
}

.alert-panel {
  display: grid;
  gap: 13px;
}

.telegram-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 0.72fr) minmax(180px, 0.72fr);
  gap: 10px;
}

.rules-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
}

.toggle-rule {
  grid-template-columns: 18px minmax(0, 1fr) 72px;
  align-items: center;
  gap: 8px;
  min-height: 58px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
}

.toggle-rule input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.toggle-rule input[type="number"] {
  height: 36px;
  text-align: center;
  font-weight: 900;
}

.alert-log {
  min-height: 42px;
  padding: 11px;
  border: 1px dashed #b7c5cc;
  border-radius: 8px;
  background: #fbfdfc;
  color: var(--muted);
  font-size: 0.9rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 9px;
  font-size: 0.86rem;
  font-weight: 900;
}

.track {
  height: 13px;
  border-radius: 999px;
  background: #e5edf0;
  overflow: hidden;
}

.fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold));
}

svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.2;
}

@media (max-width: 900px) {
  .app-shell {
    width: min(100vw - 24px, 1220px);
    padding-top: 12px;
  }

  .topbar,
  .capture-grid,
  .analysis-grid,
  .telegram-grid,
  .rules-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: start;
  }

  .bankroll {
    width: 100%;
    grid-template-columns: 1fr 1fr;
  }

  .history-panel {
    grid-template-columns: 1fr;
    grid-template-areas:
      "head"
      "last"
      "strip"
      "status"
      "stats";
  }

  .last-number {
    width: min(210px, 72vw);
  }

  .history-strip {
    justify-content: center;
  }

  .quick-board {
    grid-template-columns: repeat(6, minmax(40px, 1fr));
  }

  .prediction-grid {
    grid-template-columns: repeat(5, minmax(62px, 1fr));
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100vw - 16px, 1220px);
    padding-bottom: 28px;
  }

  h1 {
    font-size: 2.2rem;
    line-height: 1.02;
  }

  .panel {
    padding: 12px;
  }

  .bankroll {
    grid-template-columns: 1fr;
  }

  .panel-head {
    align-items: flex-start;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .chip {
    width: 34px;
    height: 34px;
    font-size: 0.82rem;
  }

  .bar-row {
    grid-template-columns: 74px minmax(0, 1fr) 32px;
  }

  .toggle-rule {
    grid-template-columns: 18px minmax(0, 1fr) 64px;
  }

  .prediction-meta {
    text-align: left;
  }

  .prediction-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
