@charset "windows-1251";

:root {
  --ink: #3a2413;
  --ink-heading: #4a1b0a;
  --link: #660000;
  --rule: rgba(102, 0, 0, 0.28);
  --panel: rgba(255, 255, 255, 0.18);
  --panel-card: rgba(255, 255, 255, 0.10);
  --panel-border: rgba(102, 0, 0, 0.26);
  --panel-border-strong: rgba(102, 0, 0, 0.48);
  --green: #2e7d32;
  --green-dark: #1b5e20;
  --red: #b71c1c;
  --red-dark: #7f0000;
  --mono: "Courier New", Courier, "Liberation Mono", monospace;
  --cell-size: 17px;
  --table-font-size: 10pt;
  --table-head-height: 24px;
}

.page-wrap,
.page-wrap *,
.page-wrap *::before,
.page-wrap *::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  background-color: #641b07;
  background-image: url("../texture2016/wood-fill.jpg");
  background-repeat: repeat;
  font-family: Georgia, "Times New Roman", Times, serif;
  color: var(--ink);
  overflow-x: hidden;
}

/* Центрирование рабочего поля по обеим осям экрана */
.page-wrap {
  flex: 1 0 auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 68px);
  padding: 28px 16px;
}

#shadow-left,
#shadow-right {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 221px;
  height: 100%;
  background-image: url("../texture2016/shadow.png");
  background-repeat: repeat-y;
  mix-blend-mode: multiply;
  pointer-events: none;
  z-index: 1;
}

#shadow-left {
  left: 0;
}

#shadow-right {
  right: 0;
  transform: scaleX(-1);
}

.vigenere-window {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 940px;
  margin: auto;
  padding: 12px;
  font-size: 15px;
  line-height: 1.48;
  color: var(--ink);
  background-color: #D7BA8F;
  background-image: url("../texture/ContFill.jpg");
  border-radius: 4px;
  box-shadow:
    2px 4px 16px rgba(0, 0, 0, 0.65),
    -1px 2px 5px rgba(0, 0, 0, 0.45),
    inset 0 0 0 1px rgba(102, 0, 0, 0.30),
    inset 5px 3px 13px rgba(255, 255, 255, 0.28),
    inset -5px -3px 13px rgba(120, 72, 28, 0.20);
}

.quiz-card {
  position: relative;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  background: var(--panel-card);
  overflow: hidden;
}

.quiz-card-header {
  margin: 0;
  padding: 7px 16px;
  background-color: #D2A86B;
  background-image: url("../texture/ContFillHD.gif");
  border-bottom: 1px solid var(--panel-border);
  font-size: 11pt;
  font-weight: bold;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  text-align: center;
  color: #3a1400;
}

.start-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 16px;
}

.header-logo-link {
  display: inline-flex;
  line-height: 0;
  text-decoration: none;
  transition: opacity 0.15s ease;
}

.header-logo-link:hover {
  opacity: 0.85;
}

.header-logo {
  display: block;
  width: 90px;
  height: 26px;
}

.quiz-card-body {
  padding: 22px 26px 26px;
}

.quiz-title {
  margin: 2px 0 0;
  font-size: 19pt;
  line-height: 1.3;
  font-weight: bold;
  color: var(--ink-heading);
  text-align: center;
  text-shadow: rgba(255, 255, 255, 0.35) 0 1px 0;
}

.page-subtitle {
  margin: 5px 0 0;
  text-align: center;
  font-size: 12pt;
  color: #5a280c;
}

.rule-line {
  height: 1px;
  border: 0;
  border-bottom: 1px dotted var(--rule);
  margin: 19px 0;
}

/* Переключатель режима */
.mode-selector {
  display: flex;
  flex-direction: row;
  gap: 10px;
  max-width: 560px;
  margin: 0 auto;
}

.mode-option {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  min-height: 46px;
  padding: 8px 14px;
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  background: var(--panel);
  cursor: pointer;
  text-align: center;
  transition: background-color 0.14s ease, border-color 0.14s ease;
}

.mode-option:hover {
  background-color: rgba(210, 168, 107, 0.45);
  border-color: var(--panel-border-strong);
}

.mode-option:has(input:checked) {
  background-color: #D2A86B;
  background-image: url("../texture/ContFillHD.gif");
  border-color: var(--panel-border-strong);
  color: #261004;
}

.mode-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-radio-mark {
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #663318;
  background: rgba(255, 255, 255, 0.55);
  position: relative;
}

.mode-option input[type="radio"]:checked + .mode-radio-mark::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--link);
}

.mode-text {
  font-size: 11pt;
  line-height: 1.35;
  font-weight: bold;
}

