* {
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
}

body {
    font-family: 'Roboto', sans-serif;
    background-color: #f4f4f9;
    color: #333;
    margin: 0;
    padding: 20px;
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    line-height: 1.6;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

.page {
    max-width: 900px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    color: #2c3e50;
    margin-bottom: 0.5rem;
}

header p {
    color: #555;
    font-size: 1.1rem;
}

section {
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    padding: 24px;
    margin-bottom: 24px;
}

section h2 {
    color: #2c3e50;
    margin-top: 0;
    border-bottom: 2px solid #007bff;
    padding-bottom: 8px;
}

section h3 {
    color: #4a4a4a;
    margin-top: 1.5rem;
}

.pros-cons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 1rem;
}

@media (max-width: 600px) {
    .pros-cons {
        grid-template-columns: 1fr;
    }
}

.pros-cons ul {
    margin: 0.5rem 0 0;
    padding-left: 1.25rem;
}

.pros-cons li {
    margin-bottom: 0.25rem;
}

.gear-uses {
    margin: 0.75rem 0 0;
    font-size: 0.95rem;
    color: #555;
}

.gear-uses strong {
    color: #2c3e50;
}

.ratio-formula {
    background: #f0f4f8;
    border-left: 4px solid #007bff;
    padding: 12px 16px;
    margin: 1rem 0;
    font-family: 'Courier New', monospace;
    font-size: 0.95rem;
}

.demo-card {
    margin-top: 1.5rem;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    background: #fafafa;
}

.canvas-wrap {
    position: relative;
    width: 100%;
    min-height: 180px;
    aspect-ratio: 16 / 10;
    max-height: min(56vh, 520px);
    background: #1a1a2e;
    overflow: hidden;
}

.canvas-wrap canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: pan-y;
}

.demo-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 16px;
    background: #eee;
    border-top: 1px solid #ddd;
}

.param-controls,
.playback-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.param-controls {
    padding-bottom: 10px;
    border-bottom: 1px solid #ddd;
}

.param-controls label {
    min-width: 180px;
}

.param-controls input[type="range"] {
    width: 140px;
}

.playback-controls {
    width: 100%;
}

.demo-controls button {
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 8px 16px;
    min-height: 44px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s;
    touch-action: manipulation;
}

.demo-controls button:hover {
    background-color: #0056b3;
}

.demo-controls button.paused {
    background-color: #28a745;
}

.demo-controls label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
}

.demo-controls input[type="range"] {
    width: 120px;
}

.ratio-readout {
    margin-left: auto;
    font-weight: 700;
    color: #2c3e50;
    font-size: 0.85rem;
    text-align: right;
    max-width: 62%;
    line-height: 1.35;
}

.contact-readout {
    font-size: 0.85rem;
    color: #555;
    font-weight: 600;
}

.fidelity-toggle {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 1rem;
    padding: 6px;
    background: #e8eef5;
    border-radius: 8px;
    max-width: 100%;
}

.overlay-label {
    margin-left: 12px;
}

.fidelity-label {
    font-size: 0.9rem;
    color: #555;
    margin-right: 4px;
}

.fidelity-btn {
    background: white;
    border: 1px solid #ccc;
    border-radius: 5px;
    padding: 8px 14px;
    min-height: 44px;
    cursor: pointer;
    font-size: 0.9rem;
    color: #333;
    transition: background-color 0.2s, border-color 0.2s;
    touch-action: manipulation;
}

.fidelity-btn:hover {
    border-color: #007bff;
}

.fidelity-btn.active {
    background: #007bff;
    border-color: #007bff;
    color: white;
}

.variant-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding-bottom: 10px;
    border-bottom: 1px solid #ddd;
}

.cycloidal-variant {
    width: 100%;
}

.fidelity-note {
    max-width: 720px;
    margin: 1rem auto 0;
    font-size: 0.92rem;
    color: #555;
    text-align: left;
}

.demo-controls button.step-btn {
    background-color: #6c757d;
}

.demo-controls button.step-btn:hover {
    background-color: #545b62;
}

@media (max-width: 600px) {
    body {
        padding: 12px;
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }

    section {
        padding: 16px;
    }

    header p {
        font-size: 1rem;
    }

    .fidelity-note {
        font-size: 0.88rem;
    }

    .param-controls,
    .playback-controls,
    .variant-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .param-controls label,
    .playback-controls label {
        min-width: 0;
        width: 100%;
        justify-content: space-between;
    }

    .param-controls input[type="range"],
    .demo-controls input[type="range"],
    .playback-controls input[type="range"] {
        flex: 1;
        width: auto;
        min-width: 0;
        min-height: 32px;
    }

    .ratio-readout,
    .contact-readout {
        margin-left: 0;
        max-width: none;
        width: 100%;
        text-align: left;
    }

    .demo-controls button {
        width: 100%;
    }

    .playback-controls .play-btn,
    .playback-controls .step-btn {
        width: auto;
        flex: 1;
    }

    .playback-controls {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .cycloidal-variant {
        gap: 6px;
    }

    .ratio-formula {
        font-size: 0.82rem;
        overflow-x: auto;
    }
}

.harmonic-watch {
    background: #f0f4f8;
    border-left: 4px solid #e8a838;
    padding: 10px 14px;
    margin: 0.75rem 0 0;
    font-size: 0.95rem;
}

.robot-examples {
    margin-top: 1.25rem;
    padding: 14px 16px;
    background: #f8f9fb;
    border: 1px solid #e0e4ea;
    border-radius: 6px;
}

.robot-examples h3 {
    margin: 0 0 0.5rem;
    font-size: 1rem;
    color: #2c3e50;
}

.robot-examples ul {
    margin: 0;
    padding-left: 1.25rem;
}

.robot-examples li {
    margin-bottom: 0.45rem;
}

.robot-examples a {
    color: #0056b3;
    text-decoration: none;
}

.robot-examples a:hover {
    text-decoration: underline;
}

.robot-examples .note {
    color: #555;
}

.site-nav {
    font-size: 0.9rem;
    margin: 0 0 0.75rem;
}

.site-nav a {
    color: #0056b3;
    text-decoration: none;
}

.site-nav a:hover {
    text-decoration: underline;
}

.site-footer {
    text-align: center;
    color: #666;
    font-size: 0.95rem;
    margin-top: 0.5rem;
    padding: 0 0 1rem;
}

.site-footer a {
    color: #0056b3;
    text-decoration: none;
}

.site-footer a:hover {
    text-decoration: underline;
}
