/* =========================================================================
   ЭКВМ «Искра-122» — стили
   -------------------------------------------------------------------------
/* --------------------------- Общий сброс --------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
/* --------------------------- Шрифты --------------------------- */
@font-face {
  font-family: 'digital';
  src: url("fonts/digital.ttf") format('truetype');
  font-display: auto;
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'gost';
  src: url("fonts/GOSTTypeB.woff2") format('woff2');
  font-display: auto;
  font-weight: normal;
  font-style: normal;
}
/* =========================================================================
   ТОКЕНЫ: цвета, шрифты, позиционирование
   ========================================================================= */
:root {
  /* ---- Цвета ---- */
  --color-page-bg: #ffffff;
  --color-board-bg: #d8dbd3;
  --color-board-border: #9aa3a8;

  --color-screen-bg: #29002c;
  --color-screen-border: #0d000f;
  --color-screen-digit: #dd600d;

  --color-label-bg: #b8bdb3;
  --color-label-border: #000000;
  --color-label-text: #000000;

  --color-key-bg: #8a8b63;
  --color-key-shadow: #444141;
  --color-key-shadow-inset: rgba(136, 85, 85, 0.5);
  --color-key-shadow-inset-active: rgba(129, 76, 76, 0.5);
  --color-digit-key-bg: #e6e8d7;
  --color-equals-bg: rgb(166, 47, 10);

  --color-panel-border: #000000;
  --color-panel-shadow: #9f9f9e;

  --color-precision-btn: #000000;
  --color-precision-btn-zero: #A8392F;

  --color-switch-track: #6b7073;
  --color-switch-border: #9aa3a8;
  --color-switch-knob: #dbebed;

  --color-register-text: #292121;
  /* Ширина одного разряда регистра и их количество (знак + 16 цифр + точка) -
     раньше ширина .register-display подбиралась в JS через scrollWidth,
     что не пережило переход регистров на строки; теперь ширина задаётся
     здесь и .register-display её просто использует через calc(). */
  --register-digit-width: 14.55px;
  --register-digit-count: 18;

  --color-instruction-bg: #4a6a8f;
  --color-instruction-bg-hover: #5f7fa0;
  --color-instruction-shadow-inset: rgba(10, 30, 99, 0.5);

  --font-digital: 'digital';
  --font-gost: 'gost';

  /* =======================================================================
     ПОЗИЦИОНИРОВАНИЕ ПЛАТЫ КАЛЬКУЛЯТОРА
     -----------------------------------------------------------------------
     ======================================================================= */
  --board-min-width: 320px;
  --board-max-width: 825px;
  --board-aspect: 825 / 700;
  --board-border-width: 20px;

  /* .top-svg — декоративная верхняя панель (в % от платы) */
  --top-svg-left: 5%;
  --top-svg-width: 90%;
  --top-svg-height: 30%;
  --top-svg-scale-x: 1.1215;
  --top-svg-scale-y: 1.1;

  /* .screen-section / .screen — блок экрана (в % от платы) */
  --screen-top: 38%;
  --screen-left: 13%;
  --screen-width: 80%;
  --screen-height: 10%;
  --screen-scale: 1.25;

  /* .calculator-title — табличка с названием модели (в % от платы) */
  --title-top: 0.5%;
  --title-left: 75%;
  --title-width: 21%;
  --title-max-width:155px;
  --title-height: 6%;
  --title-scale: 0.9;

  /* .keyboard — область клавиатуры целиком (в % от платы) */
  --keyboard-top: 50%;
  --keyboard-right: -32%;
  --keyboard-width: 75%;
  --keyboard-height: 27%;
  --keyboard-scale: 1.1;

  /* .precision — переключатель точности (в % от .keyboard) */
  --precision-top: -4.44%;
  --precision-left: -31.91%;
  --precision-scale: 0.93;
  --precision-width: 80px;
  --precision-height: 180px;

  /* .switch-row — тумблер включения (в % от .keyboard) */
  --switch-top: -20%;
  --switch-left: -51.5%;
  --switch-rotate: 270deg;
  --switch-scale: 1.5;

  /* .memory_flags — панель регистров и флагов */
  --memory-flags-basis: 330px;
  --memory-flags-min: 220px;
}
/* =========================================================================
   БАЗОВЫЕ СТИЛИ СТРАНИЦЫ
   ========================================================================= */
