/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --accent: #f59e0b;
  --bg: #f0f4ff;
  --surface: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --border: #e2e8f0;
  --radius: 16px;
  --shadow: 0 4px 24px rgba(37, 99, 235, 0.1);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ===== Header ===== */
header {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 60%, #3b82f6 100%);
  color: #fff;
  padding: 48px 24px 40px;
  text-align: center;
}

.header-inner { max-width: 700px; margin: 0 auto; }

.apple-icon {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 12px;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}

header h1 { font-size: clamp(28px, 6vw, 48px); font-weight: 800; letter-spacing: -1px; }
.subtitle { margin-top: 8px; font-size: 16px; opacity: 0.8; }

/* ===== Tab navigation ===== */
.tab-nav {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 20px 16px;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

.tab-btn {
  padding: 10px 28px;
  border: 2px solid var(--border);
  border-radius: 50px;
  background: transparent;
  color: var(--text-light);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.tab-btn:hover { border-color: var(--primary); color: var(--primary); }
.tab-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

/* ===== Main layout ===== */
main { max-width: 900px; margin: 0 auto; padding: 32px 16px; }

.law-section { display: none; flex-direction: column; gap: 24px; }
.law-section.active { display: flex; }

/* ===== Law card ===== */
.law-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  border-left: 6px solid var(--primary);
  position: relative;
  overflow: hidden;
}

.law-number {
  position: absolute;
  top: -10px;
  right: 20px;
  font-size: 100px;
  font-weight: 900;
  color: var(--primary);
  opacity: 0.06;
  line-height: 1;
  user-select: none;
}

.law-card h2 { font-size: 24px; margin-bottom: 16px; color: var(--primary); }

blockquote {
  border-left: 4px solid var(--accent);
  padding: 12px 20px;
  background: #fffbeb;
  border-radius: 0 8px 8px 0;
  font-style: italic;
  font-size: 17px;
  line-height: 1.6;
  color: #78350f;
  margin-bottom: 16px;
}

.formula-box {
  text-align: center;
  padding: 16px;
  background: linear-gradient(135deg, #eff6ff, #dbeafe);
  border-radius: 12px;
  margin: 16px 0;
}
.formula { font-size: 28px; font-weight: 700; color: var(--primary); letter-spacing: 2px; }

.law-explanation { color: var(--text-light); line-height: 1.7; }

/* ===== Demo card ===== */
.demo-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.demo-card h3 { font-size: 18px; margin-bottom: 8px; }
.demo-hint { font-size: 14px; color: var(--text-light); margin-bottom: 20px; }

/* ===== Demo 1: sliding block ===== */
.demo-area {
  position: relative;
  height: 80px;
  background: #f8fafc;
  border-radius: 12px;
  border: 2px solid var(--border);
  overflow: hidden;
  margin-bottom: 20px;
}

.surface {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 6px;
  background: repeating-linear-gradient(90deg, #94a3b8 0 8px, #cbd5e1 8px 16px);
  border-radius: 0 0 10px 10px;
}

.block {
  position: absolute;
  bottom: 6px;
  left: 20px;
  font-size: 36px;
  line-height: 1;
  transition: left 0s linear;
  cursor: default;
  user-select: none;
}

/* ===== Controls ===== */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.controls label {
  font-size: 14px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.controls select, .controls input[type="range"] { cursor: pointer; }

.btn {
  padding: 10px 22px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 50px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: scale(0.97); }
.btn.secondary { background: var(--border); color: var(--text); }
.btn.secondary:hover { background: #cbd5e1; }

.demo-result {
  min-height: 24px;
  font-size: 14px;
  color: var(--primary);
  font-weight: 600;
  padding: 4px 0;
}

/* ===== Calculator (Law 2) ===== */
.calc-grid {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.calc-field { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 100px; }
.calc-field label { font-size: 13px; color: var(--text-light); font-weight: 500; }
.calc-field input {
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 18px;
  text-align: center;
  transition: border-color 0.2s;
  width: 100%;
}
.calc-field input:focus { outline: none; border-color: var(--primary); }
.calc-field input.highlighted { background: #eff6ff; border-color: var(--primary); }
.calc-eq, .calc-dot { font-size: 24px; font-weight: 700; padding-bottom: 10px; color: var(--text-light); }

/* ===== Bar chart ===== */
.bar-demo { margin-top: 28px; }
.bar-demo h4 { font-size: 14px; color: var(--text-light); margin-bottom: 14px; }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-label { width: 70px; font-size: 13px; color: var(--text-light); text-align: right; flex-shrink: 0; }
.bar-track { flex: 1; background: #f1f5f9; border-radius: 50px; height: 30px; overflow: hidden; }
.bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #60a5fa);
  border-radius: 50px;
  display: flex;
  align-items: center;
  padding-left: 12px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  min-width: 60px;
  transition: width 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ===== Demo 3: carts ===== */
#demo3-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  height: 80px;
  background: #f8fafc;
  border-radius: 12px;
  border: 2px solid var(--border);
  padding: 0 12px;
  overflow: hidden;
  margin-bottom: 20px;
  position: relative;
}

.cart {
  font-size: 28px;
  font-weight: 700;
  user-select: none;
  transition: transform 0.05s linear;
  white-space: nowrap;
}
.left-cart { margin-right: 4px; }
.right-cart { margin-left: 4px; }

.spring {
  font-size: 22px;
  color: var(--accent);
  user-select: none;
  transition: transform 0.15s;
}

#demo3-area .controls label { display: flex; align-items: center; gap: 8px; font-size: 14px; }

/* ===== Examples section ===== */
.examples-section {
  max-width: 900px;
  margin: 0 auto 40px;
  padding: 0 16px;
}
.examples-section h2 { font-size: 22px; margin-bottom: 20px; }
.examples-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }

.example-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow);
  text-align: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
.example-card:hover { transform: translateY(-4px); box-shadow: 0 8px 30px rgba(37,99,235,0.15); }
.example-icon { font-size: 40px; margin-bottom: 12px; }
.example-card h4 { font-size: 15px; margin-bottom: 8px; }
.example-card p { font-size: 13px; color: var(--text-light); line-height: 1.6; }

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 24px 16px;
  font-size: 14px;
  color: var(--text-light);
  border-top: 1px solid var(--border);
}

/* ===== Responsive ===== */
@media (max-width: 500px) {
  .calc-grid { gap: 6px; }
  .calc-eq, .calc-dot { display: none; }
  .tab-btn { padding: 8px 16px; font-size: 14px; }
}
