:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --secondary: #ec4899;
    --bg-dark: #0f172a;
    --bg-darker: #020617;
    --card-bg: #1e293b;
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --accent: #eab308;
    --glass: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.1);
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Noto Sans JP', sans-serif;
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
}

.logo-section h1 {
    font-size: 1.8rem;
    font-weight: 900;
    color: var(--primary);
}

.btn-back {
    padding: 8px 16px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.3s;
}

.btn-back:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Simulation HUD (Bottom Left) */
.sim-hud {
    position: absolute;
    bottom: 12px;
    left: 12px;
    display: flex;
    flex-direction: row; /* Default horizontal for PC */
    flex-wrap: wrap; 
    gap: 10px;
    pointer-events: none;
    z-index: 10;
}

/* PC Circular Mode - Sidebar Layout */
@media (min-width: 769px) {
    .is-circle-layout .sim-hud {
        left: auto;
        right: 12px;
        bottom: auto;
        top: 50%;
        transform: translateY(-50%);
        flex-direction: column; /* Vertical for circle mode sidebar */
        gap: 6px;
    }
}

.hud-line {
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 4px 10px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    white-space: nowrap;
}

.hud-line span {
    font-size: 0.9rem;
    color: #fff;
    margin: 0 2px;
}

.hud-a { border-left: 3px solid var(--primary); }
.hud-b { border-left: 3px solid var(--secondary); }
.hud-extra { border-left: 3px solid var(--accent); }

@media (max-width: 768px) {
    .sim-hud {
        bottom: 12px;
        left: 12px;
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    .hud-group-b {
        display: flex;
        flex-direction: row;
        gap: 4px;
    }
    .hud-line {
        padding: 3px 8px;
        font-size: 0.7rem;
    }
    .hud-line span {
        font-size: 0.8rem;
    }
}

/* Layout Grid */
.layout-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 12px;
    flex: 1;
}

@media (max-width: 768px) {
    :root {
        font-size: 14px; /* Global downscale for rem units */
    }

    .app-container {
        padding: 8px; /* Slightly tighter */
        gap: 8px;
    }

    header {
        padding: 5px 12px;
        margin-bottom: 3px;
    }

    header h1 {
        font-size: 1.1rem !important; /* Slightly smaller title */
    }

    .layout-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
    }

    .sidebar {
        order: -1 !important;
        width: 100% !important;
    }

    .card {
        padding: 10px 12px; /* Tighter card padding */
    }

    .sidebar-header {
        margin-bottom: 10px;
        padding-bottom: 8px;
    }
    
    .sidebar-header h2 {
        font-size: 0.95rem; /* Smaller sub-header */
    }

    .mode-description {
        font-size: 0.8rem; /* Compact description */
        margin-bottom: 3px;
        line-height: 1.4;
    }

    .canvas-wrapper {
        height: 160px; /* Further reduction to keep more items visible */
    }

    .canvas-wrapper {
        width: 100%;
        height: 280px !important;
        background: var(--bg-darker);
        border-radius: 12px;
        position: relative;
        overflow: visible;
    }

    .hud-overlay {
        position: absolute !important;
        top: 5px !important;
        left: 5px !important;
        right: 5px !important;
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 2px !important;
        padding: 0 !important;
        width: auto !important;
        pointer-events: none;
        z-index: 10;
    }

    .hud-item {
        background: rgba(15, 23, 42, 0.75);
        padding: 2px 6px;
        border-radius: 3px;
        font-size: 0.7rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border: 1px solid rgba(255, 255, 255, 0.05);
        line-height: 1.2;
    }

    /* Circular Mode Specific Optimization */
    .hud-overlay.is-circle {
        right: auto !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 3px !important;
    }

    .hud-overlay.is-circle .hud-item {
        background: rgba(15, 23, 42, 0.85);
        padding: 3px 6px;
        flex-direction: column;
        align-items: flex-start;
        min-width: 60px;
        line-height: 1.1;
    }

    .hud-overlay.is-circle .hud-unit {
        display: inline; /* Restore units */
        font-size: 0.55rem;
        opacity: 0.6;
        margin-left: 2px;
    }

    .hud-label {
        font-size: 0.65rem;
        opacity: 0.8;
    }

    .hud-val {
        font-size: 0.75rem;
        font-weight: 700;
    }

    .hud-overlay.is-circle .hud-label {
        font-size: 0.55rem;
        opacity: 0.7;
    }

    .hud-overlay.is-circle .hud-val {
        font-size: 0.8rem;
    }

    .graph-tooltip {
        width: calc(100vw - 32px) !important;
        max-width: 280px !important;
        padding: 10px !important;
        font-size: 0.85rem !important;
    }

    .hud-item {
        font-size: 0.75rem;
    }

    .hud-val {
        font-size: 0.85rem;
        min-width: 2.6rem;
    }

    .control-group label {
        font-size: 0.8rem;
        margin-bottom: 2px;
    }

    .speed-value {
        font-size: 0.7rem;
        margin-top: 2px;
    }

    select {
        padding: 12px 40px 12px 15px; /* Larger touch target */
        font-size: 1rem; /* Prevent auto-zoom and improve legibility */
        background-position: right 12px center;
        background-size: 20px;
    }

    .btn {
        padding: 10px;
        font-size: 0.85rem;
    }
}

