/* ===== Reset / Сброс отступов ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, 'Helvetica Neue', Arial, sans-serif;
  background-color: #f5f5f5;
  color: #222;
  line-height: 1.5;
  min-height: 100vh;
}

ul {
  list-style: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* ===== Layout container ===== */
.container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ===== Header ===== */
.header {
  text-align: center;
  padding: 40px 20px 20px;
}

.header__title {
  font-size: 2.4rem;
  font-weight: 700;
  color: #c0392b;
  letter-spacing: 0.02em;
  margin-bottom: 16px;
}

.header__subtitle {
  font-size: 0.95rem;
  color: #666;
  font-style: italic;
  max-width: 720px;
  margin: 0 auto;
  line-height: 1.6;
  border-left: 3px solid #c0392b;
  padding-left: 16px;
}

/* ===== Main layout ===== */
.main {
  display: flex;
  flex-direction: row;
  gap: 24px;
  flex: 1;
  padding: 20px 0;
}

/* ===== Canvas section ===== */
.canvas-section {
  flex: 1;
  display: flex;
  align-items: stretch;
  min-width: 0;
}

.canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 70vw;
  min-height: 60vh;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  object-fit: contain;
}

/* ===== Legend section ===== */
.legend-section {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.legend__title {
  font-size: 1.2rem;
  font-weight: 600;
  color: #333;
  padding-bottom: 8px;
  border-bottom: 2px solid #e0e0e0;
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.legend__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid #e8e8e8;
  border-radius: 6px;
  transition: all 0.25s ease;
  cursor: pointer;
  position: relative;
}

.legend__item:hover {
  border-color: #999;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transform: translateX(4px);
}

.legend__item--highlighted {
  border-color: #c0392b;
  box-shadow: 0 0 0 2px rgba(192, 57, 43, 0.25);
}

.legend__item--contradiction {
  border-color: #e74c3c;
  animation: contradictionPulse 1.2s ease-in-out infinite;
}

.legend__indicator {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.legend__indicator--red {
  background-color: #e74c3c;
}

.legend__indicator--green {
  background-color: #27ae60;
}

.legend__indicator--transparent {
  background-color: transparent;
  border: 1px dashed #aaa;
}

.legend__indicator--kitten {
  background-color: #e74c3c;
  position: relative;
}

.legend__indicator--kitten::after {
  content: '🐱';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px;
  line-height: 1;
}

.legend__label {
  font-weight: 600;
  font-size: 0.9rem;
  color: #333;
}

.legend__desc {
  font-size: 0.8rem;
  color: #888;
  margin-left: auto;
  white-space: nowrap;
}

/* ===== Button ===== */
.btn-contradictions {
  display: inline-block;
  width: 100%;
  padding: 14px 20px;
  background: linear-gradient(135deg, #c0392b, #e74c3c);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 8px;
  transition: all 0.3s ease;
  text-align: center;
  letter-spacing: 0.02em;
  box-shadow: 0 4px 14px rgba(192, 57, 43, 0.3);
}

.btn-contradictions:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(192, 57, 43, 0.4);
}

.btn-contradictions:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(192, 57, 43, 0.3);
}

/* ===== Tooltip ===== */
.tooltip {
  position: fixed;
  display: none;
  max-width: 280px;
  padding: 12px 16px;
  background: #222;
  color: #fff;
  font-size: 0.85rem;
  line-height: 1.5;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.tooltip--visible {
  display: block;
  opacity: 1;
}

.tooltip__title {
  font-weight: 600;
  margin-bottom: 6px;
  color: #f1c40f;
}

.tooltip__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 2px;
}

.tooltip__key {
  color: #bbb;
}

.tooltip__value {
  color: #fff;
  font-weight: 500;
}

/* ===== Protocol section ===== */
.protocol {
  margin: 20px 0;
  padding: 24px 28px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.protocol__title {
  font-size: 1.3rem;
  font-weight: 600;
  color: #333;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid #e0e0e0;
}

.protocol__dialog p {
  margin-bottom: 10px;
  font-size: 0.95rem;
  color: #444;
  line-height: 1.6;
}

.protocol__dialog p:last-child {
  margin-bottom: 0;
}

.protocol__dialog strong {
  color: #c0392b;
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 20px;
  border-top: 1px solid #e0e0e0;
  margin-top: auto;
}

.footer__text {
  font-size: 0.85rem;
  color: #999;
}

/* ===== CSS Animations ===== */

/* Pulse animation for contradiction highlighting */
@keyframes contradictionPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.5);
    border-color: #e74c3c;
  }
  50% {
    box-shadow: 0 0 0 6px rgba(231, 76, 60, 0.15);
    border-color: #c0392b;
  }
  100% {
    box-shadow: 0 0 0 0 rgba(231, 76, 60, 0);
    border-color: #e74c3c;
  }
}

