/* ===== Variables ===== */
:root {
    --bg-dark: #0a0e17;
    --bg-card: #131928;
    --bg-sidebar: #0d1220;
    --accent: #00c8ff;
    --accent-dim: #0088aa;
    --accent-glow: rgba(0, 200, 255, 0.15);
    --text: #d0d8e8;
    --text-dim: #7a8ba8;
    --text-bright: #ffffff;
    --border: #1e2a40;
    --green: #00e676;
    --orange: #ff9100;
    --red: #ff5252;
    --yellow: #ffd740;
    --blue: #448aff;
    --cyan: #00e5ff;
    --sidebar-w: 220px;
    --radius: 8px;
    --mobile-header-h: 50px;
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans JP', sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
}

/* ===== Mobile Header ===== */
.mobile-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: calc(var(--mobile-header-h) + var(--safe-top));
    padding-top: var(--safe-top);
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    padding-left: 12px;
    padding-right: 12px;
    z-index: 20;
}

.hamburger {
    background: none;
    border: none;
    color: var(--text);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.mobile-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 30;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    -webkit-overflow-scrolling: touch;
}

.sidebar.open { transform: translateX(0); }

.sidebar-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 25;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.sidebar-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 16px;
    text-decoration: none;
    border-bottom: 1px solid var(--border);
}
.logo-icon { font-size: 28px; }
.logo-text {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.2;
}
.logo-text span { font-size: 11px; color: var(--text-dim); font-weight: 400; }

/* Portal back link */
.portal-back {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    -webkit-tap-highlight-color: transparent;
}
.portal-back:hover, .portal-back:active { color: var(--accent); }

/* Search Box */
.search-box {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.search-box input, .search-mobile {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}
.search-box input:focus, .search-mobile:focus {
    border-color: var(--accent);
}
.search-box input::placeholder, .search-mobile::placeholder {
    color: var(--text-dim);
}
.search-mobile {
    flex: 1;
    padding: 6px 10px;
    font-size: 13px;
    min-width: 0;
}

.nav-list { list-style: none; padding: 12px 0; flex: 1; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 13px;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}
.nav-link:hover, .nav-link:active {
    color: var(--text);
    background: var(--accent-glow);
}
.nav-link.active {
    color: var(--accent);
    border-left-color: var(--accent);
    background: var(--accent-glow);
}
.nav-icon { font-size: 16px; }

/* ===== Content ===== */
.content {
    padding-top: calc(var(--mobile-header-h) + var(--safe-top));
    padding-bottom: var(--safe-bottom);
    min-height: 100vh;
}

/* ===== Hero ===== */
.hero {
    position: relative;
    padding: 32px 16px 24px;
    background: linear-gradient(135deg, #0a1628, #0d1f3c);
    border-bottom: 1px solid var(--border);
    overflow: hidden;
}
.hero-bg {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    opacity: 0.35;
    pointer-events: none;
}
.circuit-svg { width: 100%; height: 100%; }
.circuit-line {
    stroke: var(--accent);
    stroke-width: 2;
    fill: none;
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
    animation: drawLine 2s ease forwards;
}
.cl-1 { animation-delay: 0s; stroke-dasharray: 800; }
.cl-2 { animation-delay: 0.3s; stroke-dasharray: 200; stroke-dashoffset: 200; }
.cl-3 { animation-delay: 0.5s; stroke-dasharray: 200; stroke-dashoffset: 200; }
.cl-4 { animation-delay: 0.7s; stroke-dasharray: 200; stroke-dashoffset: 200; }
.cl-5 { animation-delay: 0.9s; stroke-dasharray: 200; stroke-dashoffset: 200; }
@keyframes drawLine { to { stroke-dashoffset: 0; } }
@keyframes fadeIn { to { opacity: 1; } }

.hero-title {
    position: relative;
    font-size: 24px;
    color: var(--text-bright);
    margin-bottom: 6px;
}
.hero-tagline {
    position: relative;
    font-size: 14px;
    color: var(--text-dim);
}

/* ===== Sections ===== */
.overview-section, .roles-section, .categories-section,
.spec-section, .sources-section {
    padding: 24px 16px;
    border-bottom: 1px solid var(--border);
}

.overview-desc { font-size: 14px; line-height: 1.8; }
.section-desc { font-size: 14px; color: var(--text-dim); margin-bottom: 20px; max-width: 640px; }

h2 { font-size: 18px; color: var(--text-bright); margin-bottom: 16px; padding-left: 12px; border-left: 3px solid var(--accent); }
h3 { font-size: 16px; color: var(--text-bright); margin: 16px 0 12px; }

/* Key Points */
.point-list { list-style: none; margin-top: 12px; }
.point-item {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 6px 0;
    font-size: 13px;
}
.point-bullet {
    width: 7px; height: 7px;
    background: var(--accent);
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 5px;
}

/* Category Grid */
.category-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}
.category-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}
.category-card:active { border-color: var(--accent); background: var(--accent-glow); }
.cat-icon { font-size: 22px; }
.cat-name { flex: 1; font-size: 14px; font-weight: 600; }
.cat-arrow { color: var(--accent-dim); font-size: 18px; }

