/* ==========================================================================
   MyCloudGame / YiLink - "Signal Horizon" base
   Shared by the admin console and the public play surfaces.
   Implements website-visual-design.md sections 4-7, 10-11. Dark single theme.
   ========================================================================== */

/* ---------- Fonts (self-hosted, latin subset, OFL) ---------- */
@font-face {
    font-family: "Archivo";
    src: url("../fonts/archivo-latin-var.woff2") format("woff2");
    font-weight: 100 900;
    font-stretch: 62% 125%;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "IBM Plex Mono";
    src: url("../fonts/plex-mono-400-latin.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "IBM Plex Mono";
    src: url("../fonts/plex-mono-500-latin.woff2") format("woff2");
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

/* ---------- Tokens ---------- */
:root {
    color-scheme: dark;

    /* night base */
    --bg-0: #060d17;
    --bg: #09121f;
    --bg-1: #0c1928;
    --bg-2: rgba(16, 34, 51, 0.4);
    --line: rgba(167, 207, 255, 0.14);
    --line-strong: rgba(167, 207, 255, 0.24);

    /* text */
    --text: #e9f3ff;
    --text-soft: rgba(233, 243, 255, 0.72);
    --text-dim: rgba(233, 243, 255, 0.45);
    --text-on-accent: #04202f;

    /* brand + semantics */
    --accent: #86d7ff;
    --accent-hi: #b3e5ff;
    --accent-dim: rgba(134, 215, 255, 0.16);
    --accent-strong: #e0a14a;
    --success: #68d9ac;
    --danger: #ff7b7b;
    --warning: #e0a14a;
    --focus: #b3e5ff;

    /* depth: tinted soft shadows only, no glow */
    --shadow-1: 0 1px 2px rgba(2, 6, 11, 0.8);
    --shadow-2: 0 12px 32px -12px rgba(2, 6, 11, 0.7);
    --shadow-cta: 0 6px 20px -6px rgba(134, 215, 255, 0.25);

    /* shape discipline: 10 / 16 / 22 */
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 22px;

    /* type scale */
    --fs-display: clamp(2.25rem, 4vw, 3.25rem);
    --fs-h2: clamp(1.5rem, 2.4vw, 2rem);
    --fs-h3: 1.25rem;
    --fs-body: 1rem;
    --fs-small: 0.875rem;
    --fs-mono: 0.8125rem;

    --font-display: "Archivo", "Avenir Next", "Gill Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --font-zh: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;

    --header-h: 64px;

    /* legacy aliases kept so console markup/inline styles keep working */
    --font-sans: var(--font-body);
    --font-wide: var(--font-display);
    --bg-soft: rgba(9, 18, 31, 0.78);
    --ink: var(--text);
    --ink-soft: var(--text-soft);
    --ink-dim: var(--text-dim);
    --ink-faint: rgba(233, 243, 255, 0.28);
    --card: var(--bg-2);
    --card-strong: var(--bg-1);
    --panel: var(--bg-2);
    --panel-strong: var(--bg-1);
    --accent-deep: #6ec6f5;
    --accent-soft: var(--accent-dim);
    --focus-ring: 0 0 0 3px rgba(134, 215, 255, 0.2);
    --shadow-sm: var(--shadow-1);
    --shadow-md: var(--shadow-2);
    --shadow-lg: var(--shadow-2);
    --shadow: var(--shadow-2);
    --radius-xl: var(--radius-lg);
}

/* ---------- Reset ---------- */
* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100dvh;
    font-family: var(--font-body);
    font-size: var(--fs-body);
    line-height: 1.7;
    color: var(--text);
    background:
        radial-gradient(1100px 520px at 78% -10%, rgba(27, 74, 110, 0.22), transparent 60%),
        radial-gradient(900px 480px at 12% 8%, rgba(18, 57, 90, 0.18), transparent 60%),
        radial-gradient(1400px 300px at 50% 118%, rgba(224, 161, 74, 0.08), transparent 65%),
        linear-gradient(180deg, var(--bg) 0%, var(--bg-0) 100%);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

:lang(zh) body {
    font-size: 1.0625rem;
    line-height: 1.75;
}

img,
svg,
video {
    display: block;
    max-width: 100%;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 160ms ease;
}
a:hover {
    color: var(--accent-hi);
}

button,
input,
textarea,
select {
    font: inherit;
    color: inherit;
}

button {
    border: 0;
    background: none;
    padding: 0;
    cursor: pointer;
}

ul,
ol {
    padding: 0;
    list-style: none;
}

::selection {
    background: var(--accent-dim);
    color: var(--text);
}

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
    border-radius: 4px;
}

::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(167, 207, 255, 0.16);
    border: 3px solid transparent;
    border-radius: 999px;
    background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(167, 207, 255, 0.28);
    background-clip: content-box;
}