/* Simulation Area */
.main-column {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.card {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 15px 20px;
    height: auto;
    position: relative;
    overflow: hidden;
}

.card h2 {
    font-size: 1.1rem;
    color: var(--text-dim);
    margin-bottom: 15px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.canvas-wrapper {
    width: 100%;
    height: 220px;
    background: var(--bg-darker);
    border-radius: 12px;
    position: relative;
    overflow: visible;
}

.graph-tooltip {
    position: fixed;
    z-index: 9999;
    pointer-events: auto;
    background: var(--bg-dark);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 18px 16px 16px;
    width: 280px;
    box-shadow: 0 20px 50px -12px rgba(0, 0, 0, 0.8);
    color: #f8fafc;
    font-size: 0.9rem;
    line-height: 1.6;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    visibility: hidden;
}

.tooltip-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
}

.tooltip-close:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.1);
}

.graph-tooltip.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    visibility: visible;
}

.graph-tooltip.dragging {
    opacity: 0.8;
    transition: none;
    box-shadow: 0 15px 35px rgba(0,0,0,0.7);
}

.graph-tooltip .tooltip-badge {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid var(--primary);
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    margin-bottom: 8px;
    letter-spacing: 0.05em;
}

/* Color coding based on tooltip state */
.graph-tooltip.increasing .title {
    color: var(--secondary);
}

/* Graph Interaction Hint */
.graph-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(56, 189, 248, 0.3);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(56, 189, 248, 0.6);
    padding: 12px 24px;
    border-radius: 40px;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
    font-size: 1rem;
    font-weight: bold;
    pointer-events: none;
    z-index: 99999 !important;
    box-shadow: 0 10px 30px rgba(56, 189, 248, 0.5);
    animation: floatHint 2.5s ease-in-out infinite;
    white-space: nowrap;
}

@keyframes floatHint {
    0%, 100% { transform: translate(-50%, -50%); }
    50% { transform: translate(-50%, -60%); }
}

.graph-tooltip .analysis-message strong {
    color: var(--primary);
    background: rgba(56, 189, 248, 0.1);
    padding: 2px 4px;
    border-radius: 4px;
}

/* Graph Interaction Hint */
.graph-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(56, 189, 248, 0.85); /* Highly visible */
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 10px 20px;
    border-radius: 30px;
    color: #fff;
    font-size: 0.95rem;
    font-weight: bold;
    pointer-events: none;
    z-index: 10000 !important;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.4);
    animation: floatHint 2s ease-in-out infinite;
    white-space: nowrap;
}

@keyframes floatHint {
    0%, 100% { transform: translate(-50%, -50%); }
    50% { transform: translate(-50%, -60%); }
}

/* Graph Interaction Hint */
.graph-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(56, 189, 248, 0.25);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(56, 189, 248, 0.5);
    padding: 10px 20px;
    border-radius: 30px;
    color: #38bdf8;
    font-size: 0.95rem;
    font-weight: bold;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.4);
    animation: floatHint 2.5s ease-in-out infinite;
    white-space: nowrap;
}

@keyframes floatHint {
    0%, 100% { transform: translate(-50%, -50%); }
    50% { transform: translate(-50%, -65%); }
}

.graph-tooltip.decreasing .title {
    color: var(--primary);
}

