/* ==========================================================================
   СИМУЛЯТОР: ДОСЛІДЖЕННЯ ОПОРУ МЕТАЛІВ ВІД ТЕМПЕРАТУРИ (9 КЛАС)
   Повна адаптивність під мобільні пристрої, планшети та ПК
   ========================================================================== */

:root {
  --primary: #1976d2;
  --primary-dark: #0d47a1;
  --primary-light: #e3f2fd;
  --accent: #ff5722;
  --success: #2e7d32;
  --danger: #c62828;
  --bg: #f4f6f9;
  --panel-bg: #ffffff;
  --panel-border: #dcdfe6;
  --text-main: #2c3e50;
  --text-muted: #606266;
  --wire-red: #d32f2f;
  --wire-shadow: rgba(180, 20, 20, 0.4);
  --metal-brass: #d4af37;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background-color: var(--bg);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Шапка додатку */
header {
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  color: #fff;
  padding: 12px 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.header-title h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.header-title p {
  font-size: 0.85rem;
  opacity: 0.9;
  font-weight: 400;
}

.badge-tag {
  display: inline-block;
  background: rgba(255, 255, 255, 0.2);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Навігаційні вкладки (особливо зручно на мобільному) */
.nav-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  padding: 3px;
  gap: 4px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.85);
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.tab-btn.active {
  background: #ffffff;
  color: var(--primary-dark);
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

/* Основний макет */
main {
  flex: 1;
  max-width: 1280px;
  width: 100%;
  margin: 12px auto;
  padding: 0 12px;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Секція симулятора */
.sim-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 992px) {
  .sim-container {
    grid-template-columns: 340px 1fr;
  }
}

/* Панель керування */
.controls-panel {
  background: var(--panel-bg);
  border-radius: var(--radius);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px;
}

.panel-card h3 {
  font-size: 0.95rem;
  color: var(--primary-dark);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
}

.form-group {
  margin-bottom: 10px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

select.custom-select {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}

select.custom-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.15);
}

/* Повзунки та регулятори */
.range-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

input[type="range"] {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: #cbd5e1;
  outline: none;
  -webkit-appearance: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.range-val {
  min-width: 58px;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--primary-dark);
  text-align: right;
  background: var(--primary-light);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Швидкі кнопки вибору температури (для кроку 20 °C) */
.temp-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.temp-pill {
  flex: 1 0 calc(25% - 5px);
  background: #fff;
  border: 1px solid #cbd5e1;
  padding: 6px 2px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 6px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
}

.temp-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.temp-pill.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 2px 4px rgba(255, 87, 34, 0.3);
}

/* Керування швидкістю та паузою симуляції */
.sim-speed-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #f1f5f9;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  margin-top: 8px;
}

.speed-selector {
  display: flex;
  align-items: center;
  gap: 4px;
}

.speed-btn {
  background: #fff;
  border: 1px solid #cbd5e1;
  color: var(--text-main);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.speed-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.speed-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-pause {
  background: #fff;
  border: 1px solid #cbd5e1;
  color: var(--text-main);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s;
}

.btn-pause:hover {
  background: #f8fafc;
  border-color: var(--primary);
}

.btn-pause.paused {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #b45309;
  font-weight: 700;
}

/* Кнопки дій */
.btn-row {
  display: flex;
  gap: 8px;
}

.btn {
  flex: 1;
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-accent:hover {
  background: #e64a19;
}

.btn-outline {
  background: #fff;
  border: 1px solid #cbd5e1;
  color: var(--text-main);
}

.btn-outline:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-success:hover {
  background: #1b5e20;
}

/* Сцена електричного кола */
.circuit-stage-card {
  background: #ffffff;
  border-radius: var(--radius);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  padding: 12px;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
}

/* Повноекранний режим */
.circuit-stage-card.fullscreen-mode {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  margin: 0 !important;
  padding: 10px !important;
  border-radius: 0 !important;
  z-index: 99999 !important;
  background: #f8fafc !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: space-between !important;
}

.circuit-stage-card.fullscreen-mode .svg-canvas-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  max-height: calc(100vh - 110px);
}
.circuit-stage-card.fullscreen-mode #circuitSvg {
  max-height: 100%;
  width: auto;
  margin: 0 auto;
}

/* Плаваюча панель швидкого керування у повноекранному режимі */
.fs-toolbar {
  display: none;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(8px);
  padding: 8px 14px;
  border-radius: 30px;
  position: absolute;
  bottom: 15px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  gap: 8px;
  align-items: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  max-width: 95vw;
  overflow-x: auto;
}

.circuit-stage-card.fullscreen-mode .fs-toolbar {
  display: flex;
}

.fs-tool-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: all 0.2s;
}