/* Поля ввода */
.fields-grid {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-top: 20px;
}

.field-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-block label,
.label-row label {
  font-size: 11.5pt;
  font-weight: bold;
  color: var(--ink-heading);
}

.label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.mono-input,
.text-input {
  font-family: var(--mono);
  letter-spacing: 0.04em;
}

.text-input {
  width: 100%;
  padding: 9px 12px;
  color: var(--ink-heading);
  background: rgba(255, 252, 244, 0.82);
  border: 1px solid rgba(102, 0, 0, 0.42);
  border-radius: 3px;
  outline: none;
  font-size: 13pt;
  line-height: 1.5;
  text-transform: none;
  box-shadow: inset 0 1px 3px rgba(58, 36, 19, 0.10);
  transition: border-color 0.14s ease, box-shadow 0.14s ease, background-color 0.14s ease;
}

#key-input {
  text-transform: uppercase;
}

.text-input:focus {
  border-color: var(--link);
  box-shadow: 0 0 0 2px rgba(102, 0, 0, 0.16);
  background: #fffdf8;
}

.text-input.is-invalid {
  border-color: var(--red);
  background: rgba(255, 244, 240, 0.92);
  box-shadow: 0 0 0 2px rgba(183, 28, 28, 0.15);
}

.text-area {
  min-height: 80px;
  resize: vertical;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.result-area {
  min-height: 80px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: rgba(210, 168, 107, 0.30);
  cursor: text;
  user-select: all;
}

.field-hint {
  margin: 0;
  font-size: 9.5pt;
  line-height: 1.45;
  color: #5a361b;
}

.char-counter {
  font-family: var(--mono);
  font-size: 9.5pt;
  color: #5a361b;
  white-space: nowrap;
}

.error-msg {
  margin: 0;
  padding: 6px 12px;
  font-size: 10pt;
  color: var(--red-dark);
  background: rgba(183, 28, 28, 0.10);
  border: 1px solid rgba(183, 28, 28, 0.35);
  border-radius: 3px;
}

/* Кнопки */
.actions-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
  margin-top: 18px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: 10.5pt;
  font-weight: bold;
  line-height: 1.25;
  color: var(--link);
  padding: 8px 16px;
  border: 1px solid var(--panel-border-strong);
  border-radius: 3px;
  background-color: rgba(255, 255, 255, 0.24);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.42),
    0 1px 2px rgba(58, 36, 19, 0.14);
  cursor: pointer;
  transition: background-color 0.14s ease, color 0.14s ease, border-color 0.14s ease, transform 0.06s ease;
}

.btn:hover:not(:disabled) {
  background-color: #D2A86B;
  background-image: url("../texture/ContFillHD.gif");
  border-color: #660000;
  color: #000000;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.48;
  cursor: default;
}

.btn-primary {
  color: #3a1400;
  background-color: rgba(210, 168, 107, 0.42);
  border-color: rgba(102, 0, 0, 0.52);
}

.btn-small {
  min-width: 36px;
  padding: 5px 11px;
  font-size: 11pt;
}

/* Заголовки разделов */
.section-title {
  margin: 0 0 9px;
  font-size: 14pt;
  line-height: 1.35;
  color: var(--ink-heading);
  text-align: center;
}

.section-lead {
  margin: 0 auto 14px;
  max-width: 670px;
  font-size: 10.5pt;
  line-height: 1.55;
  text-align: center;
  color: var(--ink);
}

.red-text {
  color: var(--red-dark);
  font-weight: bold;
}

.green-text {
  color: var(--green-dark);
  font-weight: bold;
}

/* Пошаговая демонстрация */
.demo-section {
  margin-top: 4px;
}

.step-card {
  border: 1px solid var(--panel-border-strong);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
}

.step-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 9px 12px;
  background-color: rgba(210, 168, 107, 0.55);
  background-image: url("../texture/ContFillHD.gif");
  border-bottom: 1px solid var(--panel-border);
}

.step-counter {
  min-width: 108px;
  font-size: 10.5pt;
  font-weight: bold;
  color: #3a1400;
  text-align: center;
}

.show-cell-btn {
  margin-left: 4px;
}

.step-explanation {
  margin: 0;
  padding: 12px 15px;
  min-height: 48px;
  font-size: 10.5pt;
  line-height: 1.55;
  text-align: center;
  color: var(--ink-heading);
  border-bottom: 1px dotted var(--rule);
}

.stream-scroll {
  overflow-x: auto;
  padding: 13px 12px 11px;
  outline: none;
  scrollbar-color: rgba(102, 0, 0, 0.45) rgba(255, 255, 255, 0.18);
}

