/* Глобальный стиль скроллбара */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(139, 148, 158, 0.5) transparent;
}

*::-webkit-scrollbar {
  width: 6px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background-color: rgba(139, 148, 158, 0.5);
  border-radius: 10px;
}
*::-webkit-scrollbar-thumb:hover {
  background-color: rgba(139, 148, 158, 0.8);
}

/* Убираем рамки фокуса для всех кнопок и ссылок */
button,
a {
  outline: none !important;
  -webkit-tap-highlight-color: transparent;
}

body { 
  background: radial-gradient(circle at center, #0a1e3d 0%, #050a18 100%); 
  color: #fff; 
  font-family: 'Segoe UI', sans-serif; 
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center; 
  min-height: 100vh;
  min-height: 100dvh; 
  margin: 0; 
  padding: 20px 0;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

/* app-frame: Anti-Scroll — фиксация без паразитного скролла */
.app-frame {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
}

@media (min-width: 481px) {
  body { background: radial-gradient(circle at center, #0a1e3d 0%, #050a18 100%); }
  .app-frame {
      left: 50%;
      transform: translateX(-50%);
      max-width: 480px;
      box-shadow: 0 0 60px rgba(0, 0, 0, 0.5);
  }
}

.game-container { 
  max-width: 800px; 
  width: 92%; 
  text-align: center; 
  background: rgba(15, 23, 42, 0.9); 
  backdrop-filter: blur(15px); 
  padding: 16px 20px 20px 20px; 
  border-radius: 20px; 
  border: 2px solid #ff9a00; 
  box-shadow: 0 20px 60px rgba(0,0,0,0.6); 
  margin: 5px auto;
  box-sizing: border-box;
  min-height: calc(100vh - 10px);
  min-height: calc(100dvh - 10px);
  max-height: 100vh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 15px;
  overflow: hidden;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.fade-in-smooth {
  animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.game-header {
  width: 100%;
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
  background: rgba(15, 23, 42, 0.98);
}
.game-main {
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}
.game-footer {
  width: 100%;
  position: sticky;
  bottom: 0;
  z-index: 10;
  flex-shrink: 0;
  background: rgba(15, 23, 42, 0.98);
}

#question-counter { 
  color: #ffffff !important; 
  font-size: 13px; 
  letter-spacing: 2px; 
  font-weight: bold; 
  text-transform: uppercase; 
  max-width: 85%;
  margin: 12px auto 12px auto;
}
.question-block {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  max-width: 85%;
  margin: 0 auto;
}
#question-text { 
  font-size: 24px; 
  font-weight: bold; 
  color: #ff9a00 !important;
  margin: 10px auto; 
  min-height: auto; 
  line-height: 1.4; 
  width: 100%;
  display: flex;
  justify-content: center;
  text-align: left;
  word-wrap: normal;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  visibility: hidden;
}

.options-grid {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  margin: 8px auto 16px auto;
  max-width: 600px;
  width: 100%;
  justify-items: stretch;
}

.option-btn {
  height: auto;
  min-height: 48px;
  background: rgba(255, 255, 255, 0.03);
  color: #fff;
  border: 1px solid rgba(255, 154, 0, 0.3);
  padding: 14px 15px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1.35;
  transition: 0.3s ease;
  text-align: left;
  display: flex;
  align-items: center;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: normal;
  hyphens: none;
  width: 100%;
  box-sizing: border-box;
}
.option-btn:hover:not(:disabled) { background: rgba(255, 154, 0, 0.1); border-color: #ff9a00; }
.option-btn.correct { background: #238636 !important; border-color: #2ea043 !important; opacity: 1 !important; }
.option-btn.wrong { background: #da3633 !important; border-color: #f85149 !important; opacity: 1 !important; }

.controls { display: flex; justify-content: center; gap: 12px; }

/* Эталон таймера: Ghost Style — прозрачный фон, оранжевая рамка, 14px Bold */
#timer-display {
  width: 140px;
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-sizing: border-box;
  overflow: hidden;
  position: relative;
  white-space: nowrap;
  background: transparent;
  border: 1px solid #ff9a00;
  color: #ff9a00;
  font-size: 14px !important;
  font-weight: bold;
  cursor: default;
  box-shadow: none;
}
#timer-display:hover {
  transform: none;
}

#timer-display.danger {
  color: transparent;
}
#timer-display.danger::after {
  content: "ВРЕМЯ ВЫШЛО";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 14px;
  font-weight: bold;
  text-transform: uppercase;
  color: #ff4d4d;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
}
#timer-display.danger.show-msg::after {
  opacity: 1;
}

/* Производные кнопки: Ghost Style на основе эталона таймера */
.ui-btn {
  width: 140px;
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  font-weight: bold;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-sizing: border-box;
  overflow: hidden;
  position: relative;
  white-space: nowrap;
  transition: all 0.3s ease;
  background: transparent !important;
  border: 1px solid #ff9a00;
  color: #ff9a00;
  cursor: pointer;
  box-shadow: none;
}
.ui-btn:hover {
  background: transparent !important;
  color: #ff9a00;
  border-color: #ff9a00;
  transform: none;
  box-shadow: none;
}
.ui-btn:active {
  filter: brightness(1.2);
  box-shadow: none;
}
#next-btn {
  display: none;
  cursor: pointer;
  text-decoration: none;
  outline: none !important;
  -webkit-tap-highlight-color: transparent;
}

#correct-counter { color: #ffffff !important; font-size: 13px; font-weight: bold; letter-spacing: 1.5px; margin-top: 25px; text-transform: uppercase; }

.brand-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  width: 100%;
  max-width: 85%;
  margin: 0 auto 12px auto;
  padding: 0 6px 10px 6px;
  border-bottom: 1px solid rgba(255, 154, 0, 0.18);
  box-sizing: border-box;
  flex-shrink: 0;
}
.brand-header h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 900;
  color: #ff9a00;
  letter-spacing: 1px;
  white-space: normal;
  line-height: 1.3;
}

