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

/* Home navigation */
.home-link {
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 100;
    opacity: 0.8;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    padding: 0.55rem 0.8rem;
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.9);
    color: #1f2937;
    font-weight: 700;
}

.home-link:hover {
    opacity: 1;
    transform: scale(1.1);
}

.alternate-link {
    margin-top: 0.4rem;
    font-size: 0.9rem;
}

.alternate-link a {
    color: white;
    text-underline-offset: 0.2rem;
}

body {
    font-family:
        "SF Mono", "Monaco", "Cascadia Code", "Roboto Mono", Consolas,
        "Courier New", monospace;
    background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
    color: #333;
    line-height: 1.4;
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    margin-bottom: 1.5rem;
    color: white;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    font-weight: 300;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

.main-content {
    flex: 1;
    display: grid;
    grid-template-columns: 300px 1fr 280px;
    gap: 1rem;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
}

/* Navigation Panel */
.nav-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.current-fraction h2 {
    font-size: 2rem;
    text-align: center;
    color: #2c3e50;
    margin-bottom: 1rem;
    padding: 1rem;
    background: linear-gradient(135deg, #ecf0f1 0%, #bdc3c7 100%);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.fraction-info {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 1rem;
}

.info-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.info-item label {
    font-weight: bold;
    color: #34495e;
}

.info-item span {
    color: #2c3e50;
    font-family: monospace;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.3;
}

.display-mode {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 1rem;
}

.display-mode label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
    color: #34495e;
}

.display-mode select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #bdc3c7;
    border-radius: 4px;
    background: white;
    font-family: inherit;
}

.navigation-controls {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    gap: 0.5rem;
}

.child-controls {
    display: flex;
    gap: 0.5rem;
}

.nav-btn {
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 6px;
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    color: white;
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.nav-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.nav-btn:active {
    transform: translateY(0);
}

.nav-btn.reset {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
}

.nav-btn:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.nav-btn.left-child {
    background: linear-gradient(135deg, #27ae60 0%, #229954 100%);
}

.nav-btn.right-child {
    background: linear-gradient(135deg, #9b59b6 0%, #8e44ad 100%);
}

.nav-btn.parent {
    background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
}

.notation-toggle {
    padding: 0.3rem 0.6rem;
    border: none;
    border-radius: 4px;
    background: linear-gradient(135deg, #8e44ad 0%, #9b59b6 100%);
    color: white;
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-left: 1rem;
    vertical-align: middle;
}

.notation-toggle:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.notation-toggle:active {
    transform: translateY(0);
}

.constant-buttons {
    margin-top: 1rem;
    padding: 0.75rem;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #e9ecef;
}

.constant-buttons label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
    color: #34495e;
    font-size: 0.9rem;
}

.constant-button-row {
    display: flex;
    gap: 0.5rem;
    justify-content: space-between;
}

.constant-btn {
    flex: 1;
    padding: 0.5rem;
    border: none;
    border-radius: 4px;
    background: linear-gradient(135deg, #e67e22 0%, #d35400 100%);
    color: white;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.constant-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.constant-btn:active {
    transform: translateY(0);
}

.expression-calculator {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 1rem;
    border: 2px solid #e3f2fd;
}

.expression-calculator label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
    color: #34495e;
}

.expression-calculator input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #bdc3c7;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    font-family: "SF Mono", Monaco, "Cascadia Code", monospace;
    font-size: 0.9rem;
}

.expression-calculator input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.expression-examples {
    background: rgba(52, 152, 219, 0.1);
    padding: 0.5rem;
    border-radius: 4px;
    border-left: 3px solid #3498db;
}

.display-mode-buttons {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.display-mode-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.85rem;
    background: #E9ECEF;
    border: 1px solid #CED4DA;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.display-mode-btn:hover {
    background: #DEE2E6;
}

.display-mode-btn.active {
    background: #007BFF;
    color: white;
    border-color: #0056B3;
}

.display-mode-btn.active:hover {
    background: #0056B3;
}

.precision-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.precision-control input {
    padding: 0.25rem 0.5rem;
    border: 1px solid #CED4DA;
    border-radius: 4px;
    font-family: monospace;
}

.jump-controls {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 1rem;
}

.jump-controls label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
    color: #34495e;
}

.jump-controls input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #bdc3c7;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    font-family: inherit;
}

/* Tree Container */
.tree-container {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 1rem;
    overflow: hidden;
    position: relative;
}

#treeSvg {
    width: 100%;
    height: 500px;
    border: 1px solid #e5e5e5;
    border-radius: 4px;
    background: white;
}