.stream-scroll:focus-visible,
.table-scroll:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(102, 0, 0, 0.30);
}

.stream-table {
  border-collapse: collapse;
  margin: 0 auto;
  font-family: var(--mono);
  font-size: 14pt;
  line-height: 1;
  table-layout: fixed;
}

.stream-table td {
  width: 25px;
  min-width: 25px;
  max-width: 25px;
  height: 29px;
  padding: 0;
  text-align: center;
  vertical-align: middle;
  white-space: pre;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.stream-label {
  width: 116px !important;
  min-width: 116px !important;
  max-width: 116px !important;
  padding: 0 12px 0 6px !important;
  font-family: Georgia, "Times New Roman", Times, serif !important;
  font-size: 9.5pt !important;
  text-align: right !important;
  color: #5a280c;
  cursor: default !important;
  border: none !important;
  white-space: nowrap !important;
}

.stream-key td {
  color: var(--red-dark);
  font-weight: bold;
}

.stream-cipher td:not(.stream-label) {
  color: var(--ink);
}

.stream-plain td:not(.stream-label) {
  color: var(--green-dark);
  font-weight: bold;
}

.stream-table td.is-active-col {
  background: rgba(183, 28, 28, 0.14);
  border-color: rgba(102, 0, 0, 0.30);
}

.stream-table .space-mark {
  display: inline-block;
  color: inherit;
  opacity: 0.72;
  font-size: 1.12em;
  line-height: 1;
  transform: scaleX(1.7);
  transform-origin: center center;
}

.micro-hint {
  margin: 0;
  padding: 9px 13px 11px;
  font-size: 9pt;
  line-height: 1.45;
  color: #5a361b;
  text-align: center;
  background: rgba(255, 255, 255, 0.10);
  border-top: 1px dotted var(--rule);
}

/* Таблица Виженера */
.table-section {
  margin-top: 4px;
}

.table-heading-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 9px;
}

.table-heading-row .section-title {
  margin: 0;
}

.alphabet-badge {
  display: inline-block;
  padding: 2px 9px;
  font-family: var(--mono);
  font-size: 9.5pt;
  font-weight: bold;
  color: var(--ink-heading);
  background: rgba(255, 255, 255, 0.30);
  border: 1px solid rgba(102, 0, 0, 0.25);
  border-radius: 3px;
  white-space: nowrap;
}

.table-scroll {
  overflow: visible;
  max-width: 100%;
  border: 1px solid var(--panel-border-strong);
  border-radius: 4px;
  background: rgba(255, 252, 244, 0.72);
  box-shadow: inset 0 1px 5px rgba(58, 36, 19, 0.18);
  outline: none;
}

.vigenere-table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
  font-family: var(--mono);
  font-size: var(--table-font-size);
  line-height: 1;
  table-layout: fixed;
  margin: 0 auto;
}

.vigenere-table th,
.vigenere-table td {
  width: var(--cell-size);
  min-width: var(--cell-size);
  max-width: var(--cell-size);
  height: var(--cell-size);
  padding: 0;
  text-align: center;
  vertical-align: middle;
  border-right: 1px solid rgba(102, 0, 0, 0.15);
  border-bottom: 1px solid rgba(102, 0, 0, 0.15);
  white-space: pre;
  user-select: none;
}

.vigenere-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  height: var(--table-head-height);
  color: var(--green-dark);
  font-weight: bold;
  background-color: #D2A86B;
  background-image: url("../texture/ContFillHD.gif");
  border-bottom: 1px solid var(--panel-border-strong);
  cursor: default;
}

.vigenere-table th.corner-cell {
  left: 0;
  z-index: 6;
  color: #3a1400;
  font-size: 9pt;
  background: #C99A5F;
}

.vigenere-table tbody th {
  position: sticky;
  left: 0;
  z-index: 2;
  color: var(--red-dark);
  font-weight: bold;
  background-color: #D2A86B;
  background-image: url("../texture/ContFillHD.gif");
  border-right: 1px solid var(--panel-border-strong);
  cursor: default;
}

.vigenere-table tbody td {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.20);
  cursor: pointer;
  transition: background-color 0.1s ease, color 0.1s ease;
}

.vigenere-table tbody tr:nth-child(even) td {
  background: rgba(210, 168, 107, 0.13);
}

.vigenere-table td.space-cell,
.vigenere-table th.space-head {
  position: relative;
}

.vigenere-table td.space-cell {
  color: transparent;
}

.vigenere-table td.space-cell::after {
  content: "·";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(58, 36, 19, 0.34);
}