/* ---------- Typography ---------- */
h1,
h2,
h3,
h4 {
    font-family: var(--font-display);
    font-weight: 600;
    color: var(--text);
    text-wrap: balance;
    margin: 0;
}
h1 {
    font-size: var(--fs-display);
    font-stretch: 125%;
    letter-spacing: -0.01em;
    line-height: 1.08;
}
h2 {
    font-size: var(--fs-h2);
    line-height: 1.15;
}
h3 {
    font-size: var(--fs-h3);
    line-height: 1.3;
}
:lang(zh) h1,
:lang(zh) h2,
:lang(zh) h3,
:lang(zh) h4 {
    font-family: var(--font-zh);
    font-stretch: normal;
    letter-spacing: 0.02em;
}

p {
    color: var(--text-soft);
    max-width: 65ch;
}

strong {
    font-weight: 600;
}

code,
kbd,
samp {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background: var(--bg-0);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0.1em 0.4em;
}

pre {
    margin: 0;
    background: var(--bg-0);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    overflow: auto;
}
pre code {
    background: none;
    border: 0;
    padding: 0;
}

/* technical annotation */
.mono {
    font-family: var(--font-mono);
    font-size: var(--fs-mono);
    font-weight: 500;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 8px;
    font-family: var(--font-mono);
    font-size: var(--fs-mono);
    font-weight: 500;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.lead {
    margin: 0;
    max-width: 65ch;
    font-size: var(--fs-small);
    line-height: 1.7;
    color: var(--text-soft);
}

/* ---------- Language switch (capsule EN | 中) ---------- */
.lang-switch {
    display: inline-flex;
    overflow: hidden;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    background: transparent;
}
.lang-switch button {
    padding: 6px 14px;
    border: 0;
    background: transparent;
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.06em;
    cursor: pointer;
    transition: background-color 160ms ease, color 160ms ease;
}
.lang-switch button:hover {
    color: var(--text);
}
.lang-switch button.active {
    background: var(--accent-dim);
    color: var(--accent);
}
.lang-switch button + button {
    border-left: 1px solid var(--line);
}

/* ---------- Signature horizon light band ---------- */
.horizon {
    height: 1px;
    border: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(134, 215, 255, 0.35) 30%,
        #86d7ff 50%,
        rgba(134, 215, 255, 0.35) 70%,
        transparent
    );
}

.horizon-breathe {
    animation: horizon-breathe 4s ease-in-out infinite;
}
@keyframes horizon-breathe {
    0%,
    100% {
        opacity: 0.7;
    }
    50% {
        opacity: 1;
    }
}

/* ---------- Engineering grid texture ---------- */
.grid-texture {
    position: relative;
}
.grid-texture::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(167, 207, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(167, 207, 255, 0.03) 1px, transparent 1px);
    background-size: 48px 48px;
    -webkit-mask-image: radial-gradient(70% 70% at 50% 40%, #000 30%, transparent 100%);
    mask-image: radial-gradient(70% 70% at 50% 40%, #000 30%, transparent 100%);
}

/* ---------- Buttons ---------- */
.button,
.button-secondary,
.button-danger,
.button-ghost,
.button-inline,
.btn,
.btn-primary,
.btn-ghost,
.btn-text {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 18px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-weight: 600;
    font-size: var(--fs-small);
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
    transition: transform 180ms ease, box-shadow 180ms ease, background-color 180ms ease,
        border-color 180ms ease, color 180ms ease, filter 180ms ease;
}

.button,
.btn-primary {
    background: linear-gradient(135deg, #9edfff, #6ec6f5);
    color: var(--text-on-accent);
    box-shadow: var(--shadow-cta);
}
.button:hover,
.btn-primary:hover {
    color: var(--text-on-accent);
    filter: brightness(1.06);
    transform: translateY(-1px);
}

.button-secondary {
    background: linear-gradient(135deg, #f0b76a, var(--accent-strong));
    color: #2a1604;
    box-shadow: var(--shadow-cta);
}
.button-secondary:hover {
    color: #2a1604;
    filter: brightness(1.05);
    transform: translateY(-1px);
}

.button-danger {
    background: transparent;
    border-color: rgba(255, 123, 123, 0.4);
    color: var(--danger);
}
.button-danger:hover {
    background: rgba(255, 123, 123, 0.12);
    border-color: rgba(255, 123, 123, 0.6);
    color: var(--danger);
}

.button-ghost,
.button-inline,
.btn-ghost {
    background: transparent;
    border-color: var(--line-strong);
    color: var(--text);
}
.button-ghost:hover,
.button-inline:hover,
.btn-ghost:hover {
    background: var(--accent-dim);
    border-color: var(--line-strong);
    color: var(--text);
}

.btn-text {
    background: none;
    border: 0;
    padding: 0;
    min-height: 0;
    color: var(--accent);
}
.btn-text:hover {
    color: var(--accent-hi);
}
.btn-text .arrow {
    display: inline-block;
    transition: transform 180ms ease;
}
.btn-text:hover .arrow {
    transform: translateX(4px);
}

.button:active,
.button-secondary:active,
.button-danger:active,
.button-ghost:active,
.button-inline:active,
.btn:active {
    transform: translateY(1px);
}

.button-inline,
.btn-sm {
    min-height: 32px;
    padding: 0 13px;
    font-size: 0.82rem;
}

.button[disabled],
.button-secondary[disabled],
.button-danger[disabled],
.button-ghost[disabled],
.button-inline[disabled],
.btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    line-height: 1;
    transition: color 140ms ease, background-color 140ms ease;
}
.icon-btn:hover {
    color: var(--accent);
    background: var(--accent-dim);
}
.icon-btn.danger:hover {
    color: var(--danger);
    background: rgba(255, 123, 123, 0.12);
}
.icon-btn:active {
    transform: scale(0.94);
}

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: rgba(233, 243, 255, 0.04);
    color: var(--text-soft);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
}
.badge-green,
.badge-active {
    background: rgba(104, 217, 172, 0.12);
    border-color: rgba(104, 217, 172, 0.28);
    color: var(--success);
}
.badge-red,
.badge-inactive {
    background: rgba(255, 123, 123, 0.12);
    border-color: rgba(255, 123, 123, 0.28);
    color: var(--danger);
}
.badge-warning {
    background: rgba(224, 161, 74, 0.14);
    border-color: rgba(224, 161, 74, 0.32);
    color: var(--accent-strong);
}
.badge-gray {
    background: rgba(233, 243, 255, 0.04);
    border-color: var(--line);
    color: var(--text-dim);
}
.badge-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    margin-left: 4px;
    border-radius: var(--radius-sm);
    background: var(--danger);
    color: #1a0505;
    font-size: 0.7rem;
}