/* Glow animation for canvas lines contradiction */
@keyframes contradictionGlow {
  0% {
    filter: drop-shadow(0 0 0 transparent);
  }
  50% {
    filter: drop-shadow(0 0 8px rgba(231, 76, 60, 0.6));
  }
  100% {
    filter: drop-shadow(0 0 0 transparent);
  }
}

.canvas--contradiction {
  animation: contradictionGlow 1.2s ease-in-out infinite;
}

/* Shake animation */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

.btn-contradictions--active {
  animation: shake 0.5s ease-in-out;
}

/* Fade-in animation for contradiction cards */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.contradiction-card {
  position: absolute;
  background: #fff;
  border: 2px solid #e74c3c;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.8rem;
  color: #c0392b;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(231, 76, 60, 0.2);
  animation: fadeInUp 0.4s ease forwards;
  pointer-events: none;
  z-index: 100;
  white-space: nowrap;
  max-width: 300px;
}

.contradiction-card:nth-child(2) {
  animation-delay: 0.15s;
}

.contradiction-card:nth-child(3) {
  animation-delay: 0.3s;
}

/* ===== Media Queries ===== */

/* Large screens (up to 1920px) */
@media (min-width: 1401px) {
  .container {
    padding: 0 40px;
  }

  .header__title {
    font-size: 2.8rem;
  }

  .legend-section {
    width: 300px;
  }
}

/* Medium screens (tablets, small laptops) */
@media (max-width: 1024px) {
  .main {
    flex-direction: column;
  }

  .canvas-section {
    min-height: 60vh;
  }

  .canvas {
    min-width: 100%;
    min-height: 55vh;
  }

  .contradiction-card {
    font-size: 0.72rem;
    padding: 6px 10px;
    max-width: 220px;
    white-space: normal;
  }

  .legend-section {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .legend__title {
    width: 100%;
  }

  .legend {
    flex-direction: row;
    flex-wrap: wrap;
    flex: 1;
  }

  .legend__item {
    flex: 1 1 calc(33.333% - 8px);
    min-width: 180px;
  }

  .btn-contradictions {
    width: auto;
    align-self: flex-start;
    padding: 12px 24px;
  }
}

/* Small tablets / large phones */
@media (max-width: 768px) {
  .header {
    padding: 24px 12px 16px;
  }

  .header__title {
    font-size: 1.8rem;
  }

  .header__subtitle {
    font-size: 0.85rem;
    padding-left: 12px;
  }

  .main {
    padding: 12px 0;
    gap: 16px;
  }

  .canvas {
    min-width: 100%;
    min-height: 50vh;
  }

  .legend__item {
    flex: 1 1 calc(50% - 8px);
    min-width: 140px;
    padding: 8px 10px;
  }

  .legend__desc {
    font-size: 0.75rem;
  }

  .protocol {
    padding: 16px 18px;
  }

  .protocol__title {
    font-size: 1.1rem;
  }

  .protocol__dialog p {
    font-size: 0.88rem;
  }
}

/* Small phones */
@media (max-width: 480px) {
  .container {
    padding: 0 12px;
  }

  .header__title {
    font-size: 1.5rem;
  }

  .header__subtitle {
    font-size: 0.8rem;
    padding-left: 10px;
  }

  .canvas {
    min-width: 100%;
    min-height: 45vh;
  }

  .contradiction-card {
    font-size: 0.65rem;
    padding: 5px 8px;
    max-width: 160px;
    white-space: normal;
  }

  .legend {
    flex-direction: column;
  }

  .legend__item {
    flex: 1 1 100%;
    min-width: auto;
  }

  .legend-section {
    flex-direction: column;
  }

  .btn-contradictions {
    width: 100%;
  }

  .protocol {
    padding: 12px 14px;
  }

  .protocol__title {
    font-size: 1rem;
  }
}

/* Minimum supported width */
@media (max-width: 360px) {
  .header__title {
    font-size: 1.3rem;
  }

  .header__subtitle {
    font-size: 0.75rem;
  }

  .canvas {
    min-height: 40vh;
  }

  .contradiction-card {
    font-size: 0.6rem;
    padding: 4px 6px;
    max-width: 130px;
    white-space: normal;
  }

  .legend__item {
    padding: 6px 8px;
    gap: 6px;
  }

  .legend__label {
    font-size: 0.8rem;
  }

  .legend__desc {
    font-size: 0.7rem;
  }
}
