:root {
  --font-sans: Arial, Helvetica, sans-serif;
  --font-mono: "Courier New", Courier, monospace;
  --ink: #17201c;
  --muted: #6f7b75;
  --paper: #f4f2ec;
  --panel: #fbfaf6;
  --line: #d9ddd6;
  --green: #215aa8;
  --green-deep: #16427c;
  --lime: #c8f35b;
  --cyan: #8fe7da;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans), Arial, sans-serif;
}

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

.app-shell {
  min-height: 100vh;
  padding: 20px 0 40px;
  background:
    radial-gradient(circle at 92% 4%, rgba(200, 243, 91, .2), transparent 22rem),
    var(--paper);
}

.kicker {
  margin: 0;
  color: var(--green);
  font: 700 10px/1.2 var(--font-mono), monospace;
  text-transform: uppercase;
  letter-spacing: .14em;
}

.workspace {
  width: min(1500px, calc(100% - clamp(28px, 5vw, 80px)));
  margin: 0 auto;
  display: grid;
  grid-template-columns: 270px minmax(470px, 1fr) 300px;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 22px 70px rgba(22, 38, 29, .09);
}

.panel {
  min-width: 0;
  background: var(--panel);
}

.controls, .result-panel { padding: 24px; }
.controls { border-right: 1px solid var(--line); }
.result-panel { border-left: 1px solid var(--line); }

.panel-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.step {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  font: 11px/1 var(--font-mono), monospace;
}

.panel-heading h2, .pitch-toolbar h2 {
  margin: 5px 0 0;
  font-size: 16px;
  line-height: 1.2;
  letter-spacing: -.025em;
}

.metric-list {
  display: grid;
  gap: 6px;
  margin-top: 18px;
}

.metric-button {
  width: 100%;
  min-height: 62px;
  display: grid;
  grid-template-columns: 42px 1fr 18px;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease, transform .18s ease;
}

