/* ===================================================================
   /gyroscope-test - the motion stage.

   The phone's transform, the bubble's position and the compass rose's
   rotation are all written by gyroscope-test.js from sensor events (or,
   in the clearly labelled demo, from a mouse drag). data-mode on the
   root is waiting | live | nosensor | demo. Scoped under .gyt.
   =================================================================== */

.gyt {
    --gyt-accent: #3d8bff;
    --gyt-accent-2: #22d3ee;
    --gyt-ok: #34f5a6;
    --gyt-warn: #ffb547;
    --gyt-demo: #b58cff;
    --gyt-ink: #10162b;
    --gyt-muted: #5b6275;
    --gyt-line: #e4e7ef;
    --gyt-w: 150px;
    --gyt-h: 300px;
    --gyt-d: 16px;

    margin: 18px auto 24px;
    padding: 0;
    max-width: 1080px;
    border-radius: 28px;
    background: #fff;
    border: 1px solid var(--gyt-line);
    box-shadow: 0 30px 60px -32px rgb(16 22 43 / 45%);
    overflow: hidden;
    text-align: left;
    font-family: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--gyt-ink);
}
.gyt *, .gyt *::before, .gyt *::after { box-sizing: border-box; }
.gyt button { font: inherit; }
.gyt svg { display: block; }
.gyt [hidden] { display: none !important; }

