:root {
  --bg-primary: #120e0b;
  --bg-secondary: #1a1410;
  --bg-tertiary: #251b14;
  --bg-card: #201712;
  --brass-bright: #f0c978;
  --brass-main: #d4a34b;
  --brass-dark: #8c6227;
  --brass-shadow: #4d3311;
  --copper: #c86d51;
  --bronze: #a77b5a;
  --iron: #3a322c;
  --iron-dark: #1e1916;
  --steel: #7d8489;
  --paper: #f4ebd9;
  --paper-dark: #e5d8bf;
  --paper-text: #2a2015;
  --accent-cyan: #5ec2c6;
  --text-main: #ecdcc9;
  --text-muted: #a39281;
  --border-brass: rgba(212, 163, 75, 0.4);
  --shadow-warm: 0 10px 30px rgba(0, 0, 0, 0.6), 0 0 20px rgba(212, 163, 75, 0.15);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(ellipse at 50% 0%, rgba(212, 163, 75, 0.15) 0%, transparent 70%),
    radial-gradient(circle at 80% 80%, rgba(200, 109, 81, 0.08) 0%, transparent 50%),
    linear-gradient(rgba(18, 14, 11, 0.94), rgba(18, 14, 11, 0.94)),
    repeating-linear-gradient(0deg, transparent, transparent 40px, rgba(212, 163, 75, 0.03) 40px, rgba(212, 163, 75, 0.03) 41px),
    repeating-linear-gradient(90deg, transparent, transparent 40px, rgba(212, 163, 75, 0.03) 40px, rgba(212, 163, 75, 0.03) 41px);
  color: var(--text-main);
  font-family: 'JetBrains Mono', monospace;
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}
::-webkit-scrollbar-thumb {
  background: var(--brass-dark);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--brass-main);
}

/* Layout container */
.app-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 3rem;
  width: 100%;
}

