/**
 * Racing Digital Cluster UI - 5連メーター
 * 12.3インチディスプレイ (1920x720) 想定
 */

:root {
    /* タイヤヒートカラー */
    --heat-cold: #2196F3;
    --heat-optimal: #4CAF50;
    --heat-warning: #FFC107;
    --heat-critical: #F44336;

    /* ステータスカラー */
    --status-normal: #4CAF50;
    --status-caution: #FFC107;
    --status-danger: #F44336;

    /* 基本カラー */
    --bg-primary: #0a0a0a;
    --bg-gauge: #111111;
    --bg-gauge-inner: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #666666;
    --accent: #00ff88;
    --accent-dim: rgba(0, 255, 136, 0.3);
    --traction-color: #ff9500;
    --danger: #ff3333;

    /* クラスターサイズ */
    --cluster-width: 1920px;
    --cluster-height: 720px;
}

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

body {
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background: #1a1a1a;
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    gap: 20px;
}

/* =====================================
   クラスターディスプレイ（12.3インチ）
===================================== */
.cluster-display {
    width: var(--cluster-width);
    height: var(--cluster-height);
    max-width: 100%;
    background: linear-gradient(180deg, #151515 0%, #0a0a0a 50%, #0d0d0d 100%);
    border-radius: 16px;
    position: relative;
    overflow: hidden;
    box-shadow:
        0 0 0 2px rgba(255, 255, 255, 0.05),
        0 20px 60px rgba(0, 0, 0, 0.8),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    aspect-ratio: 1920 / 720;
}

/* =====================================
   重大アラート
===================================== */
.critical-alert {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(90deg, transparent, var(--danger), transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    font-size: 24px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 3px;
    animation: alert-pulse 0.5s infinite;
    z-index: 100;
}

.critical-alert.hidden {
    display: none;
}

/* デモフェーズインジケーター */
.demo-indicator {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    padding: 8px 12px 12px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 50;
    overflow: hidden;
}

.demo-indicator.hidden {
    display: none;
}

/* 進捗バー（枠線として） */
.demo-indicator .progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    width: 0%;
    background: var(--accent);
    border-radius: 0 0 20px 20px;
    transition: width 0.05s linear;
    box-shadow: 0 0 8px var(--accent);
}

.demo-indicator.phase-accelerate .progress-bar,
.demo-indicator.phase-exit .progress-bar {
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent);
}

.demo-indicator.phase-brake .progress-bar {
    background: #ff4444;
    box-shadow: 0 0 8px #ff4444;
}

.demo-indicator.phase-corner .progress-bar {
    background: #ffaa00;
    box-shadow: 0 0 8px #ffaa00;
}

.demo-indicator.phase-coast .progress-bar {
    background: #4488ff;
    box-shadow: 0 0 8px #4488ff;
}

.demo-indicator .phase {
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    color: #444;
    border-radius: 12px;
    transition: all 0.2s ease;
}

.demo-indicator .phase.active {
    color: #fff;
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent);
}

.demo-indicator .phase[data-phase="brake"].active {
    background: #ff4444;
    box-shadow: 0 0 10px #ff4444;
}

.demo-indicator .phase[data-phase="corner"].active {
    background: #ffaa00;
    box-shadow: 0 0 10px #ffaa00;
}

.demo-indicator .phase[data-phase="coast"].active {
    background: #4488ff;
    box-shadow: 0 0 10px #4488ff;
}

.alert-icon {
    font-size: 32px;
    animation: alert-shake 0.1s infinite;
}

@keyframes alert-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@keyframes alert-shake {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(2px); }
}