.fs-tool-btn:hover, .fs-tool-btn:active {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.fs-tool-btn.active {
  background: var(--accent);
  border-color: var(--accent);
}

/* Інтерактивні SVG елементи з підсвіткою при наведенні */
.interactive-svg-element {
  cursor: pointer;
  transition: opacity 0.15s ease, filter 0.15s ease;
}

.interactive-svg-element:hover {
  filter: drop-shadow(0 0 6px rgba(25, 118, 210, 0.5));
}

/* Не використовуємо CSS transform: він перекриває SVG transform="translate(...)"
   і переносить натиснутий елемент до початку системи координат SVG. */
.interactive-svg-element:active {
  opacity: 0.78;
  filter: drop-shadow(0 0 8px rgba(25, 118, 210, 0.72));
}

.stage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid #edf2f7;
  margin-bottom: 8px;
  flex-wrap: wrap;
  gap: 6px;
}

.stage-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 600px) {
  .sim-container .circuit-stage-card {
    order: -1;
  }

  .stage-actions {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .stage-actions .circuit-status {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .stage-actions .btn-quick-graph,
  .stage-actions #btnFullscreen {
    width: 100%;
    min-height: 44px;
    padding: 8px 12px !important;
    justify-content: center;
    border-color: #1d4ed8;
    border-radius: 8px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    font-size: 0.8rem !important;
    font-weight: 800;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.34);
  }

  .stage-actions #btnFullscreen {
    animation: fullscreen-attention 0.9s ease-in-out 5;
  }

  .stage-actions .btn-quick-graph:hover,
  .stage-actions .btn-quick-graph:focus-visible,
  .stage-actions #btnFullscreen:hover,
  .stage-actions #btnFullscreen:focus-visible {
    background: linear-gradient(135deg, #1d4ed8, #1e40af);
    border-color: #1e3a8a;
  }
}

@keyframes fullscreen-attention {
  0%, 100% {
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.34);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(59, 130, 246, 0.2), 0 6px 16px rgba(37, 99, 235, 0.46);
    transform: scale(1.015);
  }
}

@media (prefers-reduced-motion: reduce) {
  .stage-actions #btnFullscreen {
    animation: none;
  }
}
.stage-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
}

.circuit-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
}

.circuit-status.closed {
  background: #e8f5e9;
  color: var(--success);
}

.circuit-status.open {
  background: #ffebee;
  color: var(--danger);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.closed .status-dot {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
  animation: pulse 1.5s infinite;
}

.open .status-dot {
  background: var(--danger);
}

@keyframes pulse {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.2); }
  100% { opacity: 1; transform: scale(1); }
}

/* SVG Контейнер схеми */
.svg-canvas-wrapper {
  width: 100%;
  position: relative;
  background: linear-gradient(180deg, #fbfcfe 0%, #f1f5f9 100%);
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  overflow: hidden;
  touch-action: pan-y;
}


#circuitSvg {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
}

/* Анімація полум'я спиртівки */
@keyframes flameWiggle {
  0% { transform: scale(1) skewX(0deg); }
  25% { transform: scale(1.04, 1.08) skewX(-2deg); }
  50% { transform: scale(0.96, 0.94) skewX(2deg); }
  75% { transform: scale(1.02, 1.05) skewX(-1deg); }
  100% { transform: scale(1) skewX(0deg); }
}

.flame-active {
  animation: flameWiggle 0.5s ease-in-out infinite alternate;
  transform-origin: 395px 330px;
}

/* Індикатор струму по дротах */
@keyframes dashFlow {
  to {
    stroke-dashoffset: -20;
  }
}

.current-flow {
  stroke-dasharray: 6 4;
  animation: dashFlow 0.8s linear infinite;
}

/* Таблиця та графік */
.data-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 992px) {
  .data-container {
    grid-template-columns: 1fr 1fr;
  }
}

