:root {
  --bg: #0a0e14;
  --panel: rgba(17, 25, 40, 0.9);
  --panel-soft: rgba(255, 255, 255, 0.045);
  --text: #edf3fb;
  --muted: #a8b6c8;
  --accent: #6ee7b7;
  --accent-2: #82b5ff;
  --danger: #ff8f9c;
  --border: rgba(255, 255, 255, 0.1);
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.34);
  --radius: 8px;
  --app-shell-max: 1280px;
  --app-shell-gap: 14px;
  --page-gutter: 18px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font: 15px/1.42 var(--sans);
  background:
    linear-gradient(135deg, rgba(110, 231, 183, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(130, 181, 255, 0.14), transparent 34%),
    var(--bg);
}

.app-shell > .hero,
.app-shell > .panel {
  width: min(1180px, 100%);
}

.hero,
.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.025));
  box-shadow: var(--shadow);
}

.hero {
  padding: 18px;
}

.hero h1 {
  margin: 0 0 6px;
  font-size: clamp(32px, 5vw, 46px);
  line-height: 1;
}

.hero p,
.panel-copy,
.status {
  margin: 0;
  color: rgba(237, 243, 251, 0.74);
}

.panel {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.run-panel {
  padding-block: 10px;
}

.alarm-panel {
  padding-block: 12px;
}

.panel-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 14px;
}

.panel-head h2,
.capture-workspace h3 {
  margin: 0 0 4px;
}

.panel-head h2 {
  font-size: 22px;
}

.capture-workspace h3 {
  font-size: 15px;
}

.preview-shell {
  position: relative;
  width: 100%;
  min-height: 420px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.22);
}

#screenVideo,
#selectionCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#screenVideo {
  object-fit: contain;
  background: #05070a;
  z-index: 0;
}

#selectionCanvas {
  cursor: crosshair;
  z-index: 1;
  touch-action: none;
}

.preview-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(237, 243, 251, 0.55);
  pointer-events: none;
  z-index: 2;
}

.preview-empty[hidden] {
  display: none;
}

.control-stack {
  display: grid;
  gap: 10px;
  align-content: start;
}

.coord-grid,
.text-grid,
.compare-grid,
.outcome-grid,
.capture-workspace {
  display: grid;
  gap: 10px;
}

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

.text-grid,
.compare-grid,
.outcome-grid,
.capture-workspace {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 6px;
  color: rgba(237, 243, 251, 0.72);
  font-size: 12px;
  font-weight: 650;
}

input,
textarea,
select,
button {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.24);
  color: var(--text);
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  padding: 9px 10px;
  outline: none;
}

textarea,
.mono-text {
  font-family: var(--mono);
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(110, 231, 183, 0.72);
  box-shadow: 0 0 0 4px rgba(110, 231, 183, 0.14);
}

select option {
  background: #111928;
}

button {
  min-height: 40px;
  padding: 9px 12px;
  cursor: pointer;
  font-weight: 750;
  transition: transform 0.08s ease, border-color 0.16s ease, background 0.16s ease;
}

button:hover {
  border-color: rgba(237, 243, 251, 0.28);
  background: rgba(255, 255, 255, 0.06);
}

button:active {
  transform: translateY(1px);
}

button.primary,
button.primary.is-active {
  border-color: rgba(110, 231, 183, 0.52);
  background: linear-gradient(180deg, rgba(110, 231, 183, 0.24), rgba(110, 231, 183, 0.1));
}

button.danger-soft.is-active {
  border-color: rgba(255, 143, 156, 0.48);
  background: linear-gradient(180deg, rgba(255, 143, 156, 0.22), rgba(255, 143, 156, 0.1));
}

button.is-inactive,
button.primary.is-inactive,
button.danger-soft.is-inactive {
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.055);
  color: rgba(237, 243, 251, 0.48);
}

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

input:disabled,
textarea:disabled,
select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: rgba(255, 255, 255, 0.04);
}

.actions,
.mode-row,
.ocr-controls,
.threshold-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
}

.ocr-controls,
.threshold-row {
  justify-content: flex-end;
}

.ocr-controls {
  display: grid;
  grid-template-columns: minmax(190px, 260px);
  align-items: end;
  gap: 10px;
  width: min(260px, 100%);
  min-width: 0;
}

.ocr-control-fields {
  display: grid;
  grid-template-columns: minmax(190px, 260px);
  gap: 8px;
  align-items: end;
  min-width: 0;
}

.ocr-run-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 128px 176px;
  gap: 8px;
  align-items: end;
  justify-content: stretch;
  min-width: 0;
}

.ocr-action-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(78px, 1fr));
  gap: 8px;
}

.ocr-controls .ocr-small-field,
.ocr-controls .ocr-interval-field,
.threshold-row label {
  width: auto;
  min-width: 0;
}

.ocr-controls .tooltip-field {
  width: auto;
  min-width: 0;
}

.ocr-controls input,
.ocr-controls select {
  min-width: 0;
}

.ocr-controls .mode-row {
  flex-wrap: nowrap;
  min-width: 0;
}