/* SVG Styles */
.tree-container {
    transition: transform 0.3s ease-out;
}

.tree-node {
    cursor: pointer;
    transition: all 0.3s ease;
}

.tree-node rect {
    fill: #3498db;
    stroke: #2980b9;
    stroke-width: 2;
}

.tree-node.current rect {
    fill: #e74c3c;
    stroke: #c0392b;
    stroke-width: 3;
}

.tree-node.parent rect {
    fill: #f39c12;
    stroke: #e67e22;
}

.tree-node.ancestor rect {
    fill: #f1c40f;
    stroke: #f4d03f;
}

.tree-node.child rect {
    fill: #27ae60;
    stroke: #229954;
}

.tree-node.left-child rect {
    fill: #27ae60;
    stroke: #229954;
}

.tree-node.right-child rect {
    fill: #9b59b6;
    stroke: #8e44ad;
}

.tree-node.descendant rect {
    fill: #85c1e9;
    stroke: #5dade2;
}

.tree-node.sibling rect {
    fill: #bdc3c7;
    stroke: #95a5a6;
    opacity: 0.7;
}

.tree-node.sibling text {
    fill: black;
    opacity: 0.8;
}

.tree-node.current-sibling rect {
    fill: #e67e22;
    stroke: #d68910;
    opacity: 0.6;
}

.tree-node.current-sibling text {
    fill: black;
    opacity: 0.9;
}

.tree-node:hover rect {
    fill: #3498db !important;
    stroke: #2980b9 !important;
}

.tree-node text {
    fill: black;
    font-family: inherit;
    /*font-size: 14px;*/
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
    font-weight: 500;
}

.tree-edge {
    stroke: #7f8c8d;
    stroke-width: 2;
    fill: none;
}

.tree-edge.current {
    stroke: #e74c3c;
    stroke-width: 3;
}

/* Info Panel */
.info-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.info-panel > div {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 1rem;
}

.info-panel h3 {
    color: #2c3e50;
    margin-bottom: 0.75rem;
    font-size: 1rem;
    border-bottom: 2px solid #3498db;
    padding-bottom: 0.5rem;
}

.breadcrumb {
    display: inline-block;
    background: #3498db;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    margin: 0.125rem;
    font-size: 0.8rem;
}

.breadcrumb.current {
    background: #e74c3c;
}

.breadcrumb.left-direction {
    background: #27ae60;
    color: white;
}

.breadcrumb.right-direction {
    background: #9b59b6;
    color: white;
}

.clickable-breadcrumb {
    cursor: pointer;
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.clickable-breadcrumb:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#mediantCalculation,
#continuedFraction,
#fareyInfo {
    font-family: monospace;
    background: white;
    padding: 0.75rem;
    border-radius: 4px;
    border: 1px solid #e5e5e5;
    margin-top: 0.5rem;
    min-height: 3rem;
    font-size: 0.9rem;
    line-height: 1.4;
}

.help-text {
    margin-top: 1rem;
    text-align: center;
    color: white;
    opacity: 0.9;
    font-size: 0.9rem;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 280px 1fr 260px;
    }
}

@media (max-width: 1000px) {
    .main-content {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
    }

    .nav-panel {
        order: 1;
    }

    .tree-container {
        order: 2;
    }

    .info-panel {
        order: 3;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .info-panel > div {
        flex: 1;
        min-width: 200px;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 0.5rem;
    }

    header h1 {
        font-size: 2rem;
    }

    .main-content {
        padding: 1rem;
    }

    .child-controls {
        flex-direction: column;
    }

    .info-panel {
        flex-direction: column;
    }

    #treeSvg {
        height: 400px;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.5rem;
    }

    .current-fraction h2 {
        font-size: 1.5rem;
    }

    #treeSvg {
        height: 300px;
    }
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 0;
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    color: white;
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
}