/* ===== Page Header ===== */
.page-header {
    padding: 24px 16px 20px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, #0a1628, #0d1f3c);
}
.page-icon { font-size: 32px; display: block; margin-bottom: 10px; }
.page-header h1 { font-size: 22px; color: var(--text-bright); margin-bottom: 6px; border: none; padding: 0; }
.page-desc { font-size: 13px; color: var(--text-dim); }

/* ===== SW Stack (OSI layers) ===== */
.sw-stack { overflow-x: auto; }
.sw-layer {
    display: flex;
    align-items: stretch;
    margin-bottom: 4px;
    min-width: 340px;
}
.sw-layer-name {
    width: 100px;
    background: var(--accent-dim);
    color: var(--text-bright);
    font-size: 11px;
    font-weight: 600;
    padding: 10px 8px;
    display: flex;
    align-items: center;
    border-radius: var(--radius) 0 0 var(--radius);
    flex-shrink: 0;
}
.sw-layer:nth-child(2) .sw-layer-name { background: #2a6b4a; }
.sw-layer:nth-child(3) .sw-layer-name { background: #4a3a6b; }
.sw-layer:nth-child(4) .sw-layer-name { background: #6b4a2a; }
.sw-layer:nth-child(5) .sw-layer-name { background: #4a6b3a; }
.sw-layer:nth-child(6) .sw-layer-name { background: #3a4a6b; }
.sw-layer-info {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.sw-provider { font-size: 12px; font-weight: 600; color: var(--text-bright); }
.sw-desc { font-size: 11px; color: var(--text-dim); }

/* ===== Flow Arrow ===== */
.flow-arrow {
    text-align: center;
    color: var(--accent-dim);
    font-size: 12px;
    padding: 2px 0;
}

/* ===== Sources ===== */
.sources-section { padding: 20px 16px 32px; }
.source-list { list-style: none; }
.source-list li { padding: 5px 0; }
.source-list a {
    color: var(--accent-dim);
    text-decoration: none;
    font-size: 12px;
}
.source-list a:hover, .source-list a:active { color: var(--accent); }

/* ===== Search Results ===== */
.search-results { padding: 20px 16px; }
.search-results h2 { margin-bottom: 16px; }
.search-result-item {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; margin-bottom: 8px; cursor: pointer; transition: border-color 0.2s;
}
.search-result-item:hover { border-color: var(--accent); }
.search-result-cat { font-size: 11px; color: var(--accent); text-transform: uppercase; margin-bottom: 4px; }
.search-result-title { font-size: 15px; font-weight: 600; color: var(--text-bright); margin-bottom: 4px; }
.search-result-desc { font-size: 13px; color: var(--text-dim); }

/* ===== Share Button & QR Modal ===== */
.share-btn {
    background: none; border: none; color: var(--accent); font-size: 20px;
    cursor: pointer; padding: 4px 8px; line-height: 1; flex-shrink: 0;
    transition: transform 0.2s;
}
.share-btn:active { transform: scale(1.2); }

.share-btn-sidebar {
    display: block; width: calc(100% - 24px); margin: 12px auto;
    padding: 10px; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg-card); color: var(--accent); font-size: 14px;
    cursor: pointer; transition: border-color 0.2s, background 0.2s;
}
.share-btn-sidebar:hover { border-color: var(--accent); background: var(--accent-glow); }

.qr-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.7);
    z-index: 1000; backdrop-filter: blur(4px);
}
.qr-overlay.show { display: block; }

.qr-modal {
    display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
    z-index: 1001; background: var(--bg-card); border: 1px solid var(--accent);
    border-radius: 16px; padding: 32px; text-align: center;
    box-shadow: 0 0 40px rgba(0,200,255,0.2); min-width: 280px;
}
.qr-modal.show { display: block; }
.qr-modal h3 { color: var(--text-bright); margin-bottom: 4px; font-size: 18px; }
.qr-desc { color: var(--text-dim); font-size: 13px; margin-bottom: 16px; }
.qr-url { color: var(--accent-dim); font-size: 11px; margin-top: 12px; word-break: break-all; }

.qr-close {
    position: absolute; top: 8px; right: 12px; background: none; border: none;
    color: var(--text-dim); font-size: 28px; cursor: pointer; line-height: 1;
}
.qr-close:hover { color: var(--text-bright); }

#qr-canvas { display: inline-block; padding: 12px; background: #fff; border-radius: 8px; }

code { font-family: 'Consolas', 'Courier New', monospace; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== Portal Home ===== */
.portal-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}
.portal-app-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.2s, background 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.portal-app-card:active { border-color: var(--accent); background: var(--accent-glow); }
.portal-app-icon { font-size: 36px; margin-bottom: 12px; }
.portal-app-name { font-size: 18px; font-weight: 700; color: var(--text-bright); margin-bottom: 4px; }
.portal-app-desc { font-size: 13px; color: var(--text-dim); margin-bottom: 12px; }
.portal-app-count { font-size: 12px; color: var(--accent); }

/* ========================================
   Desktop (768px+)
   ======================================== */
@media (min-width: 768px) {
    .mobile-header { display: none; }
    .sidebar-overlay { display: none; }

    .sidebar {
        transform: translateX(0);
        transition: none;
    }

    .content {
        margin-left: var(--sidebar-w);
        padding-top: 0;
    }

    .hero { padding: 50px 40px 36px; }
    .hero-title { font-size: 30px; }
    .hero-tagline { font-size: 15px; }

    .overview-section, .roles-section, .categories-section,
    .spec-section, .sources-section {
        padding: 32px 40px;
    }

    h2 { font-size: 20px; margin-bottom: 20px; }

    .overview-desc { font-size: 15px; max-width: 720px; }

    .page-header { padding: 40px 40px 24px; }
    .page-header h1 { font-size: 28px; }
    .page-desc { font-size: 14px; max-width: 640px; }

    .category-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }

    .sw-layer-name { width: 130px; font-size: 13px; padding: 12px; }
    .sw-layer-info { padding: 12px; }
    .sw-provider { font-size: 13px; }
    .sw-desc { font-size: 12px; }

    .sources-section { padding: 24px 40px 40px; }
    .source-list a { font-size: 13px; }

    .search-results { padding: 32px 40px; }
    .share-btn-sidebar { display: none; }

    .portal-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
    .portal-app-card:hover { border-color: var(--accent); background: var(--accent-glow); }
}