#view-final .brand-header .save-status {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
  line-height: 1.2;
  padding: 6px 10px;
  text-align: center;
}

.result-header {
  text-align: center;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 2px solid rgba(255, 154, 0, 0.3);
  flex-shrink: 0;
}

.result-title {
  color: #ff9a00;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.result-info {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 14px;
  align-items: flex-start;
  text-align: left;
  margin: 8px 0;
}

.result-info-item {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
}

.result-info-label {
  color: #ff9a00;
  font-weight: bold;
  flex: 0 0 60px;
  text-align: left;
}

.result-info-value {
  color: #ffffff;
  font-weight: bold;
}

.result-info-total {
  color: #00f2ff;
  font-weight: bold;
}

.result-info-rating {
  color: #00f2ff;
  font-weight: bold;
  font-size: 16px;
}

.res-table { 
  width: 100%; 
  border-collapse: collapse; 
  margin-top: 5px; 
  font-size: 12px; 
  text-align: center; 
  table-layout: fixed;
  background-color: #161b22 !important;
  color: #e6edf3 !important;
  border: 1px solid #30363d !important;
}
.res-table th { 
  background-color: #161b22 !important;
  color: #00bcd4 !important;
  padding: 8px 5px; 
  border-bottom: 1px solid #30363d !important;
  border-right: 1px solid #30363d !important;
  text-transform: uppercase; 
  font-size: 10px; 
  font-weight: bold;
}
.res-table td { 
  background-color: #161b22 !important;
  color: #e6edf3 !important;
  padding: 8px 5px; 
  border-bottom: 1px solid #30363d !important;
  border-right: 1px solid #30363d !important;
  vertical-align: middle; 
  overflow-wrap: break-word;
  word-wrap: break-word;
}
.res-table th:not(:last-child), .res-table td:not(:last-child) { border-right: 1px solid #30363d !important; }

.col-num { width: 40px; }
.col-q { 
  width: 40%; 
  min-width: 220px;
  text-align: left !important; 
  padding-left: 15px !important; 
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
}
.col-a { width: 25%; }
.col-t { width: 15%; }
.col-s { width: 12%; }

.tr-total { 
  color: #00bcd4 !important; 
  font-weight: bold !important; 
  font-size: 15px; 
  background: rgba(0, 188, 212, 0.08) !important;
}
.tr-total td {
  color: #00bcd4 !important;
  font-weight: bold !important;
}
.tr-total-label {
  text-align: left !important;
  padding-left: 15px !important;
}

.txt-success {
  color: #66bb6a !important;
  font-weight: bold !important;
}

.txt-error {
  color: #ff4444 !important;
  font-weight: bold !important;
}

.result-footer {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
  padding: 20px 0;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid rgba(255, 154, 0, 0.2);
  flex-shrink: 0;
}
.orange-link { color: #ff9a00; text-decoration: none; font-weight: bold; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; transition: 0.3s ease; }
.orange-link:hover { color: #ff9a00; }

.result-exit-btn {
  flex: 1;
  max-width: 320px;
}

.result-rating-link {
  flex: 1;
  max-width: 320px;
}

/* Стили для сообщения о лимите */
.limit-exceeded-message {
  text-align: center;
  padding: 40px 20px;
}

.limit-exceeded-title {
  color: #ff9a00;
  margin-bottom: 20px;
  font-size: 20px;
}

.limit-exceeded-text {
  margin-bottom: 20px;
  color: var(--text-main);
  font-size: 16px;
}

/* Кнопка "Результат" на 10-м вопросе — Ghost Style, без изменений (наследует от .ui-btn) */

/* Кнопки футера итогов: эталон .ui-btn (40px, 12px) + только ширина в ряд */
.result-footer .ui-btn {
  flex: 1;
  max-width: 320px;
}

.results-table-container,
.game-results {
  flex: 1;
  min-height: 0;
  max-height: 500px;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 10px;
  border-top: 1px solid rgba(255, 154, 0, 0.1);
  background-color: #161b22 !important;
  color: #e6edf3 !important;
  border: 1px solid #30363d !important;
  padding: 12px;
  padding-right: 16px;
  box-sizing: content-box;
  touch-action: pan-y;
  min-height: 120px;
}

.results-cards-container {
  flex: 1;
  min-height: 0;
  max-height: 500px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  margin-bottom: 10px;
  padding: 0;
  box-sizing: border-box;
  touch-action: pan-y;
  display: flex;
  flex-direction: column;
}

/* Блок вопроса в итогах — полностью адаптивная высота по контенту */
.results-cards-container .option-btn {
  height: auto;
  min-height: fit-content;
  padding: 10px 12px;
  margin-left: 0;
  margin-right: 0;
  margin-bottom: 8px;
  display: block;
  cursor: default;
}

.results-cards-container .option-btn:last-child {
  margin-bottom: 0;
}

.result-card {
  box-sizing: border-box;
  display: block;
  text-align: left;
  word-wrap: break-word;
  overflow-wrap: break-word;
  width: 100%;
}

.result-item {
  padding: 0;
}

/* Текст вопроса: курсив, не жирный; цвет — Success/Error как в игре */
.result-card .result-question-text {
  font-size: 16px;
  line-height: 1.3;
  font-style: italic;
  font-weight: 400;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.result-card .result-question-text.result-correct {
  color: #2ea043 !important;
}

.result-card .result-question-text.result-wrong {
  color: #f85149 !important;
}

.countdown-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  box-sizing: border-box;
  background: radial-gradient(circle at center, #0a1e3d 0%, #050a18 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  opacity: 1;
  transition: opacity 0.5s ease-out;
}

.countdown-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.countdown-text {
  color: #ff9a00;
  font-size: 18px;
  font-weight: bold;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 30px;
  text-shadow: 0 0 20px rgba(255, 154, 0, 0.5);
  font-family: 'Segoe UI', sans-serif;
}

.countdown-number {
  color: #ff9a00;
  font-size: 120px;
  font-weight: 900;
  text-shadow: 0 0 40px rgba(255, 154, 0, 0.8);
  font-family: 'Segoe UI', sans-serif;
  line-height: 1;
  animation: pulse 0.5s ease-in-out;
}

@keyframes pulse {
  0% { transform: scale(0.8); opacity: 0.5; }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

#main-ui.saving-pause {
  display: flex !important;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 80vh;
  min-height: 80dvh;
}

.save-status {
  color: #fff;
  font-size: 24px;
  text-align: center;
  margin: 0 !important;
  padding: 40px 30px;
  width: auto;
  max-width: 90%;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(15px);
  border: 2px solid #ff9a00;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  box-sizing: border-box;
}
.save-status.save-error {
  color: #ff4444;
}
.saving-pause {
  pointer-events: none;
}

@media (min-width: 1024px) {
  body {
      padding-left: 120px;
      padding-right: 120px;
  }
}

@media (min-width: 1440px) {
  body {
      padding-left: 220px;
      padding-right: 220px;
  }
}

@media (max-width: 600px) {
  body {
      padding: 2px 0;
      padding-left: env(safe-area-inset-left);
      padding-right: env(safe-area-inset-right);
      padding-bottom: env(safe-area-inset-bottom);
      min-height: auto;
      justify-content: center;
  }
  
  .game-container { 
      width: 96%; 
      max-width: calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right) - 20px);
      padding: 16px 14px;
      margin: 5px auto;
      min-height: calc(100vh - 10px);
      min-height: calc(100dvh - 10px);
      justify-content: flex-start;
      gap: 8px;
  }

  #main-ui.saving-pause {
      display: flex !important;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      min-height: 99vh;
      min-height: 99dvh;
      width: 100%;
      margin-top: 5px;
      padding: 20px;
      box-sizing: border-box;
  }

  .save-status {
      font-size: 20px;
  }

  #question-counter { margin: 6px auto 8px auto; color: #ffffff !important; }
  
  .options-grid { grid-template-columns: 1fr; gap: 8px; margin: 6px auto 10px auto; justify-items: center; }
  #question-text { 
      font-size: 18px; 
      color: #ff9a00 !important;
      font-weight: bold;
      text-align: left; 
      width: 100%;
      margin: 0 auto 10px auto; 
      min-height: auto;
      line-height: 1.4;
      word-wrap: normal;
      overflow-wrap: normal;
      word-break: normal;
      hyphens: none;
  }
  .option-btn {
      height: auto;
      min-height: 48px;
      padding: 12px 12px;
      font-size: 16px;
      line-height: 1.35;
      width: 100%;
      max-width: 340px;
      margin: 6px auto;
      text-align: left;
  }
  .controls { flex-direction: row; align-items: stretch; justify-content: center; gap: 12px; margin-bottom: 4px; }
  .ui-btn { width: calc(50% - 6px); max-width: 160px; }
  #next-btn { width: calc(50% - 8px); max-width: 340px; }
  #correct-counter { color: #ffffff !important; font-size: 11px; margin-top: 6px; margin-bottom: 6px; letter-spacing: 1px; }
  
  .result-title { font-size: clamp(12px, 3.6vw, 16px) !important; letter-spacing: 0px !important; margin-bottom: 6px; }
  .result-info { font-size: 14px; gap: 10px; margin-top: 20px; margin-bottom: 18px; }
  .result-info-label { flex: 0 0 52px; }
  .result-info-rating { font-size: 16px; }

  .res-table { font-size: 10px; margin-top: 3px; table-layout: auto; min-width: 380px; }
  .res-table th { font-size: 8px; padding: 5px 2px; }
  .res-table td { padding: 5px 2px; }
  
  .col-num { width: 22px; }
  .col-q { 
      min-width: 220px;
      text-align: left !important; 
      padding-left: 10px !important; 
      word-wrap: break-word;
      overflow-wrap: break-word;
      white-space: normal;
  }
  .col-a { width: 85px; }
  .col-t { width: 42px; }
  .col-s { width: 38px; }
  
  .countdown-text { font-size: 14px; letter-spacing: 2px; margin-bottom: 20px; }
  .countdown-number { font-size: 80px; }
  
  .result-footer { margin-top: 2px; padding-top: 2px; gap: 10px; flex-direction: row; }
  .results-table-container,
  .game-results {
      max-height: 420px;
      padding: 16px;
      min-height: 140px;
  }
}