.vigenere-table th.space-head {
  color: transparent;
}

.vigenere-table th.space-head::after {
  content: "\2423";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--green-dark);
  opacity: 0.72;
  font-size: 1.22em;
  transform: scaleX(1.55);
  transform-origin: center center;
}

.vigenere-table tbody th.space-row-head {
  color: transparent;
}

.vigenere-table tbody th.space-row-head::after {
  content: "\2423";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--red-dark);
  opacity: 0.72;
}

/* Подсветка шагов */
.vigenere-table tr.is-active-row td,
.vigenere-table td.is-in-active-row {
  background: rgba(183, 28, 28, 0.10);
}

.vigenere-table td.is-in-active-col {
  background: rgba(46, 125, 50, 0.11);
}

.vigenere-table td.is-in-active-row.is-in-active-col,
.vigenere-table td.is-active-row-cell {
  background: rgba(210, 168, 107, 0.58);
}

.vigenere-table td.is-target-cell {
  background: #D2A86B !important;
  color: #1f0a00;
  font-weight: bold;
  outline: 2px solid var(--red-dark);
  outline-offset: -2px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
  animation: cell-pulse 1.25s ease-in-out infinite;
}

.vigenere-table tbody th.is-active-row-head {
  color: #ffffff;
  background-color: var(--red-dark);
  background-image: none;
}

.vigenere-table thead th.is-active-col-head {
  color: #ffffff;
  background-color: var(--green-dark);
  background-image: none;
}

@keyframes cell-pulse {
  0%, 100% {
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
  }
  50% {
    box-shadow: inset 0 0 0 3px rgba(102, 0, 0, 0.35);
  }
}

.table-hint {
  border: none;
  border-top: 1px dotted var(--rule);
  background: transparent;
  padding: 10px 8px 0;
}

.cell-info {
  margin: 9px 0 0;
  min-height: 22px;
  font-size: 10pt;
  text-align: center;
  color: var(--ink-heading);
}

/* Нижний блок с правилами */
.how-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.how-card {
  padding: 13px 15px;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.16);
}

.how-card h3 {
  margin: 0 0 6px;
  font-size: 11.5pt;
  color: var(--link);
}

.how-card p {
  margin: 0;
  font-size: 10pt;
  line-height: 1.55;
}

@media (max-width: 960px) {
  :root {
    --cell-size: 14px;
    --table-font-size: 9pt;
    --table-head-height: 21px;
  }

  #shadow-left,
  #shadow-right {
    width: 90px;
    background-size: 90px 221px;
  }
}

@media (max-width: 800px) {
  :root {
    --cell-size: 13px;
    --table-font-size: 8.5pt;
    --table-head-height: 20px;
  }
}

@media (max-width: 700px) {
  :root {
    --cell-size: 21px;
    --table-font-size: 10pt;
    --table-head-height: 24px;
  }

  .how-grid {
    grid-template-columns: 1fr;
  }

  .table-scroll {
    overflow-x: auto;
    scrollbar-color: rgba(102, 0, 0, 0.45) rgba(255, 255, 255, 0.22);
  }
}

@media (max-width: 560px) {
  .page-wrap {
    align-items: flex-start;
    min-height: calc(100vh - 60px);
    padding: 12px 8px;
  }

  #shadow-left,
  #shadow-right {
    width: 32px;
    background-size: 32px 221px;
  }

  .vigenere-window {
    padding: 8px;
  }

  .quiz-card-body {
    padding: 16px 14px 18px;
  }

  .quiz-title {
    font-size: 15.5pt;
  }

  .mode-selector {
    flex-direction: column;
  }

  .mode-option {
    min-height: 44px;
  }

  .text-input {
    font-size: 11.5pt;
  }

  .actions-row {
    flex-direction: column;
  }

  .actions-row .btn {
    width: 100%;
  }

  .stream-table {
    font-size: 12pt;
  }

  .stream-table td {
    width: 22px;
    min-width: 22px;
    max-width: 22px;
    height: 27px;
  }

  .stream-label {
    width: 100px !important;
    min-width: 100px !important;
    max-width: 100px !important;
    padding-right: 10px !important;
    font-size: 8.5pt !important;
  }

  .label-row {
    gap: 8px;
  }

  .result-hint {
    display: none;
  }

  .step-toolbar {
    gap: 6px;
  }

  .show-cell-btn {
    margin-left: 0;
  }

  :root {
    --cell-size: 21px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .vigenere-table td.is-target-cell {
    animation: none;
  }

  .btn,
  .text-input,
  .mode-option {
    transition: none;
  }
}