.graph-tooltip.static .title,
.graph-tooltip.static .tooltip-badge {
    color: var(--text-dim);
    border-color: var(--text-dim);
    background: rgba(148, 163, 184, 0.1);
}

.graph-tooltip .formula {
    display: block;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--glass-border);
    font-family: "Outfit", sans-serif;
    font-weight: 600;
}

.graph-tooltip .title {
    display: block;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--primary);
}

#simulation-canvas, #graph-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Controls */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.control-group {
    margin-bottom: 20px;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-group label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 6px;
    font-size: 0.9rem;
    font-weight: 500;
}

.group-a label { color: var(--primary); }
.group-b label { color: var(--secondary); }

.control-group input[type="range"] {
    width: 100%;
    cursor: pointer;
    margin-bottom: 8px;
}

.group-a input[type="range"] { accent-color: var(--primary); }
.group-b input[type="range"] { accent-color: var(--secondary); }
/* Removed .speed-value as it is now integrated into label */

.persistent-control {
    padding-bottom: 5px;
    margin-bottom: 5px;
}

.sidebar.collapsed .sidebar-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    margin-bottom: 15px;
    padding-bottom: 10px;
}

select {
    width: 100%;
    padding: 10px 35px 10px 12px;
    background-color: #0a0f1d; /* High contrast dark background */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2338bdf8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 18px;
    border: 1px solid var(--primary);
    border-radius: 8px;
    color: #fff;
    font-size: 0.95rem;
    cursor: pointer;
    appearance: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.15);
}

select:hover {
    border-color: #fbbf24; /* Change border on hover for interactivity */
    background-color: #111827;
    box-shadow: 0 0 15px rgba(251, 191, 36, 0.2);
}

select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.4), 0 0 10px rgba(56, 189, 248, 0.2);
}

input[type="range"] {
    width: 100%;
    background: var(--bg-darker);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 10px;
    border-radius: 8px;
}

.speed-value {
    display: flex;
    justify-content: center;
    font-size: 0.8rem;
    margin-top: 4px;
    font-weight: 600;
}

.action-btns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 10px;
}

.btn {
    padding: 12px;
    border: none;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:active { scale: 0.95; }

.btn-outline {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-main);
}

/* Analysis Box */
.card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    margin-bottom: 24px;
}

.card:last-child {
    margin-bottom: 0;
}

.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 10px;
}

.stat-item {
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    text-align: center;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-dim);
}

.stat-value {
    font-size: 1.2rem;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
}

.distance-value { color: var(--accent); }
.time-value { color: var(--text-main); }

/* Animation Overlay */
.mode-description {
    background: rgba(56, 189, 248, 0.1);
    border-left: 4px solid var(--primary);
    padding: 12px;
    border-radius: 4px;
    font-size: 0.9rem;
    margin-bottom: 20px;
}

/* Helper Classes */
.hidden { display: none; }

/* HUD Overlay - Minimalist Right-Top Positioning */
.hud-overlay {
    position: absolute;
    top: 10px;
    left: 20px;
    right: 20px;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 8px 25px;
    z-index: 100;
    pointer-events: none;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    gap: 15px;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.hud-item {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 8px;
    font-family: "Outfit", sans-serif;
    font-weight: 700;
    color: #fff;
}

.hud-label {
    font-size: 0.9rem;
    white-space: nowrap;
}

.hud-val {
    font-family: 'JetBrains Mono', 'Roboto Mono', monospace !important;
    font-size: 1.1rem;
    text-align: right;
    min-width: 3.5rem;
}

.hud-unit {
    font-size: 0.85rem;
    width: 1rem;
}

/* Circle Mode Adjustment - Vertical Left */
.hud-overlay.is-circle {
    top: 15px;
    left: 15px;
    right: auto;
    flex-direction: column;
    align-items: stretch;
    padding: 15px 20px;
    gap: 10px;
    width: 180px;
}

.hud-overlay.is-circle .hud-item {
    grid-template-columns: 3.5rem 1fr 1rem;
}

.hud-overlay.is-circle .hud-label {
    font-size: 0.85rem;
}

/* Dynamic Controls Visibility */
.dynamic-control {
    display: none;
    animation: fadeIn 0.3s ease;
}
.dynamic-control.visible {
    display: block;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}
