:root {
  color-scheme: light;
  --ink: var(--tg-theme-text-color, #172033);
  --muted: var(--tg-theme-hint-color, #657087);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --background: var(--tg-theme-bg-color, #eef3fb);
  --line: #dfe6f1;
  --blue: var(--tg-theme-button-color, #1685e6);
  --blue-deep: #0868c1;
  --green: #18a957;
  --green-soft: #e7f8ed;
  --amber: #c97900;
  --amber-soft: #fff4dc;
  --red: #c52f38;
  --red-soft: #ffebed;
  --shadow: 0 14px 40px rgba(34, 59, 96, .10);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--background);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button { color: inherit; font: inherit; }
button:disabled { cursor: wait; filter: saturate(.5); opacity: .65; }
button:focus-visible { outline: 3px solid #8bd2ff; outline-offset: 3px; }

#app { min-height: 100dvh; }
.app-shell {
  width: 100%;
  max-width: 520px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(15px, env(safe-area-inset-top)) 14px calc(94px + env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 92% 2%, rgba(22, 133, 230, .16), transparent 25%),
    linear-gradient(180deg, #f7faff 0%, #edf3fb 100%);
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: 3px 2px 14px;
}
.eyebrow {
  margin: 0 0 3px;
  color: var(--blue-deep);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.app-header h1 { margin: 0 0 4px; font-size: 27px; line-height: 1.08; letter-spacing: -.6px; }
.header-date { margin: 0; color: var(--muted); font-size: 13px; }
.refresh-button {
  width: 43px;
  height: 43px;
  border: 1px solid rgba(255,255,255,.9);
  border-radius: 14px;
  background: rgba(255,255,255,.84);
  box-shadow: 0 6px 18px rgba(40, 74, 120, .08);
  color: var(--blue-deep);
  font-size: 21px;
  cursor: pointer;
}
.refresh-button.loading { animation: turn .8s linear infinite; }
@keyframes turn { to { transform: rotate(360deg); } }

.summary-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 9px 11px;
  border: 1px solid #d9e4f2;
  border-radius: 13px;
  background: rgba(255,255,255,.76);
  color: #50627d;
  font-size: 12px;
}
.summary-strip strong { margin-left: auto; color: var(--green); white-space: nowrap; }
.summary-strip strong.waiting { color: var(--amber); }

.device-list { display: grid; gap: 11px; }
.device-card {
  --device-accent: var(--blue);
  position: relative;
  padding: 15px;
  overflow: hidden;
  border: 1px solid rgba(216, 226, 240, .94);
  border-radius: 22px;
  background: rgba(255,255,255,.97);
  box-shadow: var(--shadow);
}
.device-card[data-id="pc-2"] { --device-accent: #20a995; }
.device-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--device-accent); }
.device-top, .time-row, .fact-row, .actions, .detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
}
.device-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pc-icon { width: 32px; height: 32px; flex: 0 0 auto; border-radius: 10px; display: grid; place-items: center; background: #edf5ff; font-size: 16px; }
.device-card[data-id="pc-2"] .pc-icon { background: #e7f8f4; }
.device-name strong { display: block; font-size: 15px; }
.device-host { display: block; color: var(--muted); font-size: 11px; }
.online-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--green-soft);
  color: #087b3b;
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
}
.online-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px rgba(24,169,87,.13); }
.online-pill.offline { background: #edf0f4; color: #6b7482; }
.online-pill.ended { background: var(--red-soft); color: var(--red); }

.time-row { align-items: flex-end; margin-top: 14px; }
.time-main span { display: block; color: var(--muted); font-size: 11px; }
.time-main strong { display: block; margin-top: 2px; font-size: 29px; line-height: 1; letter-spacing: -.8px; font-variant-numeric: tabular-nums; }
.usage-copy { text-align: right; color: var(--muted); font-size: 11px; }
.usage-copy b { display: block; margin-top: 3px; color: var(--ink); font-size: 12px; }
.progress-track { height: 8px; margin: 11px 0 10px; overflow: hidden; border-radius: 999px; background: #edf1f6; }
.progress-bar { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--device-accent), #5ab8ff); transition: width .35s ease; }
.device-card[data-id="pc-2"] .progress-bar { background: linear-gradient(90deg, #20a995, #5ed3c0); }
.fact-row { min-height: 29px; margin-bottom: 11px; }
.game-now { min-width: 0; overflow: hidden; color: #46556d; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.game-now b { color: var(--ink); }
.sync-state { flex: 0 0 auto; color: var(--green); font-size: 11px; font-weight: 750; white-space: nowrap; }
.sync-state.waiting { color: var(--amber); }
.sync-state.error, .sync-state.offline { color: #707987; }
.actions { gap: 7px; }
.action-button { min-height: 40px; border: 0; border-radius: 12px; padding: 9px 11px; cursor: pointer; font-weight: 750; transition: transform .12s ease; }
.action-button:active { transform: scale(.97); }
.action-button.add { flex: 1; background: var(--green); color: white; }
.action-button.add.alt { background: #128ddd; }
.action-button.detail { background: #edf2f8; color: #39465a; }

.view-title { margin: 4px 2px 12px; }
.view-title h2 { margin: 0 0 3px; font-size: 22px; }
.view-title p { margin: 0; color: var(--muted); font-size: 13px; }
.content-card { margin-bottom: 10px; padding: 14px; border: 1px solid var(--line); border-radius: 17px; background: rgba(255,255,255,.96); box-shadow: 0 8px 24px rgba(34,59,96,.07); }
.content-card h3 { margin: 0 0 7px; font-size: 15px; }
.content-card p { margin: 4px 0; color: #4e5a70; font-size: 13px; line-height: 1.4; }
.content-card time { color: var(--muted); font-size: 11px; }
.empty-state { padding: 28px 18px; text-align: center; color: var(--muted); }
.empty-state b { display: block; margin-bottom: 5px; color: var(--ink); }
.primary-wide { width: 100%; min-height: 45px; margin-top: 4px; border: 0; border-radius: 14px; background: var(--blue); color: white; font-weight: 750; cursor: pointer; }

.bottom-nav {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  max-width: 520px;
  margin: 0 auto;
  padding: 8px 5px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(208,219,234,.95);
  background: rgba(251,253,255,.94);
  backdrop-filter: blur(18px);
}
.nav-button { min-width: 0; border: 0; background: transparent; color: #738096; font-size: 10px; cursor: pointer; }
.nav-button span { display: block; height: 25px; font-size: 20px; line-height: 23px; }
.nav-button.active { color: var(--blue-deep); font-weight: 750; }

.scrim { position: fixed; z-index: 40; inset: 0; background: rgba(16,26,42,.42); opacity: 0; pointer-events: none; transition: opacity .18s ease; }
.scrim.open { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; z-index: 41; right: 0; bottom: 0; left: 0; max-width: 520px; max-height: 85dvh; margin: 0 auto; padding: 9px 16px calc(18px + env(safe-area-inset-bottom)); overflow-y: auto; border-radius: 24px 24px 0 0; background: white; box-shadow: 0 -14px 50px rgba(14,29,53,.2); transform: translateY(105%); transition: transform .22s ease; }
.sheet.open { transform: translateY(0); }
.sheet-handle { width: 42px; height: 4px; margin: 0 auto 14px; border-radius: 99px; background: #d7dee9; }
.sheet h2 { margin: 0 0 8px; font-size: 21px; }
.sheet-lead { margin: 0 0 14px; color: #536077; font-size: 13px; line-height: 1.45; }
.change-box { margin: 11px 0 15px; padding: 13px; border-radius: 15px; background: #f2f6fb; }
.change-box small { display: block; margin-bottom: 8px; color: var(--muted); }
.change-values { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 17px; }
.change-values b { color: var(--green); }
.detail-list { display: grid; gap: 0; margin: 8px 0 16px; }
.detail-row { padding: 10px 0; border-bottom: 1px solid #edf0f4; font-size: 13px; }
.detail-row span { color: var(--muted); }
.detail-row b { max-width: 58%; text-align: right; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1.25fr; gap: 8px; }
.sheet-button { min-height: 45px; border: 0; border-radius: 14px; font-weight: 750; cursor: pointer; }
.sheet-button.ghost { background: #edf2f8; }
.sheet-button.primary { background: var(--green); color: white; }

.toast { position: fixed; z-index: 50; top: calc(12px + env(safe-area-inset-top)); right: 12px; left: 12px; display: flex; align-items: center; gap: 10px; max-width: 480px; margin: 0 auto; padding: 12px; border: 1px solid #d9e3ef; border-radius: 15px; background: white; box-shadow: 0 14px 35px rgba(25,43,72,.18); opacity: 0; transform: translateY(-120%); transition: .2s ease; pointer-events: none; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast-icon { width: 30px; height: 30px; flex: 0 0 auto; border-radius: 50%; display: grid; place-items: center; background: var(--amber-soft); color: var(--amber); font-weight: 850; }
.toast.applied .toast-icon { background: var(--green-soft); color: var(--green); }
.toast.error .toast-icon { background: var(--red-soft); color: var(--red); }
.toast-copy strong, .toast-copy span { display: block; }
.toast-copy strong { font-size: 13px; }
.toast-copy span { margin-top: 2px; color: var(--muted); font-size: 11px; }

.startup-card { width: calc(100% - 28px); max-width: 440px; margin: 20vh auto 0; padding: 28px 22px; border: 1px solid var(--line); border-radius: 22px; background: white; box-shadow: var(--shadow); text-align: center; }
.startup-card h1 { margin: 12px 0 5px; font-size: 24px; }
.startup-card p { margin: 0; color: var(--muted); line-height: 1.45; }
.startup-card.error h1 { color: var(--red); }
.spinner { display: inline-block; width: 28px; height: 28px; border: 3px solid #dfeaf7; border-top-color: var(--blue); border-radius: 50%; animation: turn .8s linear infinite; }

/* Вариант 2: тёмный двойной кокпит */
body[data-concept="cockpit"] {
  color-scheme: dark;
  --ink: #f4f7ff;
  --muted: #9cacc9;
  --surface: #162441;
  --background: #0b1428;
  --line: #2b3b59;
  --blue: #34a8ff;
  --blue-deep: #69c2ff;
  --green: #2bd77f;
  --green-soft: rgba(43, 215, 127, .13);
  --amber: #ffb63a;
  --amber-soft: rgba(255, 182, 58, .14);
  --red: #ff6670;
  --red-soft: rgba(255, 102, 112, .14);
  --shadow: 0 18px 46px rgba(0, 0, 0, .25);
  background: #0b1428;
}

body[data-concept="cockpit"] .app-shell {
  background:
    linear-gradient(rgba(92, 148, 213, .025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(92, 148, 213, .025) 1px, transparent 1px),
    radial-gradient(circle at 50% -5%, rgba(40, 125, 215, .29), transparent 32%),
    linear-gradient(180deg, #101d37 0%, #0a1428 100%);
  background-size: 22px 22px, 22px 22px, auto, auto;
}

body[data-concept="cockpit"] .eyebrow { color: #69c2ff; }
body[data-concept="cockpit"] .refresh-button {
  border-color: #2a4267;
  background: rgba(21, 38, 68, .82);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .18);
  color: #73c8ff;
}

body[data-concept="cockpit"] .summary-strip {
  border-color: #2a3f61;
  background: rgba(20, 35, 62, .78);
  color: #b6c5db;
}

.cockpit-grid { display: grid; gap: 11px; }
.cockpit-panel {
  padding: 14px;
  border: 1px solid #294064;
  border-radius: 23px;
  background: linear-gradient(145deg, rgba(27, 45, 76, .98), rgba(16, 30, 54, .98));
  box-shadow: 0 16px 40px rgba(0, 0, 0, .23), inset 0 1px rgba(255,255,255,.035);
}
.cockpit-panel[data-id="pc-2"] {
  border-color: #28535c;
  background: linear-gradient(145deg, rgba(24, 60, 69, .97), rgba(15, 36, 52, .98));
}
.cockpit-top { display: flex; justify-content: space-between; align-items: center; gap: 9px; }
.cockpit-name { min-width: 0; }
.cockpit-name strong { display: block; color: #fff; font-size: 16px; }
.cockpit-name span { display: block; margin-top: 2px; color: #aebed7; font-size: 12px; }
body[data-concept="cockpit"] .online-pill { background: rgba(43, 215, 127, .13); color: #55e696; }
body[data-concept="cockpit"] .online-pill.offline { background: rgba(156, 172, 201, .12); color: #a5b1c6; }
body[data-concept="cockpit"] .online-pill.ended { background: rgba(255, 102, 112, .13); color: #ff7c85; }

.cockpit-core {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  align-items: center;
  gap: 15px;
  margin: 12px 0;
}
.time-ring {
  width: 126px;
  aspect-ratio: 1;
  padding: 9px;
  border-radius: 50%;
  background: conic-gradient(#34a8ff var(--ring), rgba(255,255,255,.085) 0);
  box-shadow: 0 0 30px rgba(52, 168, 255, .13);
}
.cockpit-panel[data-id="pc-2"] .time-ring {
  background: conic-gradient(#39d8be var(--ring), rgba(255,255,255,.085) 0);
  box-shadow: 0 0 30px rgba(57, 216, 190, .11);
}
.time-ring > div {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,.035);
  border-radius: 50%;
  background: #111f39;
}
.cockpit-panel[data-id="pc-2"] .time-ring > div { background: #122a37; }
.time-ring small, .time-ring span { color: #9cacc9; font-size: 12px; }
.time-ring strong { margin: 3px 0; color: #fff; font-size: 28px; line-height: 1; letter-spacing: -.8px; font-variant-numeric: tabular-nums; }
.time-ring span b { color: #dce7f8; }
.cockpit-facts { min-width: 0; }
.cockpit-facts p { margin: 12px 0; color: #dce6f5; font-size: 14px; line-height: 1.45; }
.cockpit-facts p b { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.cockpit-facts p small { color: #9cacc9; font-size: 12px; }
.cockpit-facts button { border: 0; padding: 4px 0; background: transparent; color: #70c1ff; font-size: 13px; font-weight: 700; cursor: pointer; }
body[data-concept="cockpit"] .sync-state.error,
body[data-concept="cockpit"] .sync-state.offline { color: #a5b1c6; }
.cockpit-actions { display: grid; grid-template-columns: .8fr 1.2fr; gap: 8px; }
.cockpit-actions button { min-height: 44px; border: 1px solid #3b8fc7; border-radius: 13px; background: #173856; color: #dff2ff; font-size: 14px; font-weight: 800; cursor: pointer; transition: transform .12s ease, filter .12s ease; }
.cockpit-actions button:last-child { border-color: #228860; background: #155238; color: #d9ffeb; }
.cockpit-actions button:active { transform: scale(.98); }

body[data-concept="cockpit"] .content-card {
  border-color: #2a3f61;
  background: rgba(20, 35, 62, .92);
  box-shadow: 0 12px 30px rgba(0,0,0,.18);
}
body[data-concept="cockpit"] .content-card p { color: #c2cee0; font-size: 14px; }
body[data-concept="cockpit"] .content-card time { color: #9cacc9; font-size: 12px; }
body[data-concept="cockpit"] .primary-wide { background: #197fc2; color: #fff; }

body[data-concept="cockpit"] .bottom-nav {
  border-color: #253753;
  background: rgba(10, 20, 39, .95);
}
body[data-concept="cockpit"] .nav-button { min-height: 48px; color: #8392aa; }
body[data-concept="cockpit"] .nav-button.active { color: #74c7ff; font-weight: 800; }

body[data-concept="cockpit"] .scrim { background: rgba(2, 8, 18, .68); }
body[data-concept="cockpit"] .sheet {
  border: 1px solid #2d4263;
  border-bottom: 0;
  background: #14233e;
  color: #f4f7ff;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, .45);
}
body[data-concept="cockpit"] .sheet-handle { background: #41506a; }
body[data-concept="cockpit"] .sheet-lead { color: #adbad0; font-size: 14px; }
body[data-concept="cockpit"] .change-box { border: 1px solid #314667; background: #1a2b49; }
body[data-concept="cockpit"] .detail-row { border-color: #314667; }
body[data-concept="cockpit"] .sheet-button.ghost { background: #293a56; color: #e5edfa; }
body[data-concept="cockpit"] .sheet-button.primary { background: #1c9f61; color: #fff; }

body[data-concept="cockpit"] .toast {
  border-color: #314766;
  background: rgba(20, 35, 62, .98);
  box-shadow: 0 14px 38px rgba(0, 0, 0, .35);
}
body[data-concept="cockpit"] .startup-card {
  border-color: #2a3f61;
  background: #14233e;
  box-shadow: 0 18px 46px rgba(0,0,0,.28);
}
body[data-concept="cockpit"] .spinner { border-color: #2a446b; border-top-color: #34a8ff; }

@media (max-width: 370px) {
  .cockpit-core { grid-template-columns: 113px minmax(0, 1fr); gap: 11px; }
  .time-ring { width: 110px; padding: 8px; }
  .time-ring strong { font-size: 24px; }
  .cockpit-panel { padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