/* ---------- Status pill ---------- */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 24px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    background: rgba(233, 243, 255, 0.04);
    color: var(--text-soft);
    white-space: nowrap;
}
.status-pill::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.85;
}
.status-pill.status-active,
.status-pill.status-connected,
.status-pill.status-online,
.status-pill.status-healthy {
    background: rgba(104, 217, 172, 0.12);
    border-color: rgba(104, 217, 172, 0.28);
    color: var(--success);
}
.status-pill.status-failed,
.status-pill.status-error,
.status-pill.status-offline,
.status-pill.status-unhealthy,
.status-pill.status-disabled,
.status-pill.status-expired {
    background: rgba(255, 123, 123, 0.12);
    border-color: rgba(255, 123, 123, 0.28);
    color: var(--danger);
}
.status-pill.status-warning,
.status-pill.status-pending,
.status-pill.status-negotiating,
.status-pill.status-connecting {
    background: rgba(224, 161, 74, 0.14);
    border-color: rgba(224, 161, 74, 0.32);
    color: var(--accent-strong);
}

/* ---------- Forms ---------- */
.field-group,
.settings-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.field-group label,
.settings-field label {
    font-size: var(--fs-small);
    color: var(--text-dim);
}
.field-hint {
    font-size: 12px;
    color: var(--text-dim);
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
    width: 100%;
    min-height: 40px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong);
    background: var(--bg-1);
    color: var(--text);
    font-size: var(--fs-small);
    transition: border-color 180ms ease, box-shadow 180ms ease, background-color 180ms ease;
}
input:not([type="checkbox"]):not([type="radio"])::placeholder,
textarea::placeholder {
    color: var(--text-dim);
}
input:not([type="checkbox"]):not([type="radio"]):focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--focus);
    background: var(--bg-1);
    box-shadow: 0 0 0 2px rgba(134, 215, 255, 0.2);
}

input[type="checkbox"] {
    accent-color: var(--accent);
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
}

/* label wrappers containing a checkbox become tidy rows */
label:has(> input[type="checkbox"]) {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    min-height: 40px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: rgba(233, 243, 255, 0.03);
    color: var(--text);
    font-size: var(--fs-small);
    font-weight: 500;
    cursor: pointer;
    transition: background-color 170ms ease, border-color 170ms ease;
}
label:has(> input[type="checkbox"]):hover {
    background: var(--accent-dim);
    border-color: var(--line-strong);
}

/* decorative ambience layers (legacy markup): tint only, never blur */
.page-glow {
    position: fixed;
    pointer-events: none;
    z-index: 0;
    opacity: 0.5;
}
.page-glow-left {
    top: -12vh;
    left: -12vw;
    width: 34vw;
    height: 34vw;
    background: radial-gradient(circle, rgba(134, 215, 255, 0.14) 0%, transparent 70%);
}
.page-glow-right {
    right: -14vw;
    bottom: -16vh;
    width: 34vw;
    height: 34vw;
    background: radial-gradient(circle, rgba(224, 161, 74, 0.1) 0%, transparent 70%);
}

/* ---------- Motion helpers ---------- */
.fade-in {
    animation: fade-in 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.25;
    }
}

/* ---------- Responsive ---------- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 32px;
}

@media (max-width: 640px) {
    .container {
        padding: 0 20px;
    }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0ms !important;
        scroll-behavior: auto !important;
    }
    .fade-in,
    .reveal {
        opacity: 1;
        transform: none;
    }
    .horizon-breathe {
        animation: none;
    }
}