html {
  height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background-color: #ffffff;
}

img {
  display: block;
  max-width: none; /* .top-svg сознательно шире платы — декоративный "вылет" за края, как и в исходном макете */
}

/* =========================================================================
   ОБЩАЯ СТРАНИЧНАЯ РАСКЛАДКА
   -------------------------------------------------------------------------
   ========================================================================= */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: auto;
}

.workspace {
  flex: 1 1 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(8px, 2vw, 120px);
  padding-top: 0;
  padding-bottom: 0;
  padding-left:10%;
  width: 100%;
}

.calculator {
  display: flex;
  justify-content: center;
  flex: 0 1 auto;
}
/* =========================================================================
   ОСНОВНАЯ ПЛАТА КАЛЬКУЛЯТОРА
   ========================================================================= */
.calc {
  width: clamp(320px, 55vw, 825px);
  aspect-ratio: 825 / 700;
  background-color: #d8dbd3;
  border: 20px solid #9aa3a8;
  position: relative;
}

.calc_body {
  position: relative;
  width: 100%;
  height: 100%;
}

/* --------------------------- Декоративная верхняя панель --------------------------- */
.top-svg {
  position: absolute;
  left: 5%;
  width: 90%;
  height: 30%;
  transform: scale(1.1215, 1.1);
  transform-origin: top;
  pointer-events: none;
}

/* =========================================================================
   ЭКРАН
   ========================================================================= */
.screen-section {
  z-index: 2;
  top: 38%;
  width: 80%;
  height: 10%;
  position: relative;
  display: block;
  margin: auto;
  transform: scale(115%);
}
.screen-holder{
  display:flex;
  width:100%;
  height:100%;
}
.screen {
  width: 100%;
  height: 100%;
  background-color: #29002c;
  border-top: solid 8px #0d000f;
  border-bottom: solid 8px #0d000f;
  border-right: solid 4px #0d000f;
  border-left: solid 4px #0d000f;
  text-align: center;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  gap: 0.5%;
  padding-left:2%;
  padding-right:2%;
}
.screen-item {
  color: #dd600d;
  font-size: 48px;
  font-family: 'digital';
  text-align: right;
  opacity: 0.15; /* по умолчанию "погашен", зажигается через JS */
}
/* Точки (запятые) между разрядами */
.dot {
  margin-left: -5px;
  margin-right: -10px;
}

/* =========================================================================
   ТАБЛИЧКА С НАЗВАНИЕМ МОДЕЛИ
   ========================================================================= */
.calculator-title {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  top: 0.5%;  
  left: 75%;
  width: 21%;
  height: 6%;
  min-width: 0px;
  transform: scale(0.9);

  content: "";
  background: #b8bdb3;
  border: 2px solid #000000;
  z-index: 0;
}

#label {
  position: relative;
  z-index: 1;
  text-align: center;
  color: #000000;
  text-transform: uppercase;
  font-family: 'gost';
  font-size: 24px;
  font-weight: bold;
  border: solid 3px #000000;
  background-color: #b8bdb3;
  padding: 0 22px 0 22px;
  white-space: nowrap;
  max-width: 155px;
}

