:root {
    --bg-dark: #0f172a;
    --bg-panel: rgba(30, 41, 59, 0.75);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --color-green: #10b981;
    --color-blue: #3b82f6;
    --color-yellow: #fbbf24;
    --color-red: #ef4444;
    --color-primary: #6366f1;
    --font-main: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-main);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

.ambient-background {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background:
        radial-gradient(circle at 15% 50%, rgba(99, 102, 241, 0.15), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(16, 185, 129, 0.10), transparent 25%);
    z-index: -1;
    pointer-events: none;
}

.glass {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.15), 0 2px 4px -1px rgba(0,0,0,0.08);
}

.app-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 1.5rem 2rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-height: 100vh;
}

/* ── Utilities ── */
.hidden { display: none !important; }
.text-green  { color: var(--color-green); }
.text-blue   { color: var(--color-blue); }
.text-yellow { color: var(--color-yellow); }
.text-red    { color: var(--color-red); }
.text-muted  { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-1 { margin-top: 1rem; }
.mt-2 { margin-top: 2rem; }

/* ── Header ── */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 0.75rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.radar-icon {
    width: 40px; height: 40px;
    background: rgba(99, 102, 241, 0.2);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: var(--color-primary);
    border: 1px solid rgba(99, 102, 241, 0.5);
    font-size: 1.1rem;
    flex-shrink: 0;
}

header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* ── Header Actions (right side) ── */
.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.airport-selector-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(0,0,0,0.3);
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.08);
}
.header-select {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-family: var(--font-main);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    outline: none;
}
.header-select option {
    background: #1e293b;
    color: white;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: color 0.2s;
    font-weight: 600;
    padding: 0.4rem;
    border-radius: 6px;
}
.btn-icon:hover { color: white; background: rgba(255,255,255,0.07); }
.btn-icon.text-red:hover { color: #fca5a5; background: rgba(239,68,68,0.1); }

/* ── Toggle Switch ── */
.beginner-toggle-container {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: rgba(0,0,0,0.3);
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
}
.toggle-label { font-size: 0.85rem; font-weight: 600; color: var(--color-yellow); }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #475569; transition: .3s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .3s; border-radius: 50%; }
input:checked + .slider { background-color: var(--color-green); }
input:checked + .slider:before { transform: translateX(20px); }

/* ── Tabs ── */
.mode-tabs {
    display: flex;
    gap: 0.4rem;
    background: rgba(0,0,0,0.3);
    padding: 0.25rem;
    border-radius: 8px;
}
.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    font-size: 0.9rem;
}
.tab-btn:hover { color: white; }
.tab-btn.active { background: var(--color-primary); color: white; }

/* ── Hub View ── */
.hub-view {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    padding-bottom: 2rem;
    overflow-y: auto;
    flex: 1;
}

.hub-header { text-align: center; margin-bottom: 0.5rem; }
.hub-header h2 { font-size: 1.75rem; margin-bottom: 0.4rem; }
.hub-header p { color: var(--text-muted); font-size: 0.95rem; }

/* ── Level Groups ── */
.level-group { margin-bottom: 1.5rem; }
.level-group h3 {
    font-size: 1.1rem;
    color: var(--color-blue);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-size: 0.85rem;
}

.missions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
}

.drill-card {
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 1.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.drill-card:hover {
    background: rgba(99, 102, 241, 0.12);
    border-color: var(--color-primary);
    transform: translateY(-3px);
    box-shadow: 0 8px 20px -5px rgba(99,102,241,0.2);
}
.drill-card-icon { font-size: 1.75rem; color: var(--color-primary); margin-bottom: 0.25rem; }
.drill-card h3 { font-size: 1.1rem; font-weight: 600; }
.drill-card p { font-size: 0.88rem; color: var(--text-muted); line-height: 1.4; }

/* ── Mission View ── */
.mission-view {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex: 1;
    min-height: 0;
}

.mission-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.9rem 1.25rem;
    flex-shrink: 0;
}

.mission-title-area { text-align: center; }
.mission-title-area .mission-id { font-size: 1.1rem; font-weight: 700; color: white; }

.streak-badge {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--color-yellow);
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: white;
    flex-shrink: 0;
}

.mission-goal {
    padding: 0.9rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
    font-size: 1rem;
    flex-shrink: 0;
}
.mission-goal i { font-size: 1.25rem; flex-shrink: 0; }

/* ── Communication Area ── */
.communication-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 280px;
}

.transcript {
    flex: 1;
    padding: 1.25rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    scroll-behavior: smooth;
}

.message { max-width: 82%; animation: fade-in 0.25s ease-out forwards; }
@keyframes fade-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.msg-content {
    padding: 0.7rem 1rem;
    border-radius: 12px;
    font-size: 1rem;
    line-height: 1.5;
}