.gyt-visually-hidden {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- top bar ---------- */

.gyt-topbar {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px;
    padding: 14px 22px;
    background: linear-gradient(180deg, #151b33, #10162b);
    color: #cdd5ee;
}
.gyt-detected { display: flex; align-items: center; gap: 8px; margin: 0; font-size: .9rem; font-weight: 500; }
.gyt-detected svg { width: 18px; height: 18px; flex: none; color: var(--gyt-accent-2); }
.gyt-devices { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: rgb(255 255 255 / 8%); }
.gyt-devices button {
    border: 0; border-radius: 999px; padding: 6px 12px; min-height: 32px;
    background: transparent; color: #aeb8d6; font-size: .8rem; font-weight: 600; cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
}
.gyt-devices button:hover { color: #fff; }
.gyt-devices button[aria-checked="true"] { background: #fff; color: var(--gyt-ink); }

/* ---------- stage ---------- */

.gyt-stage {
    position: relative;
    display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center;
    gap: clamp(10px, 3vw, 40px);
    padding: clamp(46px, 5vw, 60px) clamp(14px, 4vw, 44px) clamp(24px, 4vw, 40px);
    background:
        radial-gradient(45% 60% at 50% 55%, rgb(61 139 255 / 26%), transparent 70%),
        radial-gradient(30% 50% at 12% 30%, rgb(34 211 238 / 9%), transparent 70%),
        radial-gradient(30% 50% at 88% 30%, rgb(181 140 255 / 9%), transparent 70%),
        linear-gradient(180deg, #10162b 0%, #1a2142 100%);
    color: #dfe5f7;
    isolation: isolate;
}
.gyt-stage::after {
    content: ""; position: absolute; left: 6%; right: 6%; bottom: 16px; height: 1px; z-index: -1;
    background: linear-gradient(90deg, transparent, rgb(255 255 255 / 16%), transparent);
}

.gyt-badge {
    position: absolute; top: 14px; left: 16px;
    display: inline-flex; align-items: center; gap: 8px;
    padding: 5px 12px; border-radius: 999px;
    background: rgb(255 255 255 / 8%); border: 1px solid rgb(255 255 255 / 10%);
    font-size: .76rem; font-weight: 700; letter-spacing: .04em; color: #dfe5f7;
}
.gyt-badge i { width: 8px; height: 8px; border-radius: 50%; background: var(--gyt-warn); }
.gyt[data-mode="waiting"] .gyt-badge i { animation: gyt-blink 1s ease-in-out infinite alternate; }
.gyt[data-mode="live"] .gyt-badge i { background: var(--gyt-ok); box-shadow: 0 0 8px var(--gyt-ok); }
.gyt[data-mode="nosensor"] .gyt-badge i { background: #8b95b5; }
.gyt[data-mode="demo"] .gyt-badge { background: rgb(181 140 255 / 18%); border-color: rgb(181 140 255 / 45%); color: #e7dcff; }
.gyt[data-mode="demo"] .gyt-badge i { background: var(--gyt-demo); box-shadow: 0 0 8px var(--gyt-demo); }
@keyframes gyt-blink { to { opacity: .25; } }

/* ---------- the phone ---------- */

.gyt-scene {
    position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    width: clamp(220px, 28vw, 300px); height: 380px;
    perspective: 900px;
    touch-action: none; user-select: none;
}
.gyt[data-mode="nosensor"] .gyt-scene, .gyt[data-mode="demo"] .gyt-scene { cursor: grab; }
.gyt.is-dragging .gyt-scene { cursor: grabbing; }
/* An outline would trace the 3D faces overflowing the box; a ring on the box reads cleanly. */
.gyt-scene:focus { outline: none; }
.gyt-scene:focus-visible { border-radius: 24px; box-shadow: 0 0 0 3px rgb(34 211 238 / 70%); }

.gyt-phone {
    position: relative; width: var(--gyt-w); height: var(--gyt-h);
    transform-style: preserve-3d;
    will-change: transform;
}
.gyt-face { position: absolute; left: 0; top: 0; backface-visibility: hidden; }
.gyt-front, .gyt-back { width: var(--gyt-w); height: var(--gyt-h); border-radius: 26px; }
.gyt-front {
    transform: translateZ(calc(var(--gyt-d) / 2));
    background:
        radial-gradient(120% 70% at 20% 0%, rgb(61 139 255 / 55%), transparent 60%),
        radial-gradient(90% 60% at 100% 100%, rgb(34 211 238 / 35%), transparent 60%),
        #0a0e1c;
    border: 6px solid #1d2440;
    box-shadow: inset 0 0 0 1px rgb(255 255 255 / 10%);
}
.gyt-island { position: absolute; top: 10px; left: 50%; width: 46px; height: 12px; margin-left: -23px; border-radius: 999px; background: #000; }
.gyt-screen-axes { position: absolute; inset: 34px 18px 22px; }
.gyt-screen-axes svg { width: 100%; height: 100%; }
.gyt-back {
    transform: rotateY(180deg) translateZ(calc(var(--gyt-d) / 2));
    background: linear-gradient(145deg, #3a4163, #1d2440 60%, #151b33);
    border: 1px solid rgb(255 255 255 / 10%);
}
.gyt-camera {
    position: absolute; top: 14px; left: 14px; width: 48px; height: 48px; border-radius: 14px;
    background: #10162b; box-shadow: inset 0 0 0 2px #4a5378;
}
.gyt-camera::before, .gyt-camera::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #5a6280, #05070e 70%); }
.gyt-camera::before { top: 6px; left: 6px; }
.gyt-camera::after { bottom: 6px; right: 6px; }
.gyt-side { width: var(--gyt-d); height: var(--gyt-h); left: calc(var(--gyt-w) / 2 - var(--gyt-d) / 2); background: linear-gradient(180deg, #4a5378, #262b40); border-radius: 8px; }
.gyt-side--r { transform: rotateY(90deg) translateZ(calc(var(--gyt-w) / 2 - 2px)); }
.gyt-side--l { transform: rotateY(-90deg) translateZ(calc(var(--gyt-w) / 2 - 2px)); }
.gyt-edge { width: var(--gyt-w); height: var(--gyt-d); top: calc(var(--gyt-h) / 2 - var(--gyt-d) / 2); background: linear-gradient(90deg, #262b40, #4a5378, #262b40); border-radius: 8px; }
.gyt-edge--t { transform: rotateX(90deg) translateZ(calc(var(--gyt-h) / 2 - 2px)); }
.gyt-edge--b { transform: rotateX(-90deg) translateZ(calc(var(--gyt-h) / 2 - 2px)); }

.gyt-shadow {
    position: absolute; left: 50%; bottom: 8px; width: 170px; height: 26px; margin-left: -85px;
    border-radius: 50%; background: radial-gradient(closest-side, rgb(0 0 0 / 55%), transparent);
    transform: scaleX(var(--gyt-shadow, 1));
}

.gyt-drag-hint {
    position: absolute; left: 50%; bottom: -8px; transform: translateX(-50%);
    margin: 0; padding: 4px 12px; border-radius: 999px; white-space: nowrap;
    background: rgb(181 140 255 / 18%); border: 1px solid rgb(181 140 255 / 45%);
    font-size: .74rem; font-weight: 600; color: #e7dcff;
    opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.gyt[data-mode="nosensor"] .gyt-drag-hint, .gyt[data-mode="demo"] .gyt-drag-hint { opacity: 1; }

/* ---------- instruments ---------- */

.gyt-instrument { display: flex; flex-direction: column; align-items: center; gap: 10px; justify-self: center; }
.gyt-instrument-label { font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: #aeb8d6; }
.gyt-instrument-label b { margin-left: 4px; color: #fff; font-variant-numeric: tabular-nums; letter-spacing: 0; }
.gyt-heading-kind { margin-top: -6px; font-size: .72rem; color: #8b95b5; text-align: center; }

.gyt-level {
    --gyt-bx: 0; --gyt-by: 0;
    position: relative; width: clamp(130px, 16vw, 180px); aspect-ratio: 1; border-radius: 50%;
    background: radial-gradient(circle at 40% 35%, #1f3a3a, #0b1a1f 70%);
    border: 3px solid #2c3558;
    box-shadow: inset 0 8px 24px rgb(0 0 0 / 55%), 0 18px 30px -16px rgb(0 0 0 / 60%);
}
.gyt-level-ring { position: absolute; left: 50%; top: 50%; border-radius: 50%; border: 1.5px solid rgb(52 245 166 / 35%); transform: translate(-50%, -50%); }
.gyt-level-ring--1 { width: 22%; height: 22%; }
.gyt-level-ring--2 { width: 58%; height: 58%; border-style: dashed; border-color: rgb(52 245 166 / 18%); }
.gyt-level-cross::before, .gyt-level-cross::after { content: ""; position: absolute; background: rgb(255 255 255 / 10%); }
.gyt-level-cross::before { left: 50%; top: 6%; bottom: 6%; width: 1px; }
.gyt-level-cross::after { top: 50%; left: 6%; right: 6%; height: 1px; }
.gyt-bubble {
    position: absolute; left: 50%; top: 50%; width: 20%; height: 20%; margin: -10% 0 0 -10%; border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fff, #b9ffe2 35%, rgb(52 245 166 / 70%) 75%);
    box-shadow: 0 0 14px rgb(52 245 166 / 55%);
    transform: translate(calc(var(--gyt-bx) * 1px), calc(var(--gyt-by) * 1px));
}
.gyt-level.is-level { border-color: var(--gyt-ok); box-shadow: inset 0 8px 24px rgb(0 0 0 / 55%), 0 0 22px rgb(52 245 166 / 40%); }

.gyt-compass { position: relative; width: clamp(130px, 16vw, 180px); aspect-ratio: 1; }
.gyt-rose { width: 100%; height: 100%; filter: drop-shadow(0 18px 20px rgb(0 0 0 / 50%)); transition: transform .12s linear; }
.gyt-lubber { position: absolute; left: 50%; top: -8px; width: 0; height: 0; margin-left: -7px; border: 7px solid transparent; border-top: 11px solid var(--gyt-accent-2); }

/* ---------- panel ---------- */

.gyt-panel { padding: 22px clamp(16px, 4vw, 36px) 26px; }
.gyt-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.gyt-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 42px; padding: 0 16px; border-radius: 12px; cursor: pointer;
    border: 1px solid var(--gyt-line); background: #fff; color: var(--gyt-ink); font-weight: 600;
    transition: transform .12s ease, background-color .15s ease, opacity .15s ease;
}
.gyt-btn svg { width: 18px; height: 18px; }
.gyt-btn:hover { background: #f4f7ff; }
.gyt-btn:active { transform: scale(.96); }
.gyt-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.gyt-btn--primary { border: 0; color: #fff; background: linear-gradient(135deg, #5b9dff, var(--gyt-accent) 55%, #2254c9); box-shadow: 0 12px 24px -12px rgb(61 139 255 / 80%); }
.gyt-btn--primary:hover { background: linear-gradient(135deg, #6aa9ff, #4a94ff 55%, #2a5fd6); }
.gyt-btn.pop { animation: gyt-pop .3s ease; }
@keyframes gyt-pop { 50% { transform: scale(1.08); } }
.gyt button:focus-visible { outline: 3px solid var(--gyt-accent); outline-offset: 2px; }
.gyt-devices button:focus-visible { outline-color: var(--gyt-accent-2); }

.gyt-status {
    margin: 16px 0 0; padding: 12px 16px; border-radius: 14px;
    background: #f4f7ff; border: 1px solid #dce6fb; font-weight: 600; color: #1d3a7a;
}
.gyt[data-mode="nosensor"] .gyt-status, .gyt[data-mode="demo"] .gyt-status { background: #f7f2ff; border-color: #e3d6fb; color: #4b2a86; }
.gyt[data-mode="live"] .gyt-status { background: #eefcf5; border-color: #c9f0dc; color: #0f5a37; }

.gyt-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-top: 16px; }
.gyt-card { min-width: 0; padding: 14px 16px; border-radius: 18px; background: #f6f8fc; border: 1px solid var(--gyt-line); }
.gyt-card h3 { margin: 0 0 8px; font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--gyt-muted); }
.gyt-card h3 small { font-size: .7rem; letter-spacing: 0; text-transform: none; font-weight: 500; color: #8a91a4; margin-left: 4px; }
.gyt-axis { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 10px; padding: 6px 0; border-bottom: 1px dashed var(--gyt-line); }
.gyt-axis:last-child { border-bottom: 0; }
.gyt-axis span { font-size: .88rem; color: #454d63; }
.gyt-axis em { font-style: normal; font-size: .75rem; color: #8a91a4; margin-left: 4px; }
.gyt-axis b { font-variant-numeric: tabular-nums; font-weight: 800; }
.gyt-axis-bar { grid-column: 1 / -1; position: relative; display: block; height: 5px; border-radius: 999px; background: #e3e7f1; overflow: hidden; }
.gyt-axis-bar i { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; background: linear-gradient(90deg, var(--gyt-accent-2), var(--gyt-accent)); border-radius: inherit; }

.gyt-xyz { display: flex; gap: 12px; flex-wrap: wrap; font-size: .82rem; font-weight: 700; }
.gyt-xyz b { font-variant-numeric: tabular-nums; color: var(--gyt-ink); margin-left: 2px; }
.gyt-x { color: #e5485a; } .gyt-y { color: #16a36b; } .gyt-z { color: #2f6fe0; }
.gyt-chart { display: block; width: 100%; height: 96px; margin-top: 8px; border-radius: 12px; background: #fff; border: 1px solid var(--gyt-line); }

.gyt-sensors { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 0; padding: 0; list-style: none; }
.gyt-sensors li {
    display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px;
    background: #f1f3f8; border: 1px solid var(--gyt-line); font-size: .8rem; font-weight: 600; color: #8a91a4;
}
.gyt-sensors li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #c7ccd8; }
.gyt-sensors li.is-on { background: #eefcf5; border-color: #c9f0dc; color: #0f5a37; }
.gyt-sensors li.is-on::before { background: #16c47f; }

.gyt-note { margin: 12px 0 0; font-size: .88rem; color: var(--gyt-muted); }
.gyt-note:empty { display: none; }

/* ---------- responsive ---------- */

@media (max-width: 860px) {
    .gyt-grid { grid-template-columns: 1fr 1fr; }
    .gyt-grid .gyt-card:nth-child(2) { grid-column: 1 / -1; grid-row: 1; }
}
@media (max-width: 680px) {
    .gyt-stage { grid-template-columns: 1fr 1fr; }
    .gyt-scene { grid-column: 1 / -1; grid-row: 1; justify-self: center; }
}
@media (max-width: 575.98px) {
    .gyt { --gyt-w: 120px; --gyt-h: 240px; --gyt-d: 13px; border-radius: 22px; margin-inline: -4px; }
    .gyt-topbar { padding: 12px 14px; }
    .gyt-devices { width: 100%; justify-content: space-between; }
    .gyt-devices button { flex: 1; }
    .gyt-scene { height: 310px; width: 100%; }
    .gyt-level, .gyt-compass { width: 118px; }
    .gyt-grid { grid-template-columns: 1fr; }
    .gyt-grid .gyt-card:nth-child(2) { grid-column: auto; grid-row: auto; }
    .gyt-actions .gyt-btn { flex: 1 1 calc(50% - 5px); padding: 0 10px; }
    .gyt-drag-hint { white-space: normal; width: max-content; max-width: 92%; text-align: center; }
}

@media (pointer: coarse) {
    .gyt-devices button, .gyt-btn { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
    .gyt *, .gyt *::before, .gyt *::after { animation: none !important; transition: none !important; }
}