/* --------------------------- Переключатель включения --------------------------- */
.switch-row {
  top: -20%;
  left: -51.5%;
  transform: rotate(270deg) scale(1.5);
  display: flex;
  position: relative;
  align-items: center;
}
.onoffswitch {
  float: left;
  box-shadow: 0px 1px 1px 1px #444141,
    inset -2px -1px 10px 1px rgba(136, 85, 85, 0.5);
  position: relative;
  width: 50px;
}
.onoffswitch-checkbox {
  display: none;
}
.onoffswitch-label {
  display: block;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid #9aa3a8;
}
.onoffswitch-inner {
  display: block;
  width: 200%;
  margin-left: -100%;
  transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner::before,
.onoffswitch-inner::after {
  display: block;
  float: left;
  width: 50%;
  height: 14px;
  padding: 0;
  line-height: 14px;
  font-size: 10px;
  color: #525252;
  box-sizing: border-box;
}
.onoffswitch-inner::before {
  content: " ";
  padding-left: 5px;
  background-color: #6b7073;
}
.onoffswitch-inner::after {
  content: " ";
  background-color: #6b7073;
}
.onoffswitch-switch {
  display: block;
  width: 13px;
  margin: 2px;
  background: #dbebed;
  position: absolute;
  top: 0;
  bottom: 0;
  right: 33px;
  border: 2px solid #9aa3a8;
  border-radius:50%;
  transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
  margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
  right: 0px;
}
.onoffswitch-checkbox:focus-visible + .onoffswitch-label {
  outline-offset: 2px;
}

/* =========================================================================
   КЛАВИАТУРА — ОБЩАЯ ОБЛАСТЬ
   ========================================================================= */
.keyboard {
  top: 50%;
  width: 75%;
  height: 27%;
  background-color: #d8dbd3;
  position: relative;
  display: grid;
  grid-auto-flow: column;
  gap:6%;
  transform-origin: top;
  margin:auto;
}

/* --------------------------- Переключатель точности --------------------------- */
.precision {
  display: block flex;
  position: relative;
  border: 1px #000 solid;
  box-shadow: 0px 0px 2px 3px #9f9f9e;
  border-radius: 5%;
  width: 80px;
  height: 180px;
  justify-content: right;
  padding-right: 8px;
  gap:12px;
}
.precision-row {
  display: grid;
  grid-auto-flow: row;
  align-items: center;
  gap: 0px;
  color: #333;
}
.precision-button {
  height: 60% !important;
  width: 200% !important;
  cursor: pointer;
  transition: 0.05s linear;
  text-align: center;
  background-color: #000000;
}
.precision-button[data-precision="0"] {
  background-color: #A8392F;
}
.precision-button:active {
  transform: translateY(1px);
  box-shadow: 0px 1px 0 0 #444141,
    inset -1px -1px 3px 0px rgba(0, 0, 0, 0.3);
}
.precision-button.active {
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
}
.calc button[data-precision="0"]:active{
    background-color: #A8392F;
}
.precision-row-labels {
  position: relative;
  display: grid;
  grid-auto-flow: row;
  width: 60%;
  gap: 0px;
  font-family: 'gost';
  font-weight: bold;
  text-align: right;
  font-size: 15px;
  min-height: 0px;
  top:2.49%;
}
.precision-row-labels p {
  margin: 0;
  border-bottom: 2px solid #000000;
  height:70%;
}

/* Панель клавиш памяти */
.keys-memory {
  display: block grid;
  position:relative;
  gap: 2px 2px;
  grid-template-columns: 40px 40px;
  background-color: #000000;
  border: 1px solid #000;
  box-shadow: 0px 0px 2px 4px #9f9f9e;
  border-radius: 2%;
  font-size: 22px;
}
.circle-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 25px;
  height: 25px;
  border: 3px solid #000000;
  border-radius: 50%;
  font-size: 20px;
}

/* Панель клавиш цифр и точки */
.digits {
  display: block grid;
  position: relative;
  grid-template-columns: 40px 40px 40px;
  gap: 2px 2px;
  background-color: #000000;
  border: 1px solid #000;
  box-shadow: 0px 0px 2px 4px #9f9f9e;
  border-radius: 2%;
}

.digits button {
  background-color: #e6e8d7;
}

.digits button[value="0"] {
  grid-column: span 2;
}

/* Панель операций (+ обратное деление, смена знака, степень) */
.operations {
  display: grid;
  position:relative;
  grid-template-columns: 40px 40px 40px;
  gap: 2px 2px;
  background-color: #000000;
  border: 1px solid #000;
  box-shadow: 0px 0px 2px 4px #9f9f9e;
  border-radius: 2%;
}

.operations button[value="-"] {
  font-weight: bold;
}

.operations button[value="+"] {
  grid-row: span 2;
}

.operations button[value="*"] {
  grid-row: span 2;
}

.operations button[value="="] {
  background-color: rgb(166, 47, 10);
  grid-column: span 2;
  font-weight: bold;
}

.calc button[value="="]:active{
  background-color: rgb(166, 47, 10)
}

.operations button[value="/-/"] {
  font-size: 17px;
}