.message.system { align-self: center; max-width: 90%; }
.message.system .msg-content {
    background: rgba(255,255,255,0.05);
    color: var(--text-muted);
    font-size: 0.88rem;
    text-align: center;
    border: 1px dashed var(--border-color);
    border-radius: 8px;
}

.message.tower { align-self: flex-start; }
.message.tower .msg-content {
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.25);
    border-bottom-left-radius: 2px;
}
.message.tower::before {
    content: "TOWER";
    display: block;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--color-green);
    margin-bottom: 0.2rem;
    letter-spacing: 0.05em;
}

.message.pilot { align-self: flex-end; }
.message.pilot .msg-content {
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-bottom-right-radius: 2px;
}
.message.pilot::before {
    content: "YOU";
    display: block;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--color-blue);
    margin-bottom: 0.2rem;
    text-align: right;
    letter-spacing: 0.05em;
}
.message.pilot.error .msg-content {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.3);
}
.message.pilot.success .msg-content {
    background: rgba(16, 185, 129, 0.18);
    border-color: rgba(16, 185, 129, 0.4);
}

/* ── Interaction Zone ── */
.interaction-zone {
    padding: 1.25rem;
    border-top: 1px solid var(--border-color);
    background: rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.9rem;
    flex-shrink: 0;
}

.ptt-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    outline: none;
    width: 100%;
    max-width: 280px;
    user-select: none;
    -webkit-user-select: none;
}
.ptt-inner {
    background: linear-gradient(145deg, #1e293b, #0f172a);
    border: 2px solid var(--border-color);
    border-radius: 100px;
    padding: 0.9rem 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-main);
    box-shadow: 0 8px 16px -4px rgba(0,0,0,0.5), inset 0 2px 4px rgba(255,255,255,0.04);
    transition: all 0.1s ease;
}
.ptt-inner i { font-size: 1.4rem; color: var(--text-muted); transition: color 0.15s; }
.ptt-inner span { font-weight: 700; letter-spacing: 0.08em; font-size: 1rem; }
.ptt-inner small { font-size: 0.72rem; color: var(--text-muted); }