/* Header & Brass Rivets */
.victorian-header {
  position: relative;
  background: linear-gradient(180deg, #2b1f17 0%, #1a130f 100%);
  border: 2px solid var(--brass-main);
  border-radius: 12px;
  padding: 1.5rem 2rem;
  margin-bottom: 1.75rem;
  box-shadow: var(--shadow-warm), inset 0 0 25px rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.5rem;
}

.rivet-corner {
  position: absolute;
  width: 12px;
  height: 12px;
  background: radial-gradient(circle, var(--brass-bright) 20%, var(--brass-dark) 80%);
  border-radius: 50%;
  border: 1px solid #1a1005;
  box-shadow: 1px 1px 3px rgba(0,0,0,0.8), inset -1px -1px 2px rgba(0,0,0,0.5);
}
.rivet-tl { top: 8px; left: 8px; }
.rivet-tr { top: 8px; right: 8px; }
.rivet-bl { bottom: 8px; left: 8px; }
.rivet-br { bottom: 8px; right: 8px; }

.title-group h1 {
  font-family: 'Cinzel', serif;
  font-size: 2.1rem;
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--brass-bright);
  text-shadow: 0 2px 4px rgba(0,0,0,0.8), 0 0 15px rgba(240, 201, 120, 0.4);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.title-group p {
  font-family: 'IM Fell English', serif;
  font-style: italic;
  color: var(--text-muted);
  font-size: 1.1rem;
  margin-top: 0.2rem;
}

/* Status Gauge and Sound Toggle */
.header-controls {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.brass-pill-btn {
  background: linear-gradient(180deg, #3d2d1f 0%, #201710 100%);
  border: 1px solid var(--brass-main);
  color: var(--brass-bright);
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-family: 'JetBrains Mono', monospace;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  box-shadow: 0 4px 8px rgba(0,0,0,0.4), inset 0 1px 1px rgba(240,201,120,0.3);
  transition: all 0.2s ease;
}

.brass-pill-btn:hover {
  background: linear-gradient(180deg, #4d3a28 0%, #291e15 100%);
  border-color: var(--brass-bright);
  transform: translateY(-1px);
  box-shadow: 0 6px 12px rgba(0,0,0,0.6), 0 0 10px rgba(212,163,75,0.3);
}

.brass-pill-btn:active {
  transform: translateY(1px);
}

/* Tabs */
.nav-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--iron);
  padding-bottom: 0.5rem;
  overflow-x: auto;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  font-weight: 700;
  padding: 0.6rem 1.25rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--brass-bright);
}

.tab-btn.active {
  color: var(--brass-bright);
  border-bottom: 3px solid var(--brass-bright);
  text-shadow: 0 0 10px rgba(240, 201, 120, 0.5);
}

/* Main Grid Layout */
.engine-layout {
  display: grid;
  grid-template-columns: 340px 1fr 340px;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 1200px) {
  .engine-layout {
    grid-template-columns: 320px 1fr;
  }
  .engine-output-col {
    grid-column: span 2;
  }
}

@media (max-width: 860px) {
  .engine-layout {
    grid-template-columns: 1fr;
  }
  .engine-output-col {
    grid-column: span 1;
  }
}

/* Victorian Brass Card Frame */
.brass-panel {
  background: linear-gradient(145deg, #1f1712 0%, #15100d 100%);
  border: 1.5px solid var(--brass-dark);
  border-radius: 8px;
  padding: 1.25rem;
  position: relative;
  box-shadow: 0 6px 16px rgba(0,0,0,0.5), inset 0 0 15px rgba(0,0,0,0.5);
  margin-bottom: 1.5rem;
}

.brass-panel::before {
  content: '';
  position: absolute;
  top: 3px; left: 3px; right: 3px; bottom: 3px;
  border: 1px dashed rgba(212, 163, 75, 0.2);
  border-radius: 5px;
  pointer-events: none;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(212, 163, 75, 0.2);
}

.panel-header h2 {
  font-family: 'Cinzel', serif;
  font-size: 1.15rem;
  color: var(--brass-bright);
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Preset Cards */
.preset-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
}

.preset-card {
  background: rgba(30, 23, 18, 0.7);
  border: 1px solid rgba(212, 163, 75, 0.25);
  border-radius: 6px;
  padding: 0.75rem;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.preset-card:hover {
  border-color: var(--brass-main);
  background: rgba(45, 33, 24, 0.9);
  transform: translateX(3px);
}

.preset-card.active {
  border-color: var(--brass-bright);
  background: linear-gradient(90deg, rgba(212, 163, 75, 0.2) 0%, rgba(30, 23, 18, 0.8) 100%);
  box-shadow: 0 0 12px rgba(212, 163, 75, 0.2);
}

.preset-name {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--brass-bright);
}

.preset-formula {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  color: var(--copper);
}

.preset-desc {
  font-family: 'IM Fell English', serif;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Form Controls */
.control-group {
  margin-bottom: 1rem;
}

.control-label {
  display: block;
  font-size: 0.8rem;
  color: var(--brass-main);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 0.4rem;
}

.victorian-input, .victorian-select {
  width: 100%;
  background: #110c09;
  border: 1px solid var(--brass-dark);
  color: var(--brass-bright);
  padding: 0.6rem 0.8rem;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.victorian-input:focus, .victorian-select:focus {
  border-color: var(--brass-bright);
  box-shadow: 0 0 8px rgba(240, 201, 120, 0.3);
}

/* Polynomial Coefficient Inputs */
.poly-inputs-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.poly-deg-tag {
  background: var(--iron);
  color: var(--brass-bright);
  padding: 0.3rem 0.5rem;
  border-radius: 3px;
  font-size: 0.8rem;
  min-width: 55px;
  text-align: center;
}

/* Steampunk Mechanical Crank & Action Buttons */
.crank-control-box {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
  padding: 1.25rem;
  background: radial-gradient(circle at 50% 50%, #2c2016 0%, #17110d 100%);
  border: 2px solid var(--brass-main);
  border-radius: 12px;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.8), 0 8px 20px rgba(0,0,0,0.4);
}

.crank-wheel-btn {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: radial-gradient(circle, #f0c978 0%, #c4933d 40%, #5a3f1b 80%, #2b1c0b 100%);
  border: 4px solid #f9df9e;
  box-shadow: 0 10px 20px rgba(0,0,0,0.6), inset 0 2px 6px rgba(255,255,255,0.6), 0 0 25px rgba(212,163,75,0.4);
  cursor: pointer;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #1a1005;
  font-family: 'Cinzel', serif;
  font-weight: 900;
  transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.crank-wheel-btn:hover {
  transform: scale(1.05) rotate(15deg);
  box-shadow: 0 12px 25px rgba(0,0,0,0.8), 0 0 30px rgba(240,201,120,0.6);
}

.crank-wheel-btn:active {
  transform: scale(0.96) rotate(60deg);
}

.crank-handle-peg {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 22px;
  height: 22px;
  background: radial-gradient(circle, #553311 0%, #1a1005 100%);
  border: 2px solid #ecdcc9;
  border-radius: 50%;
  box-shadow: 2px 2px 5px rgba(0,0,0,0.8);
}

.crank-label {
  font-size: 0.8rem;
  letter-spacing: 1px;
  margin-top: 4px;
  text-transform: uppercase;
}

.engine-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  width: 100%;
}

.action-btn {
  padding: 0.65rem;
  border-radius: 6px;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--brass-main);
  transition: all 0.2s;
}

.btn-primary {
  background: linear-gradient(180deg, #d4a34b 0%, #8c6227 100%);
  color: #1a1005;
}
.btn-primary:hover {
  background: linear-gradient(180deg, #f0c978 0%, #a77833 100%);
  box-shadow: 0 0 12px rgba(240, 201, 120, 0.5);
}

.btn-secondary {
  background: #1f1712;
  color: var(--brass-bright);
}
.btn-secondary:hover {
  background: #33261d;
  border-color: var(--brass-bright);
}

/* Visual Difference Engine Machine Columns */
.machine-stage {
  background: #140e0b;
  border: 2px solid var(--brass-dark);
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.9), 0 4px 20px rgba(0,0,0,0.6);
  position: relative;
  overflow: hidden;
}

.columns-stage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.columns-container {
  display: flex;
  gap: 1rem;
  justify-content: center;
  align-items: flex-end;
  padding: 1rem 0 2rem;
  overflow-x: auto;
}

/* Individual Difference Column */
.diff-column-assembly {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 130px;
  position: relative;
}

.diff-col-title {
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  color: var(--brass-bright);
  margin-bottom: 0.5rem;
  text-align: center;
  white-space: nowrap;
}

.diff-col-subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.column-chassis {
  background: linear-gradient(180deg, #3d2f24 0%, #201712 50%, #150f0c 100%);
  border: 2px solid var(--brass-main);
  border-radius: 8px;
  padding: 0.75rem 0.5rem;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
  box-shadow: 0 10px 25px rgba(0,0,0,0.7), inset 0 0 15px rgba(0,0,0,0.8);
  position: relative;
}

.column-chassis::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 4px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #6e767c, #9aa2a8, #444c51);
  z-index: 1;
}

/* Brass Figure Wheels (Number Dials) */
.figure-wheel-stack {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: 100%;
  z-index: 2;
}

.figure-wheel {
  background: linear-gradient(180deg, #42301f 0%, #f0c978 45%, #d4a34b 55%, #3d2c1c 100%);
  border: 1px solid #1a1005;
  border-radius: 4px;
  padding: 0.35rem;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  box-shadow: 0 3px 6px rgba(0,0,0,0.6), inset 0 1px 2px rgba(255,255,255,0.4);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.figure-wheel.rotating {
  transform: rotateX(360deg);
}

.figure-wheel-digit {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.4rem;
  font-weight: 900;
  color: #120902;
  text-shadow: 0 1px 0 rgba(255,255,255,0.4);
}

.column-val-display {
  background: #0d0907;
  border: 1px solid var(--brass-dark);
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  width: 100%;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--brass-bright);
  letter-spacing: 1px;
  margin-top: 0.5rem;
  z-index: 2;
}

.column-operation-arrow {
  position: absolute;
  top: 40%;
  right: -14px;
  transform: translateY(-50%);
  color: var(--accent-cyan);
  font-size: 1.2rem;
  z-index: 10;
  text-shadow: 0 0 8px rgba(94, 194, 198, 0.8);
  animation: pulseArrow 1.5s infinite alternate;
}

@keyframes pulseArrow {
  0% { transform: translate(-2px, -50%); opacity: 0.5; }
  100% { transform: translate(3px, -50%); opacity: 1; }
}

/* Mechanical Gears Decoration */
.gear-icon-spinning {
  animation: spinGear 8s linear infinite;
}

.gear-icon-spinning-reverse {
  animation: spinGearRev 6s linear infinite;
}

@keyframes spinGear {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes spinGearRev {
  from { transform: rotate(0deg); }
  to { transform: rotate(-360deg); }
}

/* Printed Output Paper (Victorian Typeset) */
.paper-tape-container {
  background: var(--paper);
  color: var(--paper-text);
  border-radius: 4px;
  padding: 1.25rem 1rem;
  box-shadow: 0 8px 25px rgba(0,0,0,0.7), inset 0 0 30px rgba(180, 150, 100, 0.3);
  position: relative;
  max-height: 520px;
  display: flex;
  flex-direction: column;
}

.paper-tape-container::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 10px;
  background: repeating-linear-gradient(90deg, #d8ccb4, #d8ccb4 8px, #c2b59c 8px, #c2b59c 16px);
  border-bottom: 1px dashed #8b7355;
}

.paper-header {
  text-align: center;
  border-bottom: 2px double #8b7355;
  padding-bottom: 0.75rem;
  margin-bottom: 0.75rem;
}

.paper-header h3 {
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  letter-spacing: 2px;
  color: #3b2814;
}

.paper-stamp {
  font-family: 'IM Fell English', serif;
  font-style: italic;
  font-size: 0.8rem;
  color: #7d5b38;
}

.paper-table-wrapper {
  overflow-y: auto;
  flex: 1;
}

.paper-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  font-family: 'JetBrains Mono', monospace;
}

.paper-table th {
  border-bottom: 1px solid #a38c6d;
  padding: 0.4rem 0.3rem;
  text-align: right;
  font-family: 'Cinzel', serif;
  font-size: 0.75rem;
  color: #4a341e;
}

.paper-table th:first-child {
  text-align: center;
}

.paper-table td {
  padding: 0.45rem 0.3rem;
  text-align: right;
  border-bottom: 1px dotted rgba(139, 115, 85, 0.3);
  color: #2b1f13;
}

.paper-table td:first-child {
  text-align: center;
  font-weight: 700;
}

.paper-table tr.latest-row {
  background: rgba(212, 163, 75, 0.25);
  font-weight: 700;
}

/* History / Gallery / Simulator tabs */
.info-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-top: 1rem;
}

.info-card {
  background: var(--bg-card);
  border: 1px solid var(--brass-dark);
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}

.info-card h3 {
  font-family: 'Cinzel', serif;
  color: var(--brass-bright);
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.info-card p, .info-card ul {
  font-family: 'IM Fell English', serif;
  font-size: 0.95rem;
  line-height: 1.5;
  color: #d1c2af;
}

.info-card ul {
  padding-left: 1.25rem;
  margin-top: 0.5rem;
}

/* Interactive Difference Table Explorer */
.diff-matrix-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  font-size: 0.85rem;
}

.diff-matrix-table th, .diff-matrix-table td {
  border: 1px solid var(--brass-dark);
  padding: 0.6rem;
  text-align: center;
}

.diff-matrix-table th {
  background: #2b1d15;
  color: var(--brass-bright);
  font-family: 'Cinzel', serif;
}

.diff-matrix-table td.const-diff {
  background: rgba(94, 194, 198, 0.15);
  color: var(--accent-cyan);
  font-weight: 700;
}

/* Animation Phase banner */
.phase-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  background: rgba(212, 163, 75, 0.15);
  border: 1px solid var(--brass-main);
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--brass-bright);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 8px #4ade80;
}

.status-dot.cranking {
  background: #fbbf24;
  box-shadow: 0 0 8px #fbbf24;
  animation: pulseDot 0.6s infinite alternate;
}

@keyframes pulseDot {
  0% { transform: scale(0.8); }
  100% { transform: scale(1.3); }
}

/* Footer quote */
.engine-footer {
  margin-top: 2rem;
  text-align: center;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(212, 163, 75, 0.2);
}

.engine-footer p {
  font-family: 'IM Fell English', serif;
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.engine-footer .author {
  font-family: 'Cinzel', serif;
  font-style: normal;
  font-size: 0.8rem;
  color: var(--brass-main);
  margin-top: 0.3rem;
}
