/* ===== Wspólny system wizualny apletów — „Komputerowe rozwiązywanie problemów matematycznych” =====
 * Na wzór applets/style.css z kursu „Classical Foundations of ANN”.
 * Trzy światy obliczeń (spójne kolory w całym serwisie):
 *   numeryka = bursztyn (--warn), symbolika/CAS = indygo (--accent), dowód formalny = zieleń (--thm)
 */

:root {
  --bg: #fafbfc;
  --bg-alt: #f1f5f9;
  --text: #1e293b;
  --text-light: #64748b;
  --heading: #0f172a;
  --accent: #4f46e5;
  --accent-light: #e0e7ff;
  --def: #3b82f6;
  --thm: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --teal: #0d9488;
  --code-bg: #f1f5f9;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 8px;
  --radius-sm: 4px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  /* światy */
  --num: #d97706;   --num-bg: #fffbeb;  --num-soft: #fef3c7;
  --sym: #4f46e5;   --sym-bg: #eef2ff;  --sym-soft: #e0e7ff;
  --prf: #059669;   --prf-bg: #f0fdf4;  --prf-soft: #d1fae5;
  /* bity IEEE 754 */
  --bit-sign: #dc2626; --bit-exp: #0d9488; --bit-frac: #4f46e5;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
code, .mono { font-family: var(--font-mono); }
code { font-size: 0.88em; background: var(--code-bg); padding: 0.08em 0.35em; border-radius: var(--radius-sm); }

/* --- Pasek nawigacji --- */
.nav-bar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.nav-bar a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  white-space: nowrap;
  transition: opacity 0.15s;
}
.nav-bar a:hover { opacity: 0.7; }
.nav-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--heading);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.nav-links { display: flex; gap: 1.1rem; align-items: center; }

/* --- Kontener strony --- */
.page-container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

.page-header { margin-bottom: 1.3rem; }
.page-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--heading);
  margin-bottom: 0.3rem;
  letter-spacing: -0.02em;
  line-height: 1.25;
}
.page-header .subtitle { font-size: 1rem; color: var(--text-light); line-height: 1.5; }

.chapter-badge {
  display: inline-block;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  margin-bottom: 0.5rem;
}
.chapter-badge.num { background: var(--num-soft); color: #b45309; }
.chapter-badge.prf { background: var(--prf-soft); color: var(--prf); }

/* --- Układ: część główna + panel boczny --- */
.app-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 1.5rem; align-items: start; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.2rem; align-items: start; }
.three-col { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; align-items: stretch; }
@media (max-width: 960px) {
  .app-layout, .two-col, .three-col { grid-template-columns: minmax(0, 1fr); }
}

/* --- Karty / panele --- */
.panel {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.2rem;
  min-width: 0;
}
.panel > h2, .panel > h3 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--heading);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.8rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.panel p { font-size: 0.88rem; margin-bottom: 0.5rem; }
.panel p:last-child { margin-bottom: 0; }

.canvas-container {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  position: relative;
}
.canvas-container canvas { display: block; width: 100%; }

.control-panel {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  box-shadow: var(--shadow);
}
.control-panel h3 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--heading);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* --- Pola tekstowe --- */
.field { margin-bottom: 0.8rem; }
.field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.3rem;
}
input[type="text"], input[type="number"], select {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: white;
  color: var(--heading);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.input-row { display: flex; gap: 0.5rem; align-items: stretch; }
.input-row input { flex: 1; min-width: 0; }
.error-msg { color: var(--danger); font-size: 0.82rem; margin-top: 0.35rem; min-height: 1.1em; }

/* --- Suwaki --- */
.slider-group { margin-bottom: 1rem; }
.slider-group label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.3rem;
}
.slider-group .value { font-family: var(--font-mono); font-size: 0.8rem; color: var(--accent); font-weight: 600; }
input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 3px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

/* --- Przyciski --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.45rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: white;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-alt); border-color: #cbd5e1; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover { background: #4338ca; border-color: #4338ca; }
.btn-success { background: var(--thm); color: white; border-color: var(--thm); }
.btn-success:hover { background: #047857; border-color: #047857; }
.btn-warn { background: var(--warn); color: white; border-color: var(--warn); }
.btn-warn:hover { background: #b45309; border-color: #b45309; }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 0.28rem 0.65rem; font-size: 0.75rem; }
.btn-group { display: flex; gap: 0.45rem; flex-wrap: wrap; }

/* presety */
.preset-group { margin-bottom: 1rem; }
.preset-group .label {
  font-size: 0.72rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 0.4rem;
}
.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: white;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); background: var(--sym-bg); }
.chip.active { background: var(--accent); color: white; border-color: var(--accent); }