.ptt-btn:active .ptt-inner,
.ptt-btn.active .ptt-inner {
    transform: scale(0.97) translateY(1px);
    box-shadow: 0 4px 8px -4px rgba(0,0,0,0.5), inset 0 4px 8px rgba(0,0,0,0.35);
    border-color: var(--color-primary);
    background: linear-gradient(145deg, #0f172a, #1e293b);
}
.ptt-btn:active .ptt-inner i,
.ptt-btn.active .ptt-inner i { color: var(--color-primary); }

/* ── Status Indicator ── */
.status-indicator { display: flex; align-items: center; gap: 0.9rem; }
.status-badge {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    background: rgba(255,255,255,0.08);
    color: var(--text-muted);
    letter-spacing: 0.05em;
    font-weight: 700;
    transition: all 0.2s;
}
.status-badge.listening { background: rgba(99, 102, 241, 0.2); color: var(--color-primary); box-shadow: 0 0 8px rgba(99,102,241,0.35); }
.status-badge.tower-tx  { background: rgba(16, 185, 129, 0.2); color: var(--color-green);   box-shadow: 0 0 8px rgba(16,185,129,0.35); }
.status-badge.success   { background: rgba(16, 185, 129, 0.4); color: white; box-shadow: 0 0 12px rgba(16,185,129,0.5); }

.wave-container { display: flex; gap: 3px; height: 15px; align-items: center; opacity: 0.3; transition: opacity 0.2s; }
.wave-container.active { opacity: 1; }
.wave-container .bar { width: 3px; background: var(--color-primary); border-radius: 2px; height: 3px; }
.wave-container.active .bar { animation: wave-anim 1s ease-in-out infinite; }
.wave-container.active .bar:nth-child(1) { animation-delay: 0.0s; }
.wave-container.active .bar:nth-child(2) { animation-delay: 0.1s; }
.wave-container.active .bar:nth-child(3) { animation-delay: 0.2s; }
.wave-container.active .bar:nth-child(4) { animation-delay: 0.3s; }
.wave-container.active .bar:nth-child(5) { animation-delay: 0.4s; }
.wave-container.tower-tx .bar { background: var(--color-green); }
@keyframes wave-anim { 0%, 100% { height: 3px; } 50% { height: 15px; } }

/* ── Hints Panel ── */
.hints-panel { padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: 0.5rem; flex-shrink: 0; }
.hints-panel .panel-header { font-size: 0.8rem; color: var(--color-yellow); font-weight: 700; letter-spacing: 0.05em; }
.hint-content { font-family: var(--font-mono); font-size: 0.95rem; line-height: 1.6; color: var(--text-main); font-weight: 600; }

/* ── Modals ── */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.72);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
    backdrop-filter: blur(5px);
    padding: 1rem;
}
.modal {
    width: 100%;
    max-width: 480px;
    padding: 2rem;
    border-top: 3px solid var(--color-blue);
    position: relative;
}
.modal h2, .modal h3 { font-size: 1.2rem; display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.modal p { color: var(--text-main); font-size: 1rem; line-height: 1.5; }

.btn-primary {
    background: var(--color-blue);
    color: white;
    border: none;
    padding: 0.7rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    width: 100%;
    transition: background 0.2s, transform 0.1s;
}
.btn-primary:hover { background: #2563eb; }
.btn-primary:active { transform: scale(0.98); }

.modal-actions { display: flex; flex-direction: column; gap: 0.5rem; }
.success-icon { font-size: 3.5rem; text-align: center; }

/* ── Settings Modal ── */
.settings-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    gap: 1rem;
}
.settings-group label { font-size: 0.92rem; color: var(--text-muted); }
.setting-input {
    background: rgba(0,0,0,0.35);
    border: 1px solid rgba(255,255,255,0.15);
    color: var(--text-main);
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    font-family: var(--font-main);
    font-size: 0.88rem;
    cursor: pointer;
    min-width: 130px;
}
.setting-input:focus { outline: none; border-color: var(--color-primary); }

/* ── Profile / Stats Modal ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-top: 1rem;
}
.stat-card {
    background: rgba(0,0,0,0.25);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    padding: 1.25rem;
    text-align: center;
}
.stat-card i { font-size: 1.5rem; }
.stat-value {
    font-size: 2.25rem;
    font-weight: 700;
    margin: 0.4rem 0 0.2rem;
    color: var(--text-main);
}
.stat-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

/* ── Toast ── */
.toast {
    visibility: hidden;
    min-width: 220px;
    background-color: var(--color-green);
    color: #fff;
    text-align: center;
    border-radius: 8px;
    padding: 0.85rem 1.25rem;
    position: fixed;
    z-index: 1000;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%) translateY(20px);
    font-size: 0.95rem;
    font-weight: 600;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.5);
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s, visibility 0.3s;
    pointer-events: none;
}
.toast.show {
    visibility: visible;
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Explanation Modal Styles ── */
.explanation-card {
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 60vh;
    overflow-y: auto;
}
.exp-phrase-box {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.exp-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--color-yellow);
    letter-spacing: 0.05em;
}
.exp-text-en {
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-blue);
    background: rgba(59, 130, 246, 0.12);
    padding: 0.6rem 0.85rem;
    border-radius: 8px;
    border: 1px solid rgba(59, 130, 246, 0.25);
}
.exp-text-tr {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-green);
    background: rgba(16, 185, 129, 0.12);
    padding: 0.6rem 0.85rem;
    border-radius: 8px;
    border: 1px solid rgba(16, 185, 129, 0.25);
}
.exp-text-logic {
    font-size: 0.92rem;
    line-height: 1.55;
    color: var(--text-main);
    background: rgba(255,255,255,0.05);
    padding: 0.75rem 0.85rem;
    border-radius: 8px;
    border: 1px dashed var(--border-color);
}
.msg-info-icon {
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
    margin-left: 0.5rem;
    transition: color 0.2s, transform 0.15s;
    display: inline-block;
}
.msg-info-icon:hover {
    color: var(--color-blue);
    transform: scale(1.2);
}

/* ── Responsive ── */
@media (max-width: 640px) {
    .app-container { padding: 1rem; gap: 1rem; }
    header { flex-direction: column; align-items: flex-start; }
    .header-actions { width: 100%; justify-content: space-between; }
    .missions-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr; }
    .modal { padding: 1.5rem; }
    .hub-header h2 { font-size: 1.4rem; }
}

/* ── Tablet / Touch PTT Enhancements ── */
@media (pointer: coarse) {
    /* Larger tap area on touch screens */
    .ptt-btn {
        max-width: 100%;
        touch-action: none;   /* prevents browser scroll/zoom intercepting the press */
        -webkit-touch-callout: none;
        user-select: none;
        -webkit-user-select: none;
    }
    .ptt-inner {
        padding: 1.4rem 2.5rem;
        border-radius: 20px;
    }
    .ptt-inner i    { font-size: 2rem; }
    .ptt-inner span { font-size: 1.25rem; }
    .ptt-inner small { font-size: 0.85rem; }

    /* Bigger interaction zone on touch devices */
    .interaction-zone { padding: 1.5rem 1.25rem; gap: 1.25rem; }

    /* Hide keyboard hint on touch (no space key) */
    .ptt-inner small { display: none; }
}