.data-card {
  background: var(--panel-bg);
  border-radius: var(--radius);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.card-head h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.table-wrapper {
  overflow-x: auto;
  max-height: 420px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

table.lab-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  text-align: center;
}

table.lab-table th {
  background: #f1f5f9;
  color: var(--text-main);
  padding: 10px 8px;
  font-weight: 700;
  border-bottom: 2px solid #cbd5e1;
  position: sticky;
  top: 0;
  z-index: 2;
}

table.lab-table td {
  padding: 8px;
  border-bottom: 1px solid #e2e8f0;
}

table.lab-table tr:hover td {
  background: #f8fafc;
}

table.lab-table tr:last-child td {
  border-bottom: none;
}

.empty-table-msg {
  text-align: center;
  padding: 30px;
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.9rem;
}

/* Canvas графіка */
.graph-wrapper {
  width: 100%;
  position: relative;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  padding: 8px;
}

#graphCanvas {
  display: block;
  width: 100%;
  height: 360px;
}

.graph-stats {
  margin-top: 10px;
  padding: 10px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  font-size: 0.8rem;
}

.stat-item {
  display: flex;
  flex-direction: column;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.stat-val {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--primary-dark);
}

/* Довідка та Теорія */
.theory-card {
  background: var(--panel-bg);
  border-radius: var(--radius);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.theory-card h2 {
  color: var(--primary-dark);
  font-size: 1.15rem;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--primary-light);
}

.theory-card p, .theory-card li {
  font-size: 0.9rem;
  color: #334155;
  margin-bottom: 8px;
}

.theory-card ul, .theory-card ol {
  padding-left: 20px;
}

.formula-box {
  background: #f1f5f9;
  border-left: 4px solid var(--primary);
  padding: 10px 14px;
  margin: 12px 0;
  border-radius: 0 8px 8px 0;
  font-family: "Cambria Math", "Times New Roman", serif;
  font-size: 1.05rem;
}

.material-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-top: 10px;
}

.material-table th, .material-table td {
  border: 1px solid #e2e8f0;
  padding: 6px 10px;
  text-align: left;
}

.material-table th {
  background: #f8fafc;
  color: var(--text-main);
  font-weight: 700;
}

/* Футер */
footer {
  background: #fff;
  border-top: 1px solid var(--panel-border);
  padding: 10px 16px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: auto;
}

/* Спливаюче повідомлення (Toast) */
.toast-notice {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1e293b;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  font-size: 0.85rem;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 1000;
  pointer-events: none;
}

.toast-notice.show {
  opacity: 1;
  transform: translateY(0);
}


.rotate-device-notice {
  display: none;
}

@media (max-width: 700px) and (orientation: portrait) {
  .circuit-stage-card.fullscreen-mode .rotate-device-notice {
    position: absolute;
    inset: 0;
    z-index: 100001;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 24px;
    background: #0f172a;
    color: #ffffff;
    text-align: center;
  }

  .rotate-device-notice > span:first-child {
    font-size: 3rem;
  }

  .rotate-device-notice > span:not(:first-child) {
    color: #cbd5e1;
  }
}
`n.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
`n.btn-quick-graph{min-height:44px}.quick-graph-dialog{width:min(94vw,820px);max-width:none;padding:0;border:0;border-radius:16px;background:#fff;color:var(--text-main);box-shadow:0 24px 70px rgba(15,23,42,.4)}.quick-graph-dialog::backdrop{background:rgba(15,23,42,.68);backdrop-filter:blur(3px)}.quick-graph-panel{padding:14px}.quick-graph-header{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:10px}.quick-graph-header h2{margin:0;font-size:clamp(1rem,4vw,1.3rem)}.quick-graph-close{flex:0 0 44px;width:44px;height:44px;border:1px solid #cbd5e1;border-radius:50%;background:#f8fafc;color:#334155;font:inherit;font-size:1.6rem;cursor:pointer}.quick-graph-close:focus-visible{outline:3px solid #2563eb;outline-offset:2px}.quick-graph-canvas{display:block;width:100%;height:min(62vh,460px);border:1px solid #e2e8f0;border-radius:10px;background:#fff}.quick-graph-canvas[hidden]{display:none}.quick-graph-empty{margin:24px 0;padding:18px;border-radius:10px;background:#f1f5f9;text-align:center;color:var(--text-muted)}
@media(max-width:600px){.quick-graph-dialog{width:calc(100vw - 16px)}.quick-graph-panel{padding:10px}.quick-graph-canvas{height:min(66vh,420px)}}
@media print{.quick-graph-dialog{display:none}}