/* ============================================================
   GearLab — Shared Stylesheet (assets/style.css)
   Single source of truth for theme, layout, header/footer.
   Used by: index.html / screen.html / audio.html / input.html
   ============================================================ */

:root { --primary: #00d4ff; --accent: #00ff64; --bg: #0f0f0f; --panel: rgba(20,20,20,0.95); --warn: #ffaa00; --danger: #ff4444; }
* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: linear-gradient(135deg, #0f0f0f 0%, #1a1a1a 100%); color: #e0e0e0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: 20px; }
.container { background: var(--panel); border: 2px solid var(--primary); border-radius: 16px; padding: 30px; max-width: 900px; width: 100%; box-shadow: 0 0 40px rgba(0, 212, 255, 0.15); position: relative; }

/* ---------- Language switching (shared mechanism) ---------- */
body:not(.en-mode) .lang-en { display: none !important; }
body.en-mode .lang-zh { display: none !important; }
body.en-mode .lang-en { display: inline-block !important; }

.lang-switch { display: flex; gap: 10px; z-index: 10; }
.lang-btn { background: transparent; border: 1px solid #444; color: #888; padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 12px; transition: 0.2s; }
.lang-btn.active { border-color: var(--primary); color: var(--primary); background: rgba(0,212,255,0.1); }

/* ---------- Site header (injected by assets/layout.js) ---------- */
.site-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 1px solid rgba(0,212,255,0.2); }
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--primary); font-weight: bold; font-size: 18px; letter-spacing: 1px; text-decoration: none; white-space: nowrap; }
.brand-icon { width: 26px; height: 26px; border-radius: 6px; }
.nav-links { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.nav-links a { padding: 5px 12px; border-radius: 14px; color: #aaa; text-decoration: none; font-size: 13px; white-space: nowrap; border: 1px solid transparent; transition: 0.2s; }
.nav-links a:hover { color: #fff; border-color: #666; }
.nav-links a.active { background: rgba(0,212,255,0.15); color: var(--primary); border-color: var(--primary); box-shadow: 0 0 8px rgba(0,212,255,0.2); }

/* ---------- Page header / hero ---------- */
.header { text-align: center; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 1px solid rgba(0,212,255,0.2); }
.header h1 { font-size: 28px; color: var(--primary); margin-bottom: 8px; letter-spacing: 1px; }
.header p { color: #888; font-size: 13px; font-weight: bold; letter-spacing: 1px; margin-bottom: 5px; }
.hero-text { color: #aaa; font-size: 14px; max-width: 600px; margin: 0 auto; line-height: 1.5; text-align: left; background: rgba(0,0,0,0.2); padding: 20px; border-radius: 8px; margin-top: 15px; font-size: 13px; }
.hero-text strong { color: var(--accent); }

/* ---------- Homepage module cards ---------- */
.module-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; margin-top: 25px; }
.module-card { background: #1a1a1a; border: 1px solid #333; border-radius: 12px; padding: 24px 20px; text-decoration: none; display: flex; flex-direction: column; transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s; }
.module-card:hover { transform: translateY(-5px); border-color: var(--primary); box-shadow: 0 5px 15px rgba(0, 212, 255, 0.15); }
.module-icon { font-size: 34px; margin-bottom: 12px; }
.module-card h2 { color: #fff; font-size: 19px; margin-bottom: 8px; }
.module-card:hover h2 { color: var(--primary); }
.module-card p { color: #888; font-size: 13px; line-height: 1.7; flex-grow: 1; margin-bottom: 15px; }
.module-cta { color: var(--primary); font-size: 14px; font-weight: bold; }

/* ---------- Navigation (module sub-tabs) ---------- */
.main-tabs { display: flex; gap: 10px; margin-bottom: 15px; justify-content: center; border-bottom: 1px solid #333; padding-bottom: 15px; }
.main-tab-btn { flex: 1; max-width: 150px; padding: 10px; background: transparent; border: 1px solid #444; color: #888; cursor: pointer; border-radius: 8px; font-weight: bold; transition: 0.2s; font-size: 14px; text-align: center; }
.main-tab-btn.active { background: rgba(0, 212, 255, 0.15); color: var(--primary); border-color: var(--primary); box-shadow: 0 0 10px rgba(0,212,255,0.2); }
.main-tab-btn:hover { border-color: #666; color: #fff; }

.sub-nav { display: flex; gap: 8px; margin-bottom: 20px; overflow-x: auto; padding-bottom: 5px; justify-content: center; animation: fadeIn 0.3s ease; }
.tab-btn { padding: 6px 12px; background: rgba(255,255,255,0.05); border: none; color: #aaa; cursor: pointer; border-radius: 15px; white-space: nowrap; font-size: 12px; transition: 0.2s; }
.tab-btn.active { background: var(--primary); color: #000; font-weight: bold; }

/* ---------- Content sections ---------- */
.view-section, .sub-content { display: none; animation: fadeIn 0.3s ease; }
.view-section.active, .sub-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Controls ---------- */
canvas { display: block; width: 100%; border: 1px solid #333; border-radius: 8px; margin-bottom: 15px; background: #000; }
.control-panel { background: rgba(255,255,255,0.03); padding: 20px; border-radius: 8px; margin-bottom: 15px; }
button.action-btn { width: 100%; padding: 12px; margin-top: 10px; border-radius: 6px; border: 1px solid var(--primary); background: rgba(0,212,255,0.1); color: var(--primary); cursor: pointer; font-weight: bold; transition: 0.2s; }
button.action-btn:hover { background: var(--primary); color: #000; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.cta-group { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }
.share-btn { flex: 0 0 auto; width: auto; padding: 8px 16px; font-size: 12px; border: 1px solid #555; background: #222; color: #ccc; }
.share-btn:hover { background: #333; color: #fff; border-color: #777; }

.grid-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 15px; }
input[type="range"] { width: 100%; height: 6px; border-radius: 5px; background: linear-gradient(to right, #ff4444, #ffaa00, #00ff64, #ffaa00, #ff4444); outline: none; appearance: none; -webkit-appearance: none; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: var(--primary); border: 2px solid #fff; cursor: pointer; }
select, input[type="number"] { background: #222; border: 1px solid #444; color: #fff; padding: 8px; border-radius: 4px; width: 100%; margin-top: 5px; }

.info-box { background: rgba(0,212,255,0.05); border-left: 3px solid var(--primary); padding: 15px; font-size: 13px; line-height: 1.6; color: #bbb; margin-top: 15px; }
.privacy-note { font-size: 11px; color: #666; margin-top: 10px; text-align: center; border-top: 1px solid #333; padding-top: 10px; }

/* ---------- Stats ---------- */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 15px; }
.stat-card { background: #222; padding: 10px; border-radius: 6px; text-align: center; border: 1px solid #333; }
.stat-val { font-size: 18px; font-weight: bold; color: var(--primary); }
.stat-label { font-size: 11px; color: #888; }
.stat-sub { font-size: 10px; color: #666; margin-top: 2px; }

.disclaimer-badge { background: rgba(255, 170, 0, 0.15); border: 1px solid var(--warn); border-radius: 6px; padding: 10px; margin-bottom: 15px; display: flex; gap: 10px; align-items: center; }
.disclaimer-icon { font-size: 20px; }
.disclaimer-text { font-size: 12px; color: #ccc; line-height: 1.4; }
.disclaimer-text strong { color: var(--warn); }

/* ---------- Leaderboard & Filter ---------- */
.leaderboard-section { background: rgba(0,0,0,0.3); border: 1px solid #333; border-radius: 8px; padding: 15px; margin-top: 20px; display: none; }
.leaderboard-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; flex-wrap: wrap; gap: 10px; }
.leaderboard-header h4 { color: var(--primary); margin: 0; }
.filter-controls { display: flex; gap: 8px; }
.filter-controls label { cursor: pointer; }
.filter-controls input[type="radio"] { display: none; }
.filter-label { font-size: 11px; color: #888; padding: 3px 8px; border: 1px solid #444; border-radius: 12px; transition: 0.2s; display: inline-block; }
.filter-controls input[type="radio"]:checked + .filter-label { background: rgba(0, 212, 255, 0.2); color: var(--primary); border-color: var(--primary); }

.table-scroll { max-height: 500px; overflow-y: auto; overflow-x: auto; border-top: 1px solid #333; }
.table-scroll::-webkit-scrollbar { width: 6px; height: 6px; }
.table-scroll::-webkit-scrollbar-track { background: #111; }
.table-scroll::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }

.rank-table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
.rank-table td, .rank-table th { padding: 10px 8px; border-bottom: 1px solid rgba(255,255,255,0.05); text-align: left; color: #ccc; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-table th { position: sticky; top: 0; background: #1a1a1a; z-index: 1; border-bottom: 1px solid #444; }
.rank-table th:nth-child(1) { width: 15%; } .rank-table th:nth-child(2) { width: 45%; } .rank-table th:nth-child(3) { width: 20%; } .rank-table th:nth-child(4) { width: 20%; text-align: right; } .rank-table td:nth-child(4) { text-align: right; }
.rank-badge { display: inline-block; width: 20px; height: 20px; text-align: center; border-radius: 50%; font-size: 11px; line-height: 20px; font-weight: bold; color: #000; }
.rank-1 { background: #ffd700; } .rank-2 { background: #c0c0c0; } .rank-3 { background: #cd7f32; } .rank-common { background: #333; color: #fff; }
.latency-good { color: var(--accent); } .latency-bad { color: #ff4444; }

/* ---------- Fullscreen overlay (screen defects test) ---------- */
#fullscreen-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 9999; background: #000; cursor: pointer; }
#fullscreen-overlay .fs-tip { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: #888; font-size: 14px; pointer-events: none; opacity: 0.5; }
/* Close button: visible on any overlay color, 48px touch target, notch-safe */
#fullscreen-overlay .fs-close { position: absolute; top: 16px; right: 16px; width: 48px; height: 48px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.7); background: rgba(0,0,0,0.35); color: #fff; font-size: 22px; line-height: 1; cursor: pointer; z-index: 10000; }
#fullscreen-overlay .fs-close { top: calc(12px + env(safe-area-inset-top)); } /* override where env() is supported (iPhone notch) */
#fullscreen-overlay .fs-close:active { background: rgba(255,255,255,0.3); }

/* ---------- Color gamut ---------- */
.gamut-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-top: 15px; }
.gamut-box { aspect-ratio: 1; border-radius: 8px; border: 1px solid #333; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 10px; font-weight: bold; color: #000; position: relative; overflow: hidden; text-shadow: 0 0 2px rgba(255,255,255,0.8); }
.gamut-box span { z-index: 2; }
.gamut-shape { position: absolute; top: 20%; left: 20%; width: 60%; height: 60%; background-color: var(--target-color); }
.shape-square { border-radius: 4px; } .shape-circle { border-radius: 50%; } .shape-triangle { clip-path: polygon(50% 0%, 0% 100%, 100% 100%); width: 70%; height: 70%; top: 15%; left: 15%; }

/* ---------- Guide / auto test ---------- */
.step-guide { display: flex; gap:10px; margin-bottom:15px; }
.step-item { flex:1; background:#222; padding:10px; border-radius:6px; font-size:12px; color:#aaa; border:1px solid #333; text-align:center; }
.step-item.active { border-color:var(--primary); color:#fff; background:rgba(0,212,255,0.1); }
.auto-result { font-size: 32px; color: var(--accent); font-weight: bold; text-align: center; margin: 20px 0; }
.auto-detail { text-align: center; color: #888; font-size: 13px; }

/* ---------- Test zones (mouse / keyboard) ---------- */
#mouseZone { width: 100%; height: 200px; background: rgba(255,255,255,0.05); border: 2px dashed #444; border-radius: 8px; display: flex; align-items: center; justify-content: center; margin-bottom: 20px; cursor: crosshair; transition: 0.2s; }
#mouseZone:hover { border-color: var(--primary); background: rgba(0, 212, 255, 0.05); }
#mouseZone.active-zone { border-style: solid; border-color: var(--accent); }
#keyboardZone { width: 100%; min-height: 150px; background: #222; border: 1px solid #444; border-radius: 8px; padding: 15px; display: flex; flex-wrap: wrap; gap: 5px; align-content: flex-start; margin-bottom: 20px; }
.key-cap { background: #444; color: #fff; padding: 5px 10px; border-radius: 4px; font-size: 14px; font-family: monospace; border-bottom: 2px solid #222; animation: popIn 0.1s ease; }
@keyframes popIn { from { transform: scale(0.8); opacity:0; } to { transform: scale(1); opacity:1; } }

/* ---------- Gamepad visualizer (Xbox-style) ---------- */
.gp-container { display: flex; flex-wrap: wrap; gap: 20px; }
.gp-visualizer { flex: 1; min-width: 320px; height: 280px; background: #1a1a1a; border: 1px solid #444; border-radius: 12px; position: relative; display: flex; justify-content: center; align-items: center; }
.gp-data { flex: 1; min-width: 300px; }

.gp-body {
    width: 300px; height: 190px;
    background: linear-gradient(160deg, #3a3a3a 0%, #2a2a2a 100%);
    border-radius: 50px 50px 60px 60px / 40px 40px 70px 70px;
    position: relative;
    box-shadow: inset 0 -4px 8px rgba(0,0,0,0.6), 0 4px 12px rgba(0,0,0,0.5);
}

.gp-shoulder { position: absolute; top: -14px; width: 80px; height: 14px; background: #444; border-radius: 6px 6px 0 0; display: flex; align-items: center; justify-content: center; font-size: 10px; color: #888; font-weight: bold; }
.gp-shoulder-l { left: 28px; }
.gp-shoulder-r { right: 28px; }
.gp-shoulder.active { background: var(--primary); color: #000; }

.gp-trigger { position: absolute; top: -26px; width: 60px; height: 12px; background: #555; border-radius: 4px 4px 0 0; display: flex; align-items: center; justify-content: center; font-size: 9px; color: #777; font-weight: bold; }
.gp-trigger-l { left: 36px; }
.gp-trigger-r { right: 36px; }
.gp-trigger.active { background: var(--accent); color: #000; }

.gp-stick { width: 52px; height: 52px; background: radial-gradient(circle at 40% 35%, #555, #1a1a1a); border-radius: 50%; border: 2px solid #555; position: absolute; box-shadow: 0 4px 8px rgba(0,0,0,0.5); }
.gp-stick-left  { top: 28px;  left: 38px; }
.gp-stick-right { bottom: 28px; right: 78px; }
.gp-stick-dot { width: 22px; height: 22px; background: radial-gradient(circle at 40% 35%, #888, #444); border-radius: 50%; position: absolute; top: 13px; left: 13px; transition: transform 0.05s linear; }

.gp-dpad { position: absolute; bottom: 30px; left: 78px; width: 54px; height: 54px; }
.gp-dpad-arm { position: absolute; background: #444; border-radius: 3px; display: flex; align-items: center; justify-content: center; }
.gp-dpad-arm.up    { top: 0;    left: 50%; transform: translateX(-50%); width: 18px; height: 20px; border-radius: 3px 3px 0 0; }
.gp-dpad-arm.down  { bottom: 0; left: 50%; transform: translateX(-50%); width: 18px; height: 20px; border-radius: 0 0 3px 3px; }
.gp-dpad-arm.left  { left: 0;   top: 50%;  transform: translateY(-50%); width: 20px; height: 18px; border-radius: 3px 0 0 3px; }
.gp-dpad-arm.right { right: 0;  top: 50%;  transform: translateY(-50%); width: 20px; height: 18px; border-radius: 0 3px 3px 0; }
.gp-dpad-center { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 18px; height: 18px; background: #444; }
.gp-dpad-arm.active, .gp-dpad-center.active { background: var(--primary); }

.gp-abxy { position: absolute; top: 22px; right: 32px; width: 80px; height: 80px; }
.gp-btn-round { width: 24px; height: 24px; position: absolute; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: bold; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.6); box-shadow: 0 3px 0 rgba(0,0,0,0.4), 0 4px 6px rgba(0,0,0,0.3); transition: margin-top 0.05s, box-shadow 0.05s, filter 0.05s; }
.gp-btn-round.active { margin-top: 3px; box-shadow: 0 0 0 rgba(0,0,0,0.4), inset 0 2px 5px rgba(0,0,0,0.5); filter: brightness(1.3); }
/* A=bottom, B=right, X=left, Y=top */
#gp-b0 { bottom: 0;  left: 28px; background: #4caf50; }
#gp-b1 { right: 0;  top: 28px;  background: #f44336; }
#gp-b2 { left: 0;   top: 28px;  background: #2196f3; }
#gp-b3 { top: 0;    left: 28px; background: #d4a017; color: #fff; }

.gp-center-btns { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; }
.gp-center-btn { width: 18px; height: 18px; background: #444; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 8px; color: #888; font-weight: bold; box-shadow: 0 2px 4px rgba(0,0,0,0.4); }
.gp-center-btn.home { width: 24px; height: 24px; background: radial-gradient(circle, #555, #333); font-size: 10px; color: var(--primary); border: 1px solid #666; }
.gp-center-btn.active { background: var(--primary); color: #000; }

/* ---------- FAQ ---------- */
.faq-content { display: none; margin-top: 30px; border-top: 1px solid #333; padding-top: 20px; color: #888; line-height: 1.6; animation: fadeIn 0.3s ease; }
.faq-content.active-faq { display: block; }
.faq-content h3 { font-size: 16px; color: var(--primary); margin-bottom: 10px; margin-top: 20px; }

/* ---------- Ads ---------- */
.ad-container { width: 100%; min-height: 100px; margin: 20px auto; text-align: center; overflow: hidden; }

/* ---------- Articles preview section ---------- */
.articles-preview-section { margin-top: 40px; padding-top: 30px; border-top: 1px solid #333; animation: fadeIn 0.5s ease; }
.articles-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; margin-top: 20px; }
.article-card { background: #1a1a1a; border: 1px solid #333; border-radius: 12px; padding: 20px; text-decoration: none; display: flex; flex-direction: column; transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s; }
.article-card:hover { transform: translateY(-5px); border-color: var(--primary); box-shadow: 0 5px 15px rgba(0, 212, 255, 0.15); }
.article-card-title { color: #fff; font-size: 15px; margin-bottom: 10px; line-height: 1.5; }
.article-card:hover .article-card-title { color: var(--primary); }
.article-card-summary { color: #888; font-size: 13px; line-height: 1.6; flex-grow: 1; margin-bottom: 15px; }
.article-card-link { color: var(--primary); font-size: 13px; font-weight: bold; }

/* ---------- Static pages (about / contact / privacy / terms) ---------- */
.page-content h2 { color: #fff; margin-top: 25px; font-size: 18px; border-left: 3px solid var(--primary); padding-left: 10px; }
.page-content p, .page-content li { color: #ccc; font-size: 14px; line-height: 1.7; margin-bottom: 10px; }
.page-content ul { margin-left: 20px; }
.page-content a { color: var(--primary); text-decoration: none; }
.contact-info { background: rgba(255,255,255,0.05); padding: 20px; border-radius: 8px; margin-bottom: 20px; border-left: 3px solid var(--primary); }
.back-btn { display: inline-block; margin-top: 20px; padding: 10px 20px; border: 1px solid var(--primary); color: var(--primary); text-decoration: none; border-radius: 6px; transition: 0.2s; background: rgba(0,212,255,0.05); }
.back-btn:hover { background: var(--primary); color: #000; }

/* ---------- Responsive canvas sizing (RWD + HiDPI) ----------
   Explicit CSS heights keep the display aspect ratio stable across viewports;
   assets/layout.js fitCanvas() then matches the bitmap to size × devicePixelRatio. */
#ufoCanvas { height: 250px; }
#latencyCanvas { height: 300px; }
#micCanvas { height: 200px; }
#sweepCanvas { height: 100px; }
#frameChart { height: 120px; }
#vrrCanvas { height: 150px; }
#frCanvas { height: 260px; }
#burninCanvas { height: 220px; }

/* Click / hold interaction zones (click latency + key repeat) */
.click-zone { width: 100%; min-height: 90px; background: rgba(255,255,255,0.04); border: 2px dashed #444; border-radius: 8px; display: flex; align-items: center; justify-content: center; cursor: pointer; user-select: none; -webkit-user-select: none; transition: 0.2s; }
.click-zone:hover { border-color: var(--primary); background: rgba(0,212,255,0.04); }

/* FR mode selector buttons */
.fr-mode.active { background: var(--primary); color: #000; }
#mouseWaveCanvas, #mouseHistCanvas { height: 100px; }
#kbCanvas { height: 120px; }
#spatialCanvas { width: min(300px, 100%); aspect-ratio: 1 / 1; margin-left: auto; margin-right: auto; }
#gpDeadzoneCanvas { width: min(280px, 100%); height: auto; aspect-ratio: 1 / 1; margin-left: auto; margin-right: auto; }

/* ---------- Footer (injected by assets/layout.js) ---------- */
.footer { margin-top: 40px; padding: 30px 20px; border-top: 1px solid #333; text-align: center; background: rgba(0, 0, 0, 0.2); border-radius: 0 0 16px 16px; }
.footer-links { margin-bottom: 15px; }
.footer-links a { color: #888; text-decoration: none; font-size: 13px; margin: 0 12px; transition: color 0.2s; }
.footer-links a:hover { color: var(--primary); }
.copyright { color: #555; font-size: 12px; }

/* ─── Dark-theme readability fixes (apply at all widths) ─── */
.stat-sub        { font-size: 11px; color: #999; }   /* was 10px #666 */
.privacy-note    { color: #888; }                     /* was #666      */
.copyright       { color: #777; }                     /* was #555      */
.stat-label      { font-size: 12px; color: #aaa; }   /* was 11px #888 */
.disclaimer-text { font-size: 13px; color: #ddd; }   /* was 12px #ccc */
.filter-label    { font-size: 12px; color: #aaa; }   /* was 11px #888 */
code { background: #2a2a2a; color: #e0e0e0; padding: 2px 6px; border-radius: 3px; font-size: 12px; }
.faq-content { color: #aaa; }
.faq-content ul li { color: #bbb; }
.info-box { color: #ccc; }

/* ─── 600 px breakpoint — general tablet/small screen ─── */
@media (max-width: 600px) {
    body { align-items: flex-start; padding: 12px; }
    .container { padding: 16px; border-radius: 12px; }

    /* Site nav: stack, language row right-aligned */
    .site-nav { flex-direction: column; align-items: stretch; gap: 8px; }
    .brand { text-align: center; }
    .nav-links { justify-content: center; }
    .lang-switch { justify-content: flex-end; width: 100%; }

    /* Header */
    .header h1 { font-size: 22px; }
    .header p  { font-size: 12px; letter-spacing: 0.5px; }
    .hero-text { font-size: 13px; }

    /* Sub-nav: scrollable single row, no wrapping */
    .sub-nav { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 6px; }
    .tab-btn { flex: 0 0 auto; font-size: 12px; padding: 7px 14px; }

    /* Stats grid: keep 3 columns but tighten */
    .stats-grid { gap: 6px; }
    .stat-val   { font-size: 16px; }

    /* Grid buttons (color/phase): 2-col */
    .grid-buttons { grid-template-columns: 1fr 1fr; gap: 8px; }

    /* Control panel inner padding */
    .control-panel { padding: 14px; }

    /* Leaderboard header stack */
    .leaderboard-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .filter-controls { flex-wrap: wrap; gap: 6px; }

    /* Color gamut: 2 cols on small screens */
    .gamut-grid { grid-template-columns: repeat(2, 1fr); }

    /* Gamepad: stack visualiser above data */
    .gp-container { flex-direction: column; }
    .gp-visualizer { min-width: 0; width: 100%; }
    .gp-data       { min-width: 0; width: 100%; }

    /* Step guide: wrap for very long labels */
    .step-guide { flex-wrap: wrap; }
    .step-item  { flex: 1 1 calc(50% - 5px); min-width: 0; font-size: 11px; padding: 8px; }

    /* Module cards & article cards: single column */
    .module-grid { grid-template-columns: 1fr; }
    .articles-grid { grid-template-columns: 1fr; }

    /* Footer links: wrap onto multiple lines, centred */
    .footer-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
    .footer-links a { margin: 0; font-size: 13px; }

    /* CTA group */
    .cta-group { flex-direction: column; gap: 8px; }
}

/* ─── 390 px breakpoint — iPhone SE / standard Android ─── */
@media (max-width: 390px) {
    body { padding: 8px; }
    .container { padding: 12px; border-radius: 10px; }

    /* Header: tighten further */
    .header { margin-bottom: 14px; padding-bottom: 12px; }
    .header h1 { font-size: 19px; letter-spacing: 0.5px; }
    .header p  { font-size: 11px; }

    /* Language buttons: slightly smaller touch targets */
    .lang-btn { padding: 5px 10px; font-size: 11px; }

    /* Nav pills: smaller so more fit before wrap */
    .nav-links a { font-size: 12px; padding: 4px 9px; }

    /* Sub-nav pills: smaller so 4-5 are visible before scroll */
    .tab-btn { font-size: 11px; padding: 6px 11px; border-radius: 12px; }

    /* Stats: keep 3-col, reduce value size */
    .stat-val   { font-size: 15px; }
    .stat-label { font-size: 11px; }
    .stat-sub   { font-size: 10px; color: #999; }

    /* Action buttons: comfortable 44px tap target */
    button.action-btn { padding: 13px 12px; font-size: 13px; }

    /* Disclaimer badge: tighter */
    .disclaimer-badge { padding: 8px; gap: 8px; }
    .disclaimer-icon  { font-size: 18px; }
    .disclaimer-text  { font-size: 12px; }

    /* Info-box: tighten padding */
    .info-box { padding: 12px; font-size: 12px; }

    /* FAQ content */
    .faq-content h3  { font-size: 14px; }
    .faq-content p, .faq-content li { font-size: 12px; line-height: 1.7; }

    /* Step guide: single column on very narrow screens */
    .step-item { flex: 1 1 100%; }

    /* Module card text */
    .module-card h2   { font-size: 17px; }
    .module-card p    { font-size: 12px; }

    /* Article card text */
    .article-card-title   { font-size: 14px; }
    .article-card-summary { font-size: 12px; }

    /* Footer */
    .footer { padding: 20px 12px; }
    .footer-links { gap: 8px; }
    .footer-links a { font-size: 12px; }
    .copyright { font-size: 11px; }

    /* Hero text block */
    .hero-text { font-size: 12px; line-height: 1.6; }

    /* Rank table: tighten cell padding */
    .rank-table td, .rank-table th { padding: 8px 5px; font-size: 12px; }

    /* Leaderboard filter pills: smaller */
    .filter-label { font-size: 11px; padding: 3px 7px; }

    /* Mouse zone height: reduce so it doesn't dominate the screen */
    #mouseZone { height: 150px; }

    /* Keyboard zone */
    #keyboardZone { min-height: 110px; padding: 10px; }
    .key-cap { font-size: 12px; padding: 4px 8px; }

    /* Gamepad body: scale down to fit 375px card */
    .gp-body { width: 260px; height: 165px; transform-origin: center; }
    .gp-visualizer { height: 240px; }
}

/* ─── Large display breakpoints — QHD / UHD monitors ───
   Windows display scaling shrinks the CSS viewport, so these min-widths
   target scaled QHD (~1700–2050 css px) and UHD (~1920–2560 css px).
   Widen the content column so test canvases get more room; stays centered. */
@media (min-width: 1700px) {
    .container { max-width: 1150px; padding: 40px; }
    .header h1 { font-size: 32px; }
}

@media (min-width: 2200px) {
    .container { max-width: 1350px; padding: 48px; }
    .header h1 { font-size: 36px; }
}