@media (max-width: 480px) {
}

/* Очень узкие экраны (320–400px): без переопределения height/font кнопок и таймера */
@media (max-width: 400px) {
  .game-container { padding: 12px 10px; gap: 10px; }
  #question-text { font-size: 18px; color: #ff9a00 !important; font-weight: bold; line-height: 1.4; }
  .option-btn { padding: 14px 12px; height: auto; min-height: 48px; }
  .countdown-number { font-size: 70px; }
}

/* Landscape: минимизация Header и Tab Bar для доступа к таблице */
@media (orientation: landscape) and (max-height: 500px) {
  .game-header { padding: 4px 0; }
  #question-counter { font-size: 10px; margin: 4px auto; color: #ffffff !important; }
  .game-footer { padding: 4px 0; }
  .controls { gap: 8px; }
  .ui-btn { width: 120px; height: 34px; min-height: 34px; padding: 0 8px; font-size: 9px; background: transparent; border: 1px solid #ff9a00; color: #ff9a00; box-shadow: none; }
  .ui-btn:active { background: rgba(255, 154, 0, 0.15); filter: brightness(1.1); }
  #timer-display { font-size: 11px !important; }
  #timer-display.danger::after { font-size: 11px !important; }
  #correct-counter { color: #ffffff !important; font-size: 10px; margin-top: 4px; }
  .result-header { margin-bottom: 8px; padding-bottom: 8px; }
  .result-footer { margin-top: 4px; padding-top: 4px; gap: 16px; }
  .results-table-container,
  .game-results { max-height: 180px; }
}

/* Откат: копия стилей до унификации — css/game_backup.css */