.ocr-controls .radio-card {
  flex: 1 1 auto;
}

.ocr-controls .radio-card span,
.ocr-action-pair button {
  white-space: nowrap;
}

.alarm-controls {
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.alarm-button-stack,
.alarm-sound-stack {
  display: grid;
  gap: 8px;
  align-content: start;
  min-width: 0;
}

.alarm-button-row,
.alarm-toggle-row,
.volume-row {
  display: flex;
  align-items: end;
  gap: 8px;
  min-width: 0;
}

.alarm-button-row button,
.alarm-toggle-row .toggle {
  flex: 1 1 0;
}

.alarm-controls button,
.alarm-toggle-row .toggle {
  white-space: nowrap;
}

#ringtoneSelect {
  width: 100%;
  min-width: 180px;
}

.volume-field {
  width: min(180px, 30vw);
}

#soundVolume {
  --vol-pct: 100%;
  height: 10px;
  padding: 0;
  border-radius: 999px;
  cursor: pointer;
  background:
    linear-gradient(90deg, rgba(110, 231, 183, 0.95) 0%, rgba(129, 140, 248, 0.95) var(--vol-pct), rgba(255, 255, 255, 0.12) var(--vol-pct), rgba(255, 255, 255, 0.12) 100%);
}

#soundVolume::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: #f4f8ff;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.28);
  margin-top: -3px;
}

#soundVolume::-moz-range-track {
  height: 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.12);
}

#soundVolume::-moz-range-progress {
  height: 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: linear-gradient(90deg, rgba(110, 231, 183, 0.95), rgba(129, 140, 248, 0.95));
}

#soundVolume::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: #f4f8ff;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.28);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
  color: rgba(237, 243, 251, 0.82);
  font-size: 12px;
  user-select: none;
  white-space: nowrap;
}

.toggle input {
  position: relative;
  width: 40px;
  height: 22px;
  padding: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.toggle input::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
  transform: translateY(-50%);
  transition: left 0.15s ease;
}

.toggle input:checked {
  border-color: rgba(110, 231, 183, 0.58);
  background: rgba(110, 231, 183, 0.22);
}

.toggle input:checked::after {
  left: 20px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
  color: rgba(237, 243, 251, 0.82);
  font-size: 12px;
  white-space: nowrap;
}

.run-panel .mode-row {
  flex-wrap: nowrap;
  min-width: 0;
}

.run-panel .radio-card {
  flex: 1 1 0;
}

.label-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tooltip-wrap {
  position: relative;
  display: inline-flex;
}

.tooltip-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
}

.tooltip-bubble {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 5;
  width: min(280px, 78vw);
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(8, 12, 18, 0.98);
  color: rgba(237, 243, 251, 0.88);
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.tooltip-wrap:hover .tooltip-bubble,
.tooltip-trigger:focus-visible + .tooltip-bubble {
  opacity: 1;
  transform: translateY(0);
}

.radio-card {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.18);
  cursor: pointer;
}

.radio-card input {
  width: 16px;
  height: 16px;
  padding: 0;
  border-radius: 50%;
}

.radio-card input:checked {
  border-color: rgba(110, 231, 183, 0.86);
  background: radial-gradient(circle at center, var(--accent) 0 42%, transparent 46%);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #05070a;
}

.processing-canvas {
  display: none;
}

.output-text {
  min-height: 120px;
}

.status {
  min-height: 20px;
  font-size: 13px;
}

.status.is-ok {
  color: var(--accent);
}

.status.is-warn {
  color: #ffd18a;
}

.status.is-error {
  color: var(--danger);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
  white-space: nowrap;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(10, 14, 20, 0.98);
}

.accepted {
  color: var(--accent);
  font-weight: 800;
}

.rejected {
  color: var(--danger);
  font-weight: 800;
}

@media (max-width: 1180px) {
  .panel-head {
    grid-template-columns: 1fr;
  }

  .ocr-controls,
  .alarm-controls,
  .threshold-row {
    justify-content: start;
  }

  .ocr-controls {
    width: 100%;
  }
}

@media (max-width: 900px) {
  .panel-head,
  .text-grid,
  .compare-grid,
  .outcome-grid,
  .capture-workspace {
    grid-template-columns: 1fr;
  }

  .ocr-controls {
    grid-template-columns: 1fr;
  }

  .ocr-run-row {
    grid-template-columns: 1fr;
    justify-content: stretch;
  }

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

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

  .alarm-button-row,
  .alarm-toggle-row,
  .volume-row {
    align-items: stretch;
  }

  .volume-field,
  #ringtoneSelect {
    width: 100%;
    max-width: none;
    min-width: 0;
  }
}

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

  .ocr-control-fields {
    grid-template-columns: 1fr;
  }

  .preview-shell {
    min-height: 260px;
  }

  .alarm-controls {
    grid-template-columns: 1fr;
  }

  .alarm-button-row,
  .alarm-toggle-row,
  .volume-row {
    flex-wrap: wrap;
  }

  .alarm-button-row button,
  .alarm-toggle-row .toggle,
  .volume-row .volume-field {
    flex: 1 1 100%;
  }
}