/* --- Przełącznik --- */
.toggle-switch { display: inline-flex; align-items: center; gap: 0.6rem; cursor: pointer; user-select: none; }
.toggle-track { width: 44px; height: 24px; background: #94a3b8; border-radius: 12px; position: relative; transition: background 0.2s; flex-shrink: 0; }
.toggle-track.on { background: var(--thm); }
.toggle-thumb { width: 20px; height: 20px; background: white; border-radius: 50%; position: absolute; top: 2px; left: 2px; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.toggle-track.on .toggle-thumb { transform: translateX(20px); }
.toggle-label { font-size: 0.85rem; font-weight: 500; }

/* --- Wartości --- */
.value-display { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.6rem; }
.value-item { text-align: center; padding: 0.55rem; background: var(--bg-alt); border-radius: var(--radius-sm); min-width: 0; }
.value-item .label { font-size: 0.68rem; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.04em; }
.value-item .num { font-family: var(--font-mono); font-size: 1.05rem; font-weight: 700; color: var(--accent); overflow-wrap: anywhere; }

.kv { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.kv th { text-align: left; font-weight: 600; color: var(--text-light); padding: 0.4rem 0.6rem 0.4rem 0; vertical-align: top; width: 34%; font-size: 0.78rem; }
.kv td { padding: 0.4rem 0; vertical-align: top; border-bottom: 1px solid var(--border); font-family: var(--font-mono); overflow-wrap: anywhere; word-break: break-word; }
.kv tr:last-child td { border-bottom: none; }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.data-table th { background: var(--bg-alt); padding: 0.45rem 0.6rem; text-align: left; font-weight: 600; color: var(--heading); border-bottom: 2px solid var(--border); white-space: nowrap; }
.data-table td { padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); font-family: var(--font-mono); vertical-align: top; }
.data-table tr.bad td { background: #fef2f2; color: var(--danger); font-weight: 600; }
.data-table tr.good td:last-child { color: var(--thm); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* --- Bloki z kodem / długimi liczbami --- */
.codebox {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  overflow-wrap: anywhere;
  word-break: break-all;
  white-space: pre-wrap;
  line-height: 1.55;
  max-height: 260px;
  overflow-y: auto;
}
.codebox.dark { background: #0f172a; color: #e2e8f0; border-color: #1e293b; }
.hl-ok { color: var(--thm); font-weight: 600; }
.hl-bad { color: var(--danger); font-weight: 600; }
.hl-dim { color: #94a3b8; }

/* --- Werdykty --- */
.verdict { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.6rem 0.8rem; border-radius: var(--radius-sm); font-size: 0.86rem; margin-top: 0.6rem; line-height: 1.5; }
.verdict .icon { font-weight: 800; font-size: 1.05rem; line-height: 1.3; }
.verdict.ok { background: var(--prf-bg); color: #065f46; border: 1px solid #a7f3d0; }
.verdict.bad { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.verdict.maybe { background: var(--num-bg); color: #92400e; border: 1px solid #fde68a; }
.verdict.na { background: var(--bg-alt); color: var(--text-light); border: 1px solid var(--border); }

/* --- Kolumny „trzech światów” --- */
.world { border-radius: var(--radius); border: 1px solid var(--border); background: white; box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.world-head { padding: 0.7rem 1rem; color: white; }
.world-head .tag { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.9; }
.world-head h3 { font-size: 1.02rem; font-weight: 700; line-height: 1.3; }
.world-body { padding: 0.9rem 1rem; font-size: 0.86rem; flex: 1; display: flex; flex-direction: column; gap: 0.5rem; min-width: 0; }
.world.num .world-head { background: var(--num); }
.world.sym .world-head { background: var(--sym); }
.world.prf .world-head { background: var(--prf); }
.world.num { border-top: none; }
.world .note { font-size: 0.78rem; color: var(--text-light); }

/* --- Panele objaśnień --- */
.explain {
  background: white;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.1rem 1.3rem;
  margin: 1.4rem 0 1.2rem;
  font-size: 0.9rem;
  line-height: 1.7;
  box-shadow: var(--shadow);
}
.explain h2 { font-size: 1.05rem; color: var(--heading); margin-bottom: 0.5rem; }
.explain p { margin-bottom: 0.6rem; }
.explain ul, .explore ul, .explore ol { padding-left: 1.3rem; }
.explain li { margin-bottom: 0.3rem; }
.explain .katex-display { margin: 0.6rem 0; overflow-x: auto; overflow-y: hidden; }

.explore {
  background: var(--num-bg);
  border: 1px dashed #f59e0b;
  border-radius: var(--radius);
  padding: 1rem 1.3rem;
  margin-bottom: 1.2rem;
  font-size: 0.9rem;
}
.explore h2 { font-size: 1rem; color: #92400e; margin-bottom: 0.5rem; }
.explore li { margin-bottom: 0.35rem; }

.description {
  margin-bottom: 1.3rem;
  padding: 0.9rem 1.2rem;
  background: white;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--text);
}
.description strong { color: var(--heading); }

.lesson {
  margin-top: 0.7rem;
  padding: 0.55rem 0.8rem;
  background: var(--sym-bg);
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  color: #3730a3;
}
.lesson::before { content: "Lekcja: "; font-weight: 700; }

/* --- Stopka strony apletu --- */
.page-footer {
  margin-top: 1.5rem;
  padding: 1.2rem 0 0.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-light);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-footer a { color: var(--accent); font-weight: 600; text-decoration: none; }
.page-footer a:hover { text-decoration: underline; }

/* --- Pasek stanu --- */
.status-bar { display: flex; align-items: center; gap: 0.8rem; padding: 0.5rem 1rem; background: var(--bg-alt); border-radius: var(--radius-sm); font-size: 0.78rem; color: var(--text-light); margin-top: 0.8rem; }
.status-bar .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--thm); }
.status-bar .dot.running { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* --- Zakładki --- */
.tab-bar { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tab-btn {
  padding: 0.55rem 1rem;
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-btn.num.active { color: #b45309; border-bottom-color: var(--num); }
.tab-btn.sym.active { color: var(--sym); border-bottom-color: var(--sym); }
.tab-btn.prf.active { color: var(--prf); border-bottom-color: var(--prf); }

/* --- Galeria (index.html) --- */
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.2rem; }
.gallery-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-decoration: none;
  color: inherit;
  transition: all 0.2s;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.gallery-card:hover { box-shadow: var(--shadow-lg); border-color: var(--accent); transform: translateY(-2px); }
.gallery-card .card-icon { width: 48px; height: 48px; background: var(--accent-light); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; margin-bottom: 1rem; }
.gallery-card .card-icon.num { background: var(--num-soft); }
.gallery-card .card-icon.prf { background: var(--prf-soft); }
.gallery-card h3 { font-size: 1.05rem; font-weight: 700; color: var(--heading); margin-bottom: 0.4rem; }
.gallery-card p { font-size: 0.85rem; color: var(--text-light); line-height: 1.5; flex: 1; }
.gallery-card .card-chapter { margin-top: 0.8rem; font-size: 0.75rem; color: var(--accent); font-weight: 600; }
.worlds-tags { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-top: 0.7rem; }
.wtag { font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; padding: 0.12rem 0.5rem; border-radius: 999px; }
.wtag.num { background: var(--num-soft); color: #b45309; }
.wtag.sym { background: var(--sym-soft); color: var(--sym); }
.wtag.prf { background: var(--prf-soft); color: var(--prf); }

/* --- Responsywność --- */
@media (max-width: 720px) {
  .nav-bar { padding: 0.5rem 0.9rem; gap: 0.6rem; }
  .nav-title { display: none; }
  .nav-links { gap: 0.75rem; }
  .nav-bar a { font-size: 0.78rem; }
}
@media (max-width: 600px) {
  .page-container { padding: 1rem; }
  .page-header h1 { font-size: 1.4rem; }
  .gallery-grid { grid-template-columns: 1fr; }
  .panel { padding: 0.9rem; }
  .explain, .explore { padding: 0.9rem 1rem; }
}
@media (max-width: 420px) {
  .nav-links.right a.hide-sm { display: none; }
}