.close {
    color: white;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.close:hover,
.close:focus {
    opacity: 1;
}

.modal-body {
    padding: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
}

/* Convergents Table Styles */
.convergents-table {
    width: 100%;
    border-collapse: collapse;
    font-family: monospace;
    font-size: 0.9rem;
}

.convergents-table th,
.convergents-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #dee2e6;
}

.convergents-table th {
    background: #f8f9fa;
    font-weight: bold;
    color: #495057;
    border-bottom: 2px solid #dee2e6;
}

.convergents-table tr:hover {
    background: #f8f9fa;
}

.convergents-table .current-row {
    background: #e74c3c;
    color: white;
}

.convergents-table .current-row:hover {
    background: #c0392b;
}

.convergents-table .fraction-cell {
    font-weight: bold;
}

.convergents-table .decimal-cell {
    font-family: monospace;
    color: #6c757d;
}

.convergents-table .distance-cell {
    font-family: monospace;
    color: #28a745;
    font-size: 0.8rem;
}

.convergents-table .action-cell {
    text-align: center;
}

.nav-convergent {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-convergent:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.current-row .nav-convergent {
    background: #95a5a6;
    cursor: not-allowed;
}

.convergent-item {
    display: inline-block;
    background: #ecf0f1;
    border: 1px solid #bdc3c7;
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    margin: 0.25rem;
    font-family: monospace;
    font-size: 0.9rem;
    transition: background-color 0.2s;
}

.convergent-item:hover {
    background: #d5dbdb;
}

.convergent-item.current {
    background: #e74c3c;
    color: white;
    border-color: #c0392b;
}

.more-link {
    color: #3498db;
    cursor: pointer;
    text-decoration: underline;
    font-weight: bold;
    display: inline-block;
    margin: 0.25rem;
    padding: 0.5rem;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.more-link:hover {
    background: #ebf3fd;
}

.farey-item {
    display: inline-block;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 0.4rem 0.6rem;
    margin: 0.2rem;
    font-family: monospace;
    font-size: 0.85rem;
    transition: background-color 0.2s;
}

.farey-item:hover {
    background: #e9ecef;
}

.farey-item.current {
    background: #e74c3c;
    color: white;
    border-color: #c0392b;
    font-weight: bold;
}

/* 2D Fraction Styles */
.fraction-2d {
    display: inline-block;
    text-align: center;
    vertical-align: middle;
    line-height: 1;
    margin: 0 0.25rem;
}

.fraction-2d .numerator {
    font-size: 0.9em;
    margin-bottom: 4px;
    font-weight: bold;
}

.fraction-2d .fraction-bar {
    border-top: 2px solid currentColor;
    margin: 2px 0;
    width: 100%;
}

.fraction-2d .denominator {
    font-size: 0.9em;
    margin-top: 4px;
    font-weight: bold;
}

/* Boundaries Layout */
.boundaries-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.left-boundary {
    text-align: left;
}

.right-boundary {
    text-align: right;
}

.current-boundary {
    text-align: center;
    font-weight: bold;
    color: #e74c3c;
    margin-top: 0.25rem;
}

/* Boundary display - fixed position at top of tree container */
.boundary-display {
    position: absolute;
    top: 1rem;
    left: 0;
    right: 0;
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0;
    z-index: 10;
    pointer-events: none;
    background-color: white;
}

.boundary-display > div {
    background: rgba(52, 73, 94, 0.95);
    border: 2px solid #3498db;
    border-radius: 8px;
    padding: 0.5rem 1rem;
    color: #ecf0f1;
    font-weight: bold;
    text-align: center;
    cursor: pointer;
    pointer-events: auto;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.boundary-display > div:hover {
    transform: scale(1.05);
    background: rgba(52, 73, 94, 1);
    border-color: #2ecc71;
}

.boundary-display .fraction-2d {
    display: inline-block;
    vertical-align: middle;
}

.boundary-display .fraction-2d .numerator,
.boundary-display .fraction-2d .denominator {
    text-align: center;
    line-height: 1;
}

.boundary-display .fraction-2d .fraction-bar {
    height: 2px;
    background: currentColor;
    margin: 2px 0;
}