.metric-button:hover { background: #f0f1eb; transform: translateX(2px); }
.metric-button:focus-visible,
.quiet-button:focus-visible,
.accent-button:focus-visible,
select:focus-visible,
input:focus-visible,
canvas:focus-visible {
  outline: 3px solid rgba(33,90,168,.22);
  outline-offset: 2px;
}

.metric-button.is-active {
  border-color: #becbbf;
  background: var(--ink);
  color: white;
  box-shadow: 0 8px 18px rgba(23,32,28,.16);
}

.metric-code {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e4e8e1;
  color: var(--green-deep);
  font: 700 12px/1 var(--font-mono), monospace;
}

.metric-button.is-active .metric-code { background: var(--lime); color: var(--ink); }
.metric-button > span:nth-child(2) { display: grid; gap: 4px; min-width: 0; }
.metric-button strong { font-size: 12px; line-height: 1.1; }
.metric-button small { color: #87918c; font-size: 9px; line-height: 1.25; white-space: nowrap; }
.metric-button.is-active small { color: #aebbb4; }
.metric-button i { color: #93a099; font-style: normal; opacity: 0; transition: opacity .18s ease; }
.metric-button.is-active i { color: var(--lime); opacity: 1; }

.context-controls {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 14px;
}

.context-controls label { display: grid; gap: 7px; color: var(--muted); font: 10px/1 var(--font-mono), monospace; text-transform: uppercase; letter-spacing: .07em; }
.context-controls select {
  width: 100%;
  min-height: 40px;
  padding: 0 34px 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
}

.pitch-panel { display: flex; min-height: 675px; flex-direction: column; background: #f0efe9; }

.pitch-toolbar {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.toolbar-actions { display: flex; gap: 7px; }
.quiet-button, .accent-button {
  min-height: 34px;
  padding: 0 11px;
  border-radius: 8px;
  font-size: 10px;
  cursor: pointer;
}
.quiet-button {
  border: 1px solid #d5d9d2;
  background: rgba(255,255,255,.55);
  color: #66726c;
}
.quiet-button:hover { border-color: #adb7b0; color: var(--ink); }
.accent-button {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--lime);
}
.accent-button:hover { background: #243029; }
.accent-button:disabled, .quiet-button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.pitch-wrap {
  position: relative;
  flex: 1;
  min-height: 470px;
  margin: 18px;
  border-radius: 12px;
  overflow: hidden;
  background: #205f9e;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.15), 0 10px 30px rgba(22,66,124,.18);
}

#pitchCanvas { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
#pitchCanvas.is-dragging { cursor: grabbing; }

.canvas-hint {
  position: absolute;
  left: 50%;
  bottom: 13px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 24px);
  padding: 7px 12px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 999px;
  background: rgba(11,61,43,.82);
  color: rgba(255,255,255,.8);
  backdrop-filter: blur(8px);
  font: 9px/1 var(--font-mono), monospace;
  white-space: nowrap;
  pointer-events: none;
}

.mouse-icon { width: 9px; height: 13px; border: 1px solid rgba(255,255,255,.75); border-radius: 6px; position: relative; }
.mouse-icon::after { content: ""; position: absolute; top: 2px; left: 3px; width: 1px; height: 3px; background: var(--lime); }

.legend {
  display: flex;
  justify-content: center;
  gap: 24px;
  min-height: 48px;
  padding: 0 18px 18px;
  color: #718079;
  font: 9px/1 var(--font-mono), monospace;
}
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i { display: inline-block; flex: 0 0 auto; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 0 3px rgba(33,90,168,.12); }
.line-sample { width: 18px; height: 0; border-top: 1px dashed var(--green); }
.area-sample { width: 14px; height: 9px; border: 1px solid #7fb3a1; background: rgba(143,231,218,.2); }

.score-card {
  margin-top: 20px;
  padding: 18px;
  border-radius: 12px;
  background: var(--ink);
  color: white;
}
.score-topline { display: flex; justify-content: space-between; align-items: center; color: #a9b8b0; font: 10px/1 var(--font-mono), monospace; }
.quality-badge { padding: 6px 8px; border-radius: 999px; background: rgba(200,243,91,.12); color: var(--lime); font-size: 8px; text-transform: uppercase; letter-spacing: .06em; }
.score-value { display: flex; align-items: baseline; gap: 8px; margin: 19px 0 14px; }
.score-value strong { color: var(--lime); font: 700 clamp(42px, 4vw, 58px)/.9 var(--font-mono), monospace; letter-spacing: -.07em; }
.score-value span { color: #93a29a; font: 11px/1 var(--font-mono), monospace; }
.probability-track { height: 4px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.12); }
.probability-track span { display: block; width: 31%; height: 100%; border-radius: inherit; background: var(--lime); transition: width .25s ease; }
.score-card p { min-height: 38px; margin: 12px 0 0; color: #aab7b0; font-size: 10px; line-height: 1.55; }

.stat-grid { margin: 18px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat-grid > div { min-height: 71px; display: flex; flex-direction: column; justify-content: space-between; padding: 11px; border: 1px solid var(--line); border-radius: 9px; background: #f7f7f2; }
.stat-grid dt { color: #87918c; font: 8px/1.2 var(--font-mono), monospace; text-transform: uppercase; letter-spacing: .06em; }
.stat-grid dd { margin: 0; font: 700 15px/1 var(--font-mono), monospace; }

.model-note {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.model-note > span { flex: 0 0 auto; width: 20px; height: 20px; display: grid; place-items: center; border-radius: 50%; background: #e7ebe4; color: var(--green); font: 700 10px/1 var(--font-mono), monospace; }
.model-note p { display: grid; gap: 5px; margin: 0; }
.model-note strong { font-size: 10px; }
.model-note small { color: #7b8781; font-size: 9px; line-height: 1.5; }

/* ---- Команди ---- */

.teams-panel {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding: 22px 24px 24px;
  background: #f7f6f1;
}

.teams-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.teams-header .panel-heading {
  padding-bottom: 0;
  border-bottom: 0;
}

.team-add {
  display: flex;
  gap: 8px;
  min-width: min(360px, 100%);
}

.team-add input {
  flex: 1;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
}

.teams-body {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  gap: 20px;
}

.teams-list-wrap {
  display: grid;
  gap: 10px;
  align-content: start;
}

.teams-list {
  display: grid;
  gap: 4px;
  max-height: 220px;
  overflow: auto;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.team-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 4px 0 10px;
  border-radius: 8px;
}

.team-row:hover { background: #f0f1eb; }

.team-row-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  min-height: 38px;
  cursor: pointer;
  font-size: 12px;
}

.team-row-all {
  border: 1px solid var(--line);
  background: #fff;
  font: 700 11px/1 var(--font-mono), monospace;
  text-transform: uppercase;
  letter-spacing: .04em;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 0 10px;
  border-radius: 8px;
  cursor: pointer;
}

.team-row input { width: 14px; height: 14px; accent-color: var(--green); }
.team-row .team-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-row .team-count {
  color: var(--muted);
  font: 10px/1 var(--font-mono), monospace;
}

.item-delete {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #8a9490;
  font: 700 16px/1 var(--font-mono), monospace;
  cursor: pointer;
}

.item-delete:hover {
  border-color: #d5d9d2;
  color: #b42318;
  background: #fff;
}

.team-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.team-hint {
  margin: 0;
  min-height: 16px;
  color: var(--muted);
  font: 10px/1.4 var(--font-mono), monospace;
}

.episodes-wrap {
  min-width: 0;
  display: grid;
  gap: 12px;
  align-content: start;
}

.episodes-topline {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.episodes-topline span {
  color: var(--muted);
  font: 10px/1 var(--font-mono), monospace;
}

.team-stats { margin: 0; }

.episodes-list {
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
}

.episode-row {
  display: grid;
  grid-template-columns: 56px 1fr auto auto;
  gap: 12px;
  align-items: center;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  font-size: 11px;
}

.episode-row .episode-code {
  width: 42px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #e4e8e1;
  color: var(--green-deep);
  font: 700 11px/1 var(--font-mono), monospace;
}

.episode-row .episode-meta {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.episode-row .episode-meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.episode-row .episode-meta small {
  color: var(--muted);
  font: 9px/1.3 var(--font-mono), monospace;
}

.episode-row .episode-value {
  font: 700 13px/1 var(--font-mono), monospace;
  white-space: nowrap;
}

.episodes-empty {
  margin: 0;
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  font: 11px/1.5 var(--font-mono), monospace;
  text-align: center;
}

@media (max-width: 1120px) {
  .workspace { grid-template-columns: 230px minmax(430px, 1fr); }
  .result-panel {
    grid-column: 1 / -1;
    border-top: 1px solid var(--line);
    border-left: 0;
    display: grid;
    grid-template-columns: 220px minmax(260px, 1fr) minmax(260px, .8fr);
    gap: 18px;
  }
  .result-panel .panel-heading { align-self: start; }
  .result-panel .score-card, .result-panel .stat-grid { margin-top: 0; }
  .result-panel .model-note { grid-column: 3; grid-row: 1; margin: 0; padding: 0; border: 0; }
  .pitch-panel { min-height: 620px; }
  .teams-body { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .workspace { width: calc(100% - 24px); grid-template-columns: 1fr; overflow: visible; border-radius: 14px; }
  .controls { border-right: 0; border-bottom: 1px solid var(--line); }
  .metric-list { grid-template-columns: 1fr 1fr; }
  .metric-button { min-height: 58px; grid-template-columns: 38px 1fr; }
  .metric-button i, .metric-button small { display: none; }
  .pitch-panel { min-height: auto; }
  .pitch-wrap { min-height: 390px; margin: 10px; }
  .pitch-toolbar { align-items: flex-start; padding: 16px; }
  .legend { flex-wrap: wrap; gap: 12px; }
  .result-panel { grid-column: auto; grid-template-columns: 1fr; border-left: 0; }
  .result-panel .model-note { grid-column: auto; grid-row: auto; padding-top: 18px; border-top: 1px solid var(--line); }
  .teams-header { flex-direction: column; align-items: stretch; }
  .team-add { min-width: 0; }
  .episode-row { grid-template-columns: 42px 1fr auto auto; }
}

@media (max-width: 480px) {
  .metric-list { grid-template-columns: 1fr; }
  .metric-button small { display: block; }
  .pitch-toolbar { display: grid; }
  .pitch-wrap { min-height: 330px; }
  .canvas-hint { font-size: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