/* Панель доп. функций (печать, целая часть, скобки) */
.additional {
  display: grid;
  gap: 2px 2px;
  font-family: 'gost';
  background-color: #000000;
  border: 1px solid #000;
  box-shadow: 0px 0px 2px 4px #9f9f9e;
  border-radius: 2%;
}

/* --------------------------- Общий стиль всех кнопок --------------------------- */
.calc button {
  display: inline-block;
  height: 100%;
  width: 100%;
  font-family: 'gost';
  font-size: 22px;
  color: #000000;
  background-color: #8a8b63;
  border: none;
  outline: none;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  text-align: center;
  -webkit-appearance: none;
  appearance: none;
  box-shadow: 0px 1px 1px 1px #444141,
    inset -1px -1px 8px 1px rgba(136, 85, 85, 0.5);
  transition: 0.05s linear;
}

.calc button:active {
  transform: translateY(1px);
  background-color: #8a8b63;
  box-shadow: 0px 1px 0 0 #444141,
    inset -2px -1px 5px 0px rgba(129, 76, 76, 0.5);
}

.calc button:focus-visible {
  outline: 2px solid #8a8b63;
  outline-offset: 1px;
}

/* =========================================================================
   ПАНЕЛЬ РЕГИСТРОВ И ФЛАГОВ
   -------------------------------------------------------------------------*/

.registers{
  display:flex;
  position: relative;
  justify-content: center;
  margin: 0;
  width: auto;
  top:180px;
}

.memory_flags {
  display: grid;
  align-items: start;
  flex: 1 1 360px;
  max-width: 360px;
  min-width: 220px;
  height: fit-content;
  gap: 10px;
  border: 3px solid #000000;

  font-family: 'digital';
  font-size: clamp(20px, 2.2vw, 32px);
  color: #292121;
}

.memory {
  display: grid;
  gap: 15px;
  padding-left: 10px;
  padding-top: 10px;
  min-height: 0px;
  height: fit-content;
  width: fit-content;
}
.register {
  display: flex;
  height: auto;
  min-height: 0px;
  align-content: center;
}
.register label {
  width: fit-content;
  height: fit-content;
}
.register-display {
  width: calc(var(--register-digit-count) * var(--register-digit-width));
  max-width: 100%;
  height:fit-content;
  height: fit-content;
  overflow: hidden;      /* страховка на случай, если JS ещё не отработал */
}
.register-digit {
  margin: 0 0;
  padding-left: var(--register-digit-width);
  height: 32px;
  height:100%;
  font-size: var(--register-font-size);
  white-space: nowrap;   /* не даём 18 символам перенестись на вторую строку */
}
.flags {
  display: grid;
  padding-left: 10px;
  padding-bottom: 10px;
  gap: 10px;
}

/* =========================================================================
   КНОПКА "ИНСТРУКЦИЯ"
   ========================================================================= */

.instruction{
  position: relative; 
  box-sizing: border-box;
  width: fit-content;
  min-height:0;
  height:80px;
  top:305px;
}

#instruction-button {
  position: relative;
  background-color: #4a6a8f;
  color: #fff;
  border: none;
  padding: 10px 12px 10px 10px;
  font-size: 18px;
  font-family: 'gost';
  cursor: pointer;
  box-shadow: 0px 3px 1px 1px #444141,
    inset -2px -1px 10px 1px rgba(10, 30, 99, 0.5);
  transition: 0.05s linear;
  height: 80px;
}

#instruction-button:hover {
  background-color: #5f7fa0;
}

#instruction-button:active {
  transform: translateY(2px);
  box-shadow: 0px 1px 0 0 #444141,
    inset -2px -1px 5px 0px rgba(10, 30, 99, 0.5);
}

#instruction-button:focus-visible {
  outline: 2px solid #5f7fa0;
  outline-offset: 2px;
}

/* =========================================================================
   АДАПТИВНОСТЬ ДЛЯ УЗКИХ ЭКРАНОВ
   ========================================================================= */
@media (max-width: 760px) {
  .workspace {
    flex-direction: column;
    align-items: center;
  }

  .memory_flags {
    max-width: min(330px, 92vw);
    width: 100%;
  }

  .calc {
    width: clamp(320px, 92vw, 825px);
  }
}