/* =====================================
   インジケータバー
===================================== */
.indicator-bar {
    position: absolute;
    top: 10px;
    left: 0;
    right: 0;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.indicator-center {
    display: flex;
    gap: 20px;
}

.indicator {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    padding: 4px 10px;
    border-radius: 4px;
    letter-spacing: 1px;
}

.indicator.active {
    color: var(--accent);
    text-shadow: 0 0 10px var(--accent);
}

.indicator.warning {
    color: var(--heat-warning);
    text-shadow: 0 0 10px var(--heat-warning);
}

/* =====================================
   5連メーターレイアウト
===================================== */
.five-gauge-layout {
    position: absolute;
    top: 50px;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0;
    padding: 10px 20px;
}

/* 共通ゲージスタイル */
.gauge {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.gauge-ring {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.gauge-ring svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.gauge-bg {
    fill: none;
    stroke: #1a1a1a;
    stroke-width: 12;
}

.gauge-fill {
    fill: none;
    stroke-width: 12;
    stroke-linecap: round;
    stroke-dasharray: 534;
    stroke-dashoffset: 534;
    transform: rotate(-90deg);
    transform-origin: center;
    transition: stroke-dashoffset 0.3s ease, stroke 0.3s ease;
}

.gauge-content {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.gauge-value {
    font-size: 32px;
    font-weight: 300;
    line-height: 1;
}

.gauge-unit {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.gauge-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: 8px;
}

/* 外側ゲージ */
.gauge-outer .gauge-ring {
    width: 180px;
    height: 180px;
}

/* 内側ゲージ */
.gauge-inner .gauge-ring {
    width: 220px;
    height: 220px;
}

/* =====================================
   中央タコメーター
===================================== */
.gauge-center {
    flex-direction: column;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.tacho-ring {
    width: 400px;
    height: 400px;
    position: relative;
}

.tacho-svg {
    width: 100%;
    height: 100%;
}

/* トラクションリング */
.traction-ring-bg {
    fill: none;
    stroke: #222;
    stroke-width: 6;
    stroke-dasharray: 885 1200;
    stroke-dashoffset: 0;
    transform: rotate(135deg);
    transform-origin: center;
}

.traction-ring-fill {
    fill: none;
    stroke: var(--traction-color);
    stroke-width: 6;
    stroke-linecap: round;
    stroke-dasharray: 885 1200;
    stroke-dashoffset: 885;
    transform: rotate(135deg);
    transform-origin: center;
    filter: drop-shadow(0 0 6px var(--traction-color));
}

/* タコメーター本体 */
.tacho-bg {
    fill: var(--bg-gauge-inner);
    stroke: #222;
    stroke-width: 3;
}

/* イエローゾーン */
.yellowzone {
    fill: rgba(255, 193, 7, 0.12);
    stroke: none;
}

/* レッドゾーン */
.redzone {
    fill: rgba(255, 51, 51, 0.12);
    stroke: none;
}

/* RPM目盛り */
.rpm-marker-major {
    stroke: #555;
    stroke-width: 3;
}

.rpm-marker-minor {
    stroke: #333;
    stroke-width: 1.5;
}

.rpm-marker-redzone {
    stroke: #ff3333;
    stroke-width: 3;
}

/* RPM数字 */
.rpm-number {
    fill: #666;
    font-size: 22px;
    font-weight: 500;
    text-anchor: middle;
    dominant-baseline: middle;
}

.rpm-number-redzone {
    fill: #ff3333;
}

/* RPMニードル */
.rpm-needle {
    fill: var(--danger);
    transform-origin: 200px 200px;
    transition: transform 0.05s ease-out;
    filter: drop-shadow(0 0 10px var(--danger));
}

.needle-center {
    fill: #222;
    stroke: #444;
    stroke-width: 3;
}

/* 中央デジタル表示 */
.tacho-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 72px;
}

.speed-display {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.speed-value {
    font-size: 72px;
    font-weight: 200;
    line-height: 1;
    letter-spacing: -3px;
}

.speed-unit {
    font-size: 14px;
    color: var(--text-secondary);
}

.gear-display {
    margin-top: 5px;
}

.gear-value {
    font-size: 48px;
    font-weight: 700;
    color: var(--accent);
    text-shadow: 0 0 20px var(--accent-dim);
}

/* ラップタイマー（メーター下） */
.lap-section {
    display: flex;
    align-items: center;
    gap: 30px;
    padding: 8px 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
}

.lap-timer {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.lap-label {
    font-size: 12px;
    color: var(--text-secondary);
    letter-spacing: 1px;
}

.lap-time {
    font-size: 24px;
    font-family: 'Courier New', monospace;
    font-weight: 500;
}

.delta-display {
    font-size: 22px;
    font-family: 'Courier New', monospace;
    font-weight: 600;
}

.delta-display.positive .delta-value {
    color: var(--danger);
}

.delta-display.negative .delta-value {
    color: var(--accent);
}

/* シフトライト＋ウインカー */
.top-indicators {
    position: absolute;
    top: -35px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 20px;
}

.top-indicators .turn-signal {
    width: 120px;
    height: 10px;
}

.top-indicators .turn-signal polygon {
    fill: #333;
}

.top-indicators .turn-signal.on polygon {
    fill: #00ff00;
    filter: drop-shadow(0 0 10px #00ff00);
}

.shift-lights {
    display: flex;
    gap: 10px;
}

.shift-light {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #222;
    border: 2px solid #333;
    transition: all 0.05s ease;
}

.shift-light.green {
    background: #00ff00;
    border-color: #00ff00;
    box-shadow: 0 0 15px #00ff00;
}

.shift-light.yellow {
    background: #ffff00;
    border-color: #ffff00;
    box-shadow: 0 0 15px #ffff00;
}

.shift-light.red {
    background: #ff0000;
    border-color: #ff0000;
    box-shadow: 0 0 15px #ff0000;
}

.shift-light.blink {
    animation: shift-blink 0.1s infinite;
}

@keyframes shift-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* =====================================
   ブーストメーター
===================================== */
.boost-fill {
    stroke: var(--accent);
}

/* =====================================
   燃料メーター
===================================== */
.fuel-fill {
    stroke: var(--heat-warning);
}

.fuel-icon {
    font-size: 24px;
    margin-bottom: 5px;
}

.fuel-value {
    color: var(--heat-warning);
}

/* =====================================
   パワートレインステータス
===================================== */
.powertrain-status {
    display: flex;
    flex-direction: column;
    width: 140px;
    gap: 12px;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-bar {
    width: 48px;
    height: 12px;
    background: #222;
    border-radius: 6px;
    overflow: hidden;
}

.status-fill {
    height: 100%;
    width: 50%;
    background: var(--status-normal);
    border-radius: 6px;
    transition: width 0.3s ease, background 0.3s ease;
}

.status-label {
    font-size: 10px;
    color: var(--text-secondary);
    width: 45px;
    text-align: right;
}

/* =====================================
   タイヤUI
===================================== */
.tire-gauge {
    width: 220px;
    height: 220px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.tire-svg {
    width: 100%;
    height: 100%;
}

.tire-gauge-bg {
    fill: var(--bg-gauge-inner);
    stroke: #222;
    stroke-width: 2;
}

.car-outline {
    fill: rgba(255, 255, 255, 0.03);
    stroke: rgba(255, 255, 255, 0.15);
    stroke-width: 2;
}

.tire-group .tire-body {
    fill: var(--heat-optimal);
    transition: fill 0.2s ease;
}

.tire-group .tire-life-bg-line {
    stroke: #333;
    stroke-width: 2;
    stroke-linecap: butt;
}

.tire-group .tire-life-line {
    stroke: var(--accent);
    stroke-width: 2;
    stroke-linecap: butt;
    stroke-dasharray: 30;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.5s ease, stroke 0.3s ease;
}

/* =====================================
   シミュレーションパネル
===================================== */
.simulation-panel {
    width: 100%;
    max-width: 1920px;
    background: #1a1a1a;
    border-radius: 12px;
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.simulation-panel h3 {
    grid-column: 1 / -1;
    font-size: 14px;
    font-weight: 400;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 10px;
}

.control-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.control-section > label {
    font-size: 12px;
    color: var(--text-secondary);
}

.control-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.control-row label {
    font-size: 12px;
    color: var(--text-secondary);
}

input[type="range"] {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    background: #333;
    border-radius: 3px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

.tire-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.powertrain-controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}

.powertrain-controls > div {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.powertrain-controls label {
    font-size: 11px;
    color: var(--text-secondary);
}

.gear-buttons {
    display: flex;
    gap: 8px;
}

.gear-buttons button {
    width: 40px;
    height: 40px;
    border: 2px solid var(--accent);
    background: transparent;
    color: var(--accent);
    font-size: 16px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.gear-buttons button:hover,
.gear-buttons button.active {
    background: var(--accent);
    color: var(--bg-primary);
}

.control-section:last-child {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
}

.control-section button {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
}

#demo-mode {
    background: var(--accent);
    color: var(--bg-primary);
}

#demo-mode:hover {
    background: #00cc6a;
}

#trigger-alert {
    background: var(--danger);
    color: white;
}

#throttle-btn {
    background: #333;
    color: white;
}

#throttle-btn:hover {
    background: #555;
}

#throttle-btn.active {
    background: var(--traction-color);
    color: black;
}

#toggle-turn-left,
#toggle-turn-right {
    background: #333;
    color: white;
}

#toggle-turn-left:hover,
#toggle-turn-right:hover,
#toggle-hazard:hover,
#toggle-turn-left.active,
#toggle-turn-right.active,
#toggle-hazard.active {
    background: #00ff00;
    color: black;
}

/* =====================================
   レスポンシブ
===================================== */
@media (max-width: 1920px) {
    .cluster-display {
        width: 100%;
    }
}

@media (max-width: 1200px) {
    .five-gauge-layout {
        gap: 0;
        padding: 10px;
    }

    .gauge-outer .gauge-ring {
        width: 140px;
        height: 140px;
    }

    .gauge-inner .gauge-ring {
        width: 170px;
        height: 170px;
    }

    .tacho-ring {
        width: 300px;
        height: 300px;
    }

    .speed-value {
        font-size: 48px;
    }

    .gear-value {
        font-size: 36px;
    }

    .gauge-value {
        font-size: 24px;
    }
}

@media (max-width: 900px) {
    .five-gauge-layout {
        flex-wrap: wrap;
        height: auto;
    }

    .gauge-outer {
        order: 2;
    }

    .gauge-inner {
        order: 1;
    }

    .gauge-center {
        order: 0;
        width: 100%;
    }
}
