:root,
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #080808;
  --surface: #101010;
  --surface-2: #171717;
  --surface-3: #202020;
  --topbar: #0b0b0b;
  --nav: #0c0c0c;
  --input-bg: #0d0d0d;
  --panel: #0d0d0d;
  --card: #101010;
  --card-hover: #141414;
  --drop: #0a0a0a;
  --text: #f5f5f2;
  --text-strong: #ffffff;
  --muted: #8e8e8a;
  --muted-2: #b6b6b1;
  --placeholder: #656561;
  --line: #30302e;
  --line-strong: #4b4b47;
  --line-hover: #6a6a65;
  --nav-text: #a5a5a0;
  --nav-number: #62625e;
  --table-head: #777772;
  --table-cell: #d5d5d0;
  --code-text: #e5e5e0;
  --quiet-text: #d8d8d3;
  --danger-text: #ff5c5c;
  --danger-border: #7d2424;
  --danger-soft: #ff6565;
  --error: #ff6161;
  --empty: #686864;
  --footer: #585854;
  --red: #ef2727;
  --red-dark: #bd1616;
  --red-soft: rgba(239, 39, 39, 0.11);
  --green: #69c58a;
  --content: 1320px;
  --theme-toggle-bg: transparent;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f1ec;
  --surface: #fffcf7;
  --surface-2: #f7f3ec;
  --surface-3: #ebe6dc;
  --topbar: #fffdf9;
  --nav: #faf7f1;
  --input-bg: #ffffff;
  --panel: #ffffff;
  --card: #ffffff;
  --card-hover: #f5f0e7;
  --drop: #faf7f1;
  --text: #1c1b18;
  --text-strong: #111110;
  --muted: #6f6a60;
  --muted-2: #534e45;
  --placeholder: #9a9488;
  --line: #ddd5c7;
  --line-strong: #c4baa8;
  --line-hover: #a89f8d;
  --nav-text: #6a645a;
  --nav-number: #9a9284;
  --table-head: #8a8376;
  --table-cell: #2d2a24;
  --code-text: #2a271f;
  --quiet-text: #3f3b34;
  --danger-text: #c51f1f;
  --danger-border: #e08a8a;
  --danger-soft: #d32f2f;
  --error: #c62828;
  --empty: #8a8376;
  --footer: #8a8376;
  --red: #d81f1f;
  --red-dark: #b01515;
  --red-soft: rgba(216, 31, 31, 0.08);
  --green: #2e7d4f;
  --theme-toggle-bg: #f0ebe2;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0;
  outline: 0;
  background: var(--input-bg);
  color: var(--text);
}

input {
  min-height: 46px;
  padding: 0 14px;
}

textarea {
  display: block;
  min-height: 170px;
  resize: vertical;
  padding: 16px;
  line-height: 1.7;
}

input::placeholder,
textarea::placeholder {
  color: var(--placeholder);
}

input:focus,
textarea:focus {
  border-color: var(--red);
  box-shadow: inset 3px 0 0 var(--red);
}

label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted-2);
  font-size: 13px;
  font-weight: 650;
}

.site-frame {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  min-height: 86px;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--topbar);
}

.brand-lockup {
  display: flex;
  align-items: center;
  min-width: 310px;
}

.brand-mark {
  width: 86px;
  align-self: stretch;
  display: grid;
  place-items: center;
  background: var(--red);
  color: var(--text-strong);
  font-size: 30px;
  font-weight: 900;
}

.brand-lockup > div {
  padding: 0 20px;
}

.brand-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 12px;
}

.brand-lockup h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  font-weight: 800;
}

.brand-zh {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text-strong);
  opacity: 0.88;
}

.brand-version {
  font-family: Consolas, "SF Mono", monospace;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel, transparent);
  letter-spacing: 0.04em;
}

.brand-lockup p {
  margin: 6px 0 0;
  color: var(--muted);
  font-family: Consolas, monospace;
  font-size: 10px;
}

.session-block {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 24px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  background: var(--red);
  box-shadow: 0 0 0 3px var(--red-soft);
}

.shell {
  width: min(var(--content), calc(100vw - 48px));
  margin: 0 auto;
  padding: 34px 0 54px;
}

.button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 0;
  padding: 0 18px;
  color: var(--text-strong);
  font-weight: 700;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

.button-primary {
  background: var(--red);
  border-color: var(--red);
}

.button-primary:hover:not(:disabled) {
  background: var(--red-dark);
  border-color: var(--red-dark);
}

.button-quiet {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--quiet-text);
}

.button-quiet:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--line-hover);
  color: var(--text-strong);
}

.button-danger {
  background: transparent;
  border-color: var(--red);
  color: var(--danger-text);
}

.button-danger:hover:not(:disabled) {
  background: var(--red);
  color: var(--text-strong);
}

.theme-toggle {
  min-width: 76px;
  background: var(--theme-toggle-bg);
  border-color: var(--line-strong);
  color: var(--quiet-text);
  font-family: Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.theme-toggle:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--line-hover);
  color: var(--text-strong);
}

.button-small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
}

.login-panel {
  width: min(940px, 100%);
  min-height: 390px;
  margin: 34px auto 0;
  display: grid;
  grid-template-columns: 104px minmax(230px, 1fr) minmax(320px, 0.95fr);
  align-items: stretch;
  border: 1px solid var(--line);
  background: var(--surface);
}

.login-index {
  padding-top: 32px;
  border-right: 1px solid var(--line);
  color: var(--red);
  font-family: Consolas, monospace;
  font-size: 13px;
  text-align: center;
}

.login-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 48px;
}

.eyebrow,
.section-kicker {
  color: var(--red);
  font-family: Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
}

.login-copy h2,
.page-heading h2 {
  margin: 10px 0 0;
  font-size: 30px;
  line-height: 1.2;
}

.login-copy p {
  max-width: 360px;
  margin: 16px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.login-form {
  align-self: center;
  padding: 48px;
  border-left: 1px solid var(--line);
}

.input-action {
  display: grid;
  grid-template-columns: 1fr auto;
}

.input-action input {
  border-right: 0;
}

.console {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  min-height: 680px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.console-nav {
  border-right: 1px solid var(--line);
  background: var(--nav);
}

.nav-item {
  width: 100%;
  min-height: 64px;
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent;
  border-radius: 0;
  padding: 0 16px 0 13px;
  background: transparent;
  color: var(--nav-text);
  text-align: left;
}

.nav-item:hover {
  background: var(--card-hover);
  color: var(--text-strong);
}

.nav-item.active {
  border-left-color: var(--red);
  background: var(--surface-2);
  color: var(--text-strong);
}

.nav-number {
  color: var(--nav-number);
  font-family: Consolas, monospace;
  font-size: 11px;
}

.nav-item.active .nav-number {
  color: var(--red);
}

.console-content {
  min-width: 0;
  padding: 32px;
}

.page-heading {
  min-height: 70px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.page-heading h2 {
  font-size: 26px;
}

.page-meta,
.sync-state {
  color: var(--muted);
  font-size: 12px;
}

.sync-state {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-top: 8px;
}

.panel-block {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 22px;
}

.panel-block + .panel-block {
  margin-top: 20px;
}

.compose-footer {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--line);
  border-top: 0;
  padding-left: 15px;
  color: var(--muted);
  font-family: Consolas, monospace;
  font-size: 11px;
}

.compose-actions {
  display: flex;
  align-self: stretch;
}

.compose-actions .button {
  min-height: 100%;
  border-top: 0;
  border-bottom: 0;
  border-right: 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-head h3,
.settings-copy h3 {
  margin: 5px 0 0;
  font-size: 18px;
}

.label-hint {
  color: var(--muted);
  font-weight: 400;
  font-size: 12px;
}

#textTitleInput {
  width: 100%;
  margin: 6px 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--text);
  font-size: 14px;
}

.text-search-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

#textSearchInput {
  flex: 1 1 220px;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--text);
  font-size: 13px;
}

.text-search-meta {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.text-list {
  display: grid;
  gap: 1px;
  margin-top: 14px;
  border: 1px solid var(--line);
  background: var(--line);
}

.text-card {
  position: relative;
  background: var(--card);
  padding: 18px 18px 14px;
}

.text-card:hover {
  background: var(--card-hover);
}

.text-card.hit-title {
  box-shadow: inset 3px 0 0 #6ea8ff;
}

.text-card.hit-body {
  box-shadow: inset 3px 0 0 #69c58a;
}

.text-card.hit-title.hit-body {
  box-shadow: inset 3px 0 0 #6ea8ff, inset 6px 0 0 #69c58a;
}

.text-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
}

.text-card-heading {
  min-width: 0;
  flex: 1;
}

.text-title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.text-title-label {
  flex: 0 0 auto;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
}

.text-title {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  color: var(--text-strong);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.text-submeta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.text-time {
  color: var(--muted);
  font-family: Consolas, monospace;
  font-size: 11px;
}

.text-hit-badge {
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
}

.text-hit-badge.is-title {
  color: #9ec5ff;
  border-color: rgba(110, 168, 255, 0.45);
  background: rgba(110, 168, 255, 0.1);
}

.text-hit-badge.is-body {
  color: #9adbb2;
  border-color: rgba(105, 197, 138, 0.45);
  background: rgba(105, 197, 138, 0.1);
}

mark.text-hit {
  background: rgba(255, 214, 102, 0.35);
  color: inherit;
  padding: 0 2px;
  border-radius: 3px;
}

.text-body-label {
  margin: 0 0 4px;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.text-actions,
.record-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.text-content {
  margin: 0;
  max-height: 260px;
  overflow: auto;
  color: var(--code-text);
  font-family: Consolas, "Microsoft YaHei", monospace;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.agent-pair-code {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #9adbb2;
  background: rgba(105, 197, 138, 0.08);
  border: 1px solid rgba(105, 197, 138, 0.35);
  border-radius: 8px;
  padding: 4px 10px;
}

.text-origin {
  display: inline-block;
  margin-top: 12px;
  color: var(--nav-number);
  font-size: 10px;
}

.drop-zone {
  min-height: 235px;
  display: grid;
  grid-template-columns: 78px 1fr;
  align-items: center;
  border: 1px dashed var(--line-strong);
  background: var(--drop);
  cursor: pointer;
}

.drop-zone:hover,
.drop-zone.drag {
  border-color: var(--red);
  background: var(--red-soft);
}

.drop-zone input {
  display: none;
}

.drop-index {
  display: grid;
  place-items: center;
  align-self: stretch;
  border-right: 1px solid var(--line);
  color: var(--red);
  font-size: 36px;
  font-weight: 200;
}

.drop-zone > div:last-child {
  padding: 30px;
}

.drop-title {
  display: block;
  font-size: 21px;
  font-weight: 700;
}

.drop-hint {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.upload-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.action-spacer {
  flex: 1;
}

.progress-wrap,
.mini-progress {
  overflow: hidden;
  background: var(--surface-3);
}

.progress-wrap {
  width: 100%;
  height: 4px;
  margin-top: 16px;
}

.progress-bar,
.mini-progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--red);
  transition: width 180ms ease;
}

.progress-meta {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.45;
  letter-spacing: 0.02em;
  color: var(--muted, #8b93a7);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  min-height: 1.45em;
}

body.role-guest .admin-only {
  display: none !important;
}

body.role-admin .guest-only {
  display: none !important;
}

.guest-only {
  margin-top: 12px;
}

.howto-list {
  margin: 12px 0 0;
  padding-left: 1.25rem;
  line-height: 1.7;
  color: var(--muted, #8b93a7);
  font-size: 13px;
}

.howto-list code {
  font-size: 12px;
  color: inherit;
}

.tunnel-online {
  color: #1a7f37;
  font-weight: 600;
}

.tunnel-offline {
  color: #a40e26;
  font-weight: 600;
}

.grok-layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
  min-height: min(72vh, 820px);
}

.grok-sidebar,
.grok-chat {
  min-width: 0;
}

.grok-search {
  width: 100%;
  margin: 8px 0 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border, rgba(127, 127, 127, 0.3));
  background: transparent;
  color: inherit;
  font: inherit;
}

.grok-session-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: min(58vh, 640px);
  overflow: auto;
}

.grok-session-item {
  text-align: left;
  width: 100%;
  border: 1px solid var(--border, rgba(127, 127, 127, 0.25));
  background: transparent;
  color: inherit;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  position: relative;
}

.grok-session-item.active {
  border-color: var(--accent, #c8a96b);
  background: rgba(200, 169, 107, 0.08);
}

.grok-session-item .title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.grok-session-item .title {
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grok-session-item .badge {
  flex-shrink: 0;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid rgba(200, 169, 107, 0.45);
  color: inherit;
  opacity: 0.9;
}

.grok-session-item .badge.muted {
  border-color: rgba(127, 127, 127, 0.35);
  opacity: 0.7;
}

.grok-session-item .meta {
  font-size: 12px;
  opacity: 0.75;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grok-session-item .preview {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
  line-height: 1.35;
}

.grok-session-item .item-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.grok-session-item .item-actions button {
  font-size: 12px;
  padding: 2px 8px;
}

/* ---- Grok chat panel (web-like) ---- */
.grok-chat-panel {
  display: flex;
  flex-direction: column;
  min-height: min(68vh, 780px);
  max-height: min(78vh, 900px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background:
    radial-gradient(1200px 400px at 50% -10%, rgba(200, 169, 107, 0.06), transparent 55%),
    var(--surface);
  overflow: hidden;
}

.grok-chat-top {
  flex-shrink: 0;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
}

.grok-chat-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.grok-chat-meta {
  margin: 4px 0 0;
  font-size: 12px;
  line-height: 1.4;
  word-break: break-all;
}

.grok-chat-log {
  flex: 1 1 auto;
  min-height: 240px;
  overflow: auto;
  padding: 8px 0 20px;
  scroll-behavior: smooth;
}

.gchat-thread {
  width: min(780px, 100%);
  margin: 0 auto;
  padding: 8px 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.gchat-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 6px 0 2px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.gchat-divider::before,
.gchat-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.gchat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 280px;
  padding: 32px 20px;
  color: var(--muted);
  gap: 8px;
}

.gchat-empty-mark {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 22px;
  color: var(--text-strong);
  background: linear-gradient(145deg, rgba(200, 169, 107, 0.28), rgba(127, 127, 127, 0.12));
  border: 1px solid rgba(200, 169, 107, 0.35);
  margin-bottom: 6px;
}

.gchat-empty h4 {
  margin: 0;
  color: var(--text-strong);
  font-size: 18px;
  font-weight: 600;
}

.gchat-empty p {
  margin: 0;
  max-width: 340px;
  line-height: 1.5;
  font-size: 13px;
}

/* Message rows — TUI-like block layout only (never multi-col grid).
   Multi-col grid + single child caused 36px trap → vertical 一字一列. */
.gmsg {
  display: block !important;
  min-width: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box;
  writing-mode: horizontal-tb !important;
  direction: ltr;
}

.gmsg-user {
  display: block !important;
  border-left: 3px solid rgba(80, 200, 220, 0.75);
  padding-left: 10px;
  margin: 2px 0 6px;
}

.gmsg-user.is-pending {
  opacity: 0.85;
}

.gmsg-assistant {
  display: block !important;
  min-width: 0 !important;
  width: 100% !important;
  padding-bottom: 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(127, 127, 127, 0.1);
}

.gmsg-avatar,
.gmsg-user-bar {
  display: none !important;
}

.gmsg-main,
.gmsg-main-full {
  display: block !important;
  min-width: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
}

.gmsg-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}

.gmsg-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-strong);
}

.gmsg-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.gmsg-time {
  font-size: 11px;
  color: var(--muted);
}

.gmsg-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted-2);
  background: rgba(127, 127, 127, 0.08);
}

.gmsg-pill.live {
  border-color: rgba(200, 169, 107, 0.45);
  color: #d4b56a;
  background: rgba(200, 169, 107, 0.1);
}

.gmsg-pill.live::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #d4b56a;
  animation: gmsg-pulse 1.2s ease-in-out infinite;
}

.gmsg-pill.ok {
  border-color: rgba(105, 197, 138, 0.35);
  color: var(--green);
  background: rgba(105, 197, 138, 0.08);
}

.gmsg-pill.bad {
  border-color: rgba(255, 97, 97, 0.35);
  color: var(--error);
  background: rgba(255, 97, 97, 0.08);
}

@keyframes gmsg-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.85); }
}

.gmsg-body {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow-wrap: break-word;
  word-break: normal;
  word-wrap: break-word;
}

.gmsg-user .gmsg-body {
  display: block;
  max-width: 100%;
  padding: 0;
  border-radius: 0;
  background: transparent;
  border: 0;
}

.gmsg-plain {
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
}

.gmsg-assistant .gmsg-body {
  padding: 2px 0 0;
  max-width: 100%;
}

.gmsg-user-bar {
  width: 3px;
  min-height: 1.2em;
  margin-top: 4px;
  border-radius: 2px;
  background: rgba(80, 200, 220, 0.75);
  align-self: stretch;
}

.gmsg.is-history {
  opacity: 0.88;
}

.gmsg.is-history .gmsg-name::after {
  content: "";
}

.gmsg.is-running .gmsg-body {
  min-height: 1.5em;
}

.gmsg.is-error .gmsg-body {
  /* keep readable even on failure */
}

.gmsg-error {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 97, 97, 0.28);
  background: rgba(255, 97, 97, 0.06);
  color: var(--error);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.gmsg-empty {
  color: var(--muted);
  font-size: 13px;
}

/* Typing / streaming caret */
.gmsg-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 10px 4px;
}

.gmsg-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: gmsg-bounce 1.1s ease-in-out infinite;
}

.gmsg-typing span:nth-child(2) { animation-delay: 0.15s; }
.gmsg-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes gmsg-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.gmsg-caret {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--text-strong);
  border-radius: 1px;
  animation: gmsg-blink 1s step-end infinite;
}

@keyframes gmsg-blink {
  50% { opacity: 0; }
}

/* Thought / tool collapsible cards (Build-like) */
.gmsg-timeline {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Build process summary chips */
.gproc-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 2px;
}

.gchip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  line-height: 1.2;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(127, 127, 127, 0.08);
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
}

.gchip.live,
.gchip.gchip-status.live {
  border-color: rgba(200, 169, 107, 0.45);
  color: #d4b56a;
  background: rgba(200, 169, 107, 0.1);
}

.gchip.gchip-status.ok {
  border-color: rgba(105, 197, 138, 0.35);
  color: var(--green);
  background: rgba(105, 197, 138, 0.08);
}

.gchip.gchip-status.bad {
  border-color: rgba(255, 97, 97, 0.35);
  color: var(--error);
  background: rgba(255, 97, 97, 0.08);
}

.gchip.gchip-effort {
  border-color: rgba(180, 140, 220, 0.45);
  color: #c4a0e8;
  background: rgba(160, 120, 210, 0.1);
  font-weight: 600;
}

.grok-effort-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.grok-effort-inline select {
  width: auto;
  min-width: 4.5em;
  padding: 3px 6px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: inherit;
  font: inherit;
  font-size: 12px;
}

.gproc-timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(127, 127, 127, 0.04);
  overflow: hidden;
}

.gproc-title {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(127, 127, 127, 0.06);
}

.gproc-step {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 0 8px;
  padding: 0 8px 0 10px;
}

.gproc-step + .gproc-step .gproc-rail::before {
  content: "";
}

.gproc-rail {
  position: relative;
  display: flex;
  justify-content: center;
  padding-top: 14px;
}

.gproc-rail::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  background: var(--line);
}

.gproc-step:first-of-type .gproc-rail::before {
  top: 18px;
}

.gproc-step:last-of-type .gproc-rail::before {
  bottom: auto;
  height: 18px;
}

.gproc-dot {
  position: relative;
  z-index: 1;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  background: var(--surface);
  flex-shrink: 0;
}

.gproc-dot.thought {
  border-color: rgba(200, 169, 107, 0.75);
  background: rgba(200, 169, 107, 0.35);
}

.gproc-dot.tool {
  border-color: rgba(120, 160, 210, 0.8);
  background: rgba(120, 160, 210, 0.35);
}

.gproc-dot.error {
  border-color: rgba(255, 97, 97, 0.8);
  background: rgba(255, 97, 97, 0.35);
}

.gproc-dot.answer {
  border-color: rgba(200, 169, 107, 0.75);
  background: rgba(200, 169, 107, 0.45);
}

.gproc-history {
  margin: 4px 0 10px;
}

.gproc-main {
  min-width: 0;
  padding: 8px 4px 10px 0;
}

.gproc-main .gcard {
  margin: 0;
}

.gproc-answer {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px 12px;
  background: rgba(127, 127, 127, 0.04);
}

.gproc-answer-label {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.gcard-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.6em;
  padding: 0 5px;
  height: 1.4em;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: rgba(127, 127, 127, 0.14);
  color: var(--muted-2);
}

.gcard-time {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.gcard-tool-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
}

.gcard {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(127, 127, 127, 0.06);
  overflow: hidden;
}

.gcard > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  user-select: none;
  font-size: 13px;
  color: var(--text);
}

.gcard > summary::-webkit-details-marker {
  display: none;
}

.gcard > summary::after {
  content: "▸";
  flex-shrink: 0;
  opacity: 0.55;
  font-size: 11px;
  transition: transform 0.15s ease;
}

.gcard[open] > summary::after {
  transform: rotate(90deg);
}

.gcard-sum-main {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  font-weight: 600;
}

.gcard-ico {
  display: inline-grid;
  place-items: center;
  width: 1.2em;
  opacity: 0.85;
  font-size: 12px;
}

.gcard-meta {
  flex-shrink: 1;
  min-width: 0;
  max-width: 48%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  text-align: right;
}

.gcard-body {
  padding: 0 12px 12px;
  border-top: 1px solid transparent;
}

.gcard[open] .gcard-body {
  border-top-color: var(--line);
  padding-top: 10px;
}

.gcard-mono {
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted-2);
  white-space: pre-wrap;
  word-break: break-word;
}

.gcard-pre {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #0a0a0a;
  color: #e8e4d9;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  overflow: auto;
  max-height: min(36vh, 360px);
  white-space: pre-wrap;
  word-break: break-word;
}

html[data-theme="light"] .gcard-pre {
  background: #171613;
}

.gcard-thought {
  border-color: rgba(200, 169, 107, 0.28);
  background: rgba(200, 169, 107, 0.06);
}

.gcard-thought > summary {
  color: var(--muted-2);
}

.gcard-thought[open] > summary {
  color: var(--text-strong);
}

.gcard-tool {
  border-color: rgba(127, 160, 200, 0.28);
  background: rgba(100, 140, 190, 0.06);
}

.gcard-tool.is-result {
  border-color: rgba(105, 197, 138, 0.28);
  background: rgba(105, 197, 138, 0.05);
}

.gcard-tool.is-running {
  border-color: rgba(110, 168, 255, 0.55);
  box-shadow: 0 0 0 1px rgba(110, 168, 255, 0.22);
  animation: gcard-run-pulse 1.6s ease-in-out infinite;
}

@keyframes gcard-run-pulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(110, 168, 255, 0.18); }
  50% { box-shadow: 0 0 0 3px rgba(110, 168, 255, 0.12); }
}

.gcard-tool-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--text-strong);
}

.gcard-tag {
  font-size: 10px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.gcard-tag.live {
  border-color: rgba(110, 168, 255, 0.45);
  color: #7eb6ff;
  background: rgba(110, 168, 255, 0.1);
}

/* Grok history sync status bar */
.grok-sync-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.grok-sync-main {
  min-width: 0;
  flex: 1 1 220px;
}

.grok-sync-status {
  margin: 4px 0 0;
  line-height: 1.45;
}

.grok-sync-status.is-empty,
.grok-sync-status.is-stale {
  color: var(--error, #e07070);
}

.grok-sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.grok-wipe-btn {
  color: var(--error, #e07070);
  border-color: rgba(255, 97, 97, 0.28);
}

.grok-wipe-btn:hover {
  background: rgba(255, 97, 97, 0.08);
}

.gcard-error-static {
  border: 1px solid rgba(255, 97, 97, 0.3);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255, 97, 97, 0.06);
  color: var(--error);
  font-size: 13px;
}

.gcard-error-static .gcard-sum-main {
  margin-bottom: 6px;
  font-weight: 600;
}

.gmsg-typing-inline {
  padding: 4px 2px 2px;
}

/* Markdown body (Build-friendly) */
.gmd {
  max-width: 100%;
}

.gmd > :first-child {
  margin-top: 0;
}

.gmd > :last-child {
  margin-bottom: 0;
}

.gmd-p {
  margin: 0 0 0.85em;
}

.gmd-h {
  margin: 1.1em 0 0.45em;
  color: var(--text-strong);
  font-weight: 650;
  line-height: 1.3;
}

.gmd h1.gmd-h { font-size: 1.35em; }
.gmd h2.gmd-h { font-size: 1.2em; }
.gmd h3.gmd-h { font-size: 1.08em; }
.gmd h4.gmd-h,
.gmd h5.gmd-h,
.gmd h6.gmd-h { font-size: 1em; }

.gmd-ul,
.gmd-ol {
  margin: 0.4em 0 0.9em;
  padding-left: 1.35em;
}

.gmd-ul li,
.gmd-ol li {
  margin: 0.25em 0;
}

.gmd-quote {
  margin: 0.6em 0 0.9em;
  padding: 0.35em 0 0.35em 0.9em;
  border-left: 3px solid rgba(200, 169, 107, 0.55);
  color: var(--muted-2);
}

.gmd-hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 1em 0;
}

.gmd-a {
  color: #c8a96b;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.gmd-ic {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  padding: 0.12em 0.38em;
  border-radius: 5px;
  background: rgba(127, 127, 127, 0.14);
  border: 1px solid rgba(127, 127, 127, 0.16);
  color: var(--code-text);
}

.gmd-code {
  margin: 0.7em 0 1em;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0a0a0a;
  overflow: hidden;
}

html[data-theme="light"] .gmd-code {
  background: #171613;
  border-color: #2c2a26;
}

.gmd-code-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.03);
}

.gmd-code-lang {
  font-size: 11px;
  color: #9a968c;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-transform: lowercase;
}

.gmd-copy {
  border: 0;
  background: transparent;
  color: #bdb8ad;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.gmd-copy:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.gmd-copy.copied {
  color: #69c58a;
}

.gmd-pre {
  margin: 0;
  padding: 12px 14px 14px;
  overflow: auto;
  max-height: min(48vh, 480px);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  color: #e8e4d9;
  white-space: pre;
  tab-size: 2;
}

.gmd-pre code {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
}

.gmd-table-wrap {
  overflow: auto;
  margin: 0.7em 0 1em;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.gmd-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.gmd-table th,
.gmd-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.gmd-table th {
  background: rgba(127, 127, 127, 0.08);
  color: var(--text-strong);
  font-weight: 600;
}

.gmd-table tr:last-child td {
  border-bottom: 0;
}

/* Compose bar — floating Grok-like input */
.grok-compose-bar {
  flex-shrink: 0;
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}

.grok-compose-shell {
  width: min(780px, 100%);
  margin: 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: var(--input-bg);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  padding: 10px 12px 8px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.grok-compose-shell:focus-within {
  border-color: rgba(200, 169, 107, 0.55);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22), 0 0 0 3px rgba(200, 169, 107, 0.1);
}

.grok-compose-shell textarea {
  width: 100%;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  resize: none;
  min-height: 52px;
  max-height: 200px;
  padding: 4px 4px 8px;
  color: var(--text);
  line-height: 1.5;
  outline: none;
  font-size: 15px;
}

.grok-compose-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 2px;
}

.grok-compose-hint {
  min-width: 0;
  flex: 1;
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grok-compose-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  margin: 8px 0 12px;
  line-height: 1.35;
}

/* Keep native checkboxes compact (iOS/Android otherwise look huge) */
.checkbox-row input[type="checkbox"],
.grok-yolo-row input[type="checkbox"] {
  width: 16px !important;
  height: 16px !important;
  min-width: 16px !important;
  min-height: 16px !important;
  max-width: 16px !important;
  max-height: 16px !important;
  margin: 0 !important;
  padding: 0 !important;
  flex: 0 0 16px;
  accent-color: var(--accent, #c8a96b);
  transform: none !important;
  scale: 1 !important;
}

.grok-yolo-row {
  gap: 10px;
  padding: 8px 0 4px;
  font-size: 13px;
  color: var(--text);
}

.grok-yolo-row span {
  flex: 1 1 auto;
  min-width: 0;
}

/* Pending image previews in compose (must stay tiny on mobile) */
.grok-image-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 96px;
  overflow-x: auto;
  overflow-y: hidden;
  margin: 0 0 8px;
  padding: 2px 0 4px;
  -webkit-overflow-scrolling: touch;
}

.grok-image-preview.hidden {
  display: none !important;
}

.grok-image-chip {
  position: relative;
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line-strong, rgba(200, 169, 107, 0.35));
  background: var(--panel, #1a1a1a);
}

.grok-image-chip img {
  display: block;
  width: 64px !important;
  height: 64px !important;
  max-width: 64px !important;
  max-height: 64px !important;
  object-fit: cover;
  object-position: center;
}

.grok-image-chip .rm {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  padding: 0;
  line-height: 18px;
  font-size: 14px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  cursor: pointer;
}

.grok-image-chip .meta {
  display: none;
}

.grok-new-session-form select,
.grok-new-session-form input[type="text"] {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  font-size: 16px; /* avoid iOS zoom */
  min-height: 40px;
}

.grok-new-session-form .checkbox-row input[type="checkbox"] {
  width: 16px !important;
  height: 16px !important;
}

.grok-cwd-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.grok-cwd-row input {
  flex: 1;
  min-width: 0;
}

.grok-cwd-row button {
  flex-shrink: 0;
}

/* Folder browse modal */
.grok-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.grok-modal.hidden {
  display: none;
}

.grok-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.grok-modal-panel {
  position: relative;
  z-index: 1;
  width: min(640px, 100%);
  max-height: min(80vh, 720px);
  overflow: auto;
  background: var(--panel, #161616);
  color: inherit;
  border: 1px solid var(--border, rgba(200, 169, 107, 0.35));
  border-radius: 14px;
  padding: 16px 18px 18px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
}

.grok-browse-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 10px;
}

.grok-browse-bar input {
  flex: 1 1 180px;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border, rgba(127, 127, 127, 0.3));
  background: transparent;
  color: inherit;
  font: inherit;
}

.grok-browse-list {
  border: 1px solid var(--border, rgba(127, 127, 127, 0.25));
  border-radius: 10px;
  max-height: min(48vh, 420px);
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.grok-browse-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: 0;
  border-bottom: 1px solid rgba(127, 127, 127, 0.12);
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.grok-browse-item:hover,
.grok-browse-item:focus {
  background: rgba(200, 169, 107, 0.1);
  outline: none;
}

.grok-browse-item .icon {
  flex-shrink: 0;
  width: 1.4em;
  opacity: 0.8;
}

.grok-browse-item .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grok-browse-item.file {
  opacity: 0.55;
  cursor: default;
}

.grok-browse-item.file:hover {
  background: transparent;
}

@media (max-width: 900px) {
  .grok-layout {
    grid-template-columns: 1fr;
    min-height: 0;
    gap: 10px;
  }

  .grok-session-list {
    max-height: 160px;
  }

  .grok-chat-panel {
    min-height: 58vh;
    max-height: none;
  }

  .gchat-thread {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 6px 8px 10px;
    gap: 14px;
  }

  .gmsg {
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 8px;
  }

  .gmsg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    font-size: 10px;
  }

  .gmsg-body {
    font-size: 14px;
  }

  /* Grok 页：去掉多余外壳，让对话区吃满宽度 */
  .console-content:has([data-view-panel="grok"]:not(.hidden)) {
    padding: 14px 10px 20px;
  }

  [data-view-panel="grok"] .page-heading {
    margin-bottom: 10px;
  }

  [data-view-panel="grok"] .page-heading .page-meta {
    display: none;
  }

  [data-view-panel="grok"] > .settings-panel.panel-block {
    padding: 12px;
  }

  [data-view-panel="grok"] .panel-block.grok-layout {
    border: 0;
    padding: 0;
    background: transparent;
  }

  [data-view-panel="grok"] .grok-chat-panel {
    border: 0;
    border-radius: 0;
    background: transparent;
    min-height: min(72vh, 900px);
    overflow: visible;
  }

  [data-view-panel="grok"] .grok-chat-top {
    padding: 6px 2px 8px;
    border-bottom: 1px solid var(--line);
    background: transparent;
  }

  [data-view-panel="grok"] .grok-chat-top .section-kicker {
    display: none;
  }

  [data-view-panel="grok"] .grok-chat-top h3 {
    font-size: 16px;
    margin: 0;
  }

  [data-view-panel="grok"] .grok-chat-meta {
    font-size: 11px;
    margin-top: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  [data-view-panel="grok"] .grok-chat-log {
    padding: 4px 0 8px;
    min-height: 40vh;
  }

  [data-view-panel="grok"] .grok-compose-bar {
    padding: 6px 0 4px;
    border-top: 0;
    background: transparent;
  }

  [data-view-panel="grok"] .grok-compose-shell {
    width: 100%;
    max-width: none;
    border-radius: 12px;
    box-shadow: none;
    padding: 6px 8px 4px;
  }

  [data-view-panel="grok"] .grok-compose-shell:focus-within {
    box-shadow: 0 0 0 2px rgba(200, 169, 107, 0.18);
  }

  [data-view-panel="grok"] .grok-sidebar .section-kicker {
    display: none;
  }
}

/* 手机窄屏：全宽但仍保留主次层次（头像、气泡、过程轨） */
@media (max-width: 640px) {
  .console-content:has([data-view-panel="grok"]:not(.hidden)) {
    padding: 10px 8px 16px;
  }

  .shell:has([data-view-panel="grok"]:not(.hidden)) {
    width: min(100% - 16px, var(--content));
    padding-top: 12px;
  }

  [data-view-panel="grok"] .page-heading h2 {
    font-size: 18px;
  }

  [data-view-panel="grok"] .page-heading .eyebrow {
    font-size: 10px;
  }

  [data-view-panel="grok"] > .settings-panel.panel-block {
    padding: 12px;
    border-radius: 12px;
  }

  [data-view-panel="grok"] > .settings-panel .settings-copy p {
    display: none;
  }

  [data-view-panel="grok"] .gchat-thread {
    padding: 6px 4px 10px;
    gap: 16px;
  }

  /* 保留小头像，分清你 / Grok */
  [data-view-panel="grok"] .gmsg {
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 8px;
  }

  [data-view-panel="grok"] .gmsg-avatar {
    display: grid;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    font-size: 10px;
  }

  [data-view-panel="grok"] .gmsg-head {
    margin-bottom: 6px;
    gap: 6px;
  }

  [data-view-panel="grok"] .gmsg-name {
    font-size: 13px;
    font-weight: 700;
  }

  [data-view-panel="grok"] .gmsg-user .gmsg-body {
    max-width: 100%;
    width: auto;
    box-sizing: border-box;
    padding: 9px 11px;
    border-radius: 14px 14px 4px 14px;
    background: rgba(200, 169, 107, 0.16);
    border: 1px solid rgba(200, 169, 107, 0.32);
  }

  [data-view-panel="grok"] .gmsg-assistant .gmsg-body {
    padding: 0;
  }

  [data-view-panel="grok"] .gmsg-assistant {
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(127, 127, 127, 0.12);
  }

  [data-view-panel="grok"] .gmsg-body {
    font-size: 14.5px;
    line-height: 1.55;
  }

  [data-view-panel="grok"] .gproc-strip {
    gap: 5px;
  }

  [data-view-panel="grok"] .gchip {
    font-size: 10.5px;
    padding: 3px 7px;
  }

  [data-view-panel="grok"] .gproc-timeline {
    border-radius: 10px;
  }

  [data-view-panel="grok"] .gproc-title,
  [data-view-panel="grok"] .gproc-answer-label {
    font-size: 10.5px;
  }

  [data-view-panel="grok"] .gproc-answer {
    border-radius: 10px;
    padding: 10px;
    background: rgba(200, 169, 107, 0.05);
    border-color: rgba(200, 169, 107, 0.22);
  }

  [data-view-panel="grok"] .gcard {
    border-radius: 10px;
  }

  [data-view-panel="grok"] .gcard > summary {
    padding: 8px 10px;
  }

  [data-view-panel="grok"] .gcard-body {
    padding: 0 10px 10px;
  }

  [data-view-panel="grok"] .gcard-meta {
    max-width: 38%;
  }

  [data-view-panel="grok"] .gcard-time {
    display: none; /* 摘要条已有时间，卡片内省略防挤 */
  }

  [data-view-panel="grok"] .gmd-code {
    border-radius: 8px;
  }

  [data-view-panel="grok"] .gmd-pre {
    padding: 10px;
    font-size: 12px;
  }

  [data-view-panel="grok"] .grok-chat-actions .button {
    padding: 4px 8px;
    font-size: 12px;
  }

  [data-view-panel="grok"] #grokMessage.message {
    margin: 4px 2px 0;
    font-size: 12px;
  }

  [data-view-panel="grok"] .gchat-divider {
    margin: 4px 0;
    font-size: 10px;
    font-weight: 650;
  }

  [data-view-panel="grok"] .gmsg-pill {
    font-size: 10.5px;
  }
}

.tunnel-cmd {
  font-size: 12px;
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.upload-speed-line {
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.mini-progress {
  width: min(180px, 100%);
  height: 3px;
  margin-top: 7px;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 18px;
}

.table-wrap-flush {
  margin-top: 0;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 13px 10px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

th {
  color: var(--table-head);
  font-family: Consolas, monospace;
  font-size: 10px;
  font-weight: 500;
}

td {
  max-width: 320px;
  color: var(--table-cell);
  overflow-wrap: anywhere;
}

tbody tr:hover {
  background: var(--card-hover);
}

.record-actions button {
  min-height: 32px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  padding: 0 10px;
  background: transparent;
  color: var(--table-cell);
  font-size: 11px;
  cursor: pointer;
}

.record-actions button:hover:not(:disabled) {
  border-color: var(--line-hover);
  background: var(--surface-3);
  color: var(--text-strong);
}

.record-actions button.danger {
  border-color: var(--danger-border);
  color: var(--danger-soft);
}

.record-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.3;
}

.danger-block {
  border-left: 3px solid var(--red);
}

.delete-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 18px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(240px, 0.8fr) minmax(320px, 1.2fr);
  gap: 60px;
  padding: 34px;
}

.settings-number {
  color: var(--red);
  font-family: Consolas, monospace;
  font-size: 12px;
}

.settings-copy p {
  max-width: 420px;
  color: var(--muted);
  line-height: 1.7;
}

.key-form {
  display: grid;
  gap: 9px;
}

.key-form label:not(:first-child) {
  margin-top: 6px;
}

.key-form .button {
  margin-top: 8px;
}

.message {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.message.error {
  color: var(--error);
}

.message.ok {
  color: var(--green);
}

.muted {
  color: var(--muted);
  font-size: 11px;
}

.empty,
.empty-state {
  color: var(--empty);
  text-align: center;
}

.empty-state {
  grid-column: 1 / -1;
  background: var(--card);
  padding: 46px 18px;
  font-size: 13px;
}

.site-footer {
  width: min(var(--content), calc(100vw - 48px));
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 auto;
  border-top: 1px solid var(--line);
  color: var(--footer);
  font-family: Consolas, monospace;
  font-size: 9px;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .shell,
  .site-footer {
    width: min(100% - 28px, var(--content));
  }

  .login-panel {
    grid-template-columns: 72px 1fr;
  }

  .login-form {
    grid-column: 2;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .console {
    grid-template-columns: 1fr;
  }

  .console-nav {
    display: grid;
    grid-template-columns: repeat(4, minmax(120px, 1fr));
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-item {
    min-width: 120px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    border-left: 0;
    border-top: 3px solid transparent;
  }

  .nav-item.active {
    border-top-color: var(--red);
    border-left-color: transparent;
  }
}

@media (max-width: 640px) {
  .topbar {
    min-height: 70px;
  }

  .brand-mark {
    width: 64px;
  }

  .brand-lockup {
    min-width: 0;
  }

  .brand-lockup > div {
    padding: 0 12px;
  }

  .brand-lockup h1 {
    font-size: 15px;
  }

  .brand-lockup p,
  .session-block .status-dot,
  #statusText {
    display: none;
  }

  .session-block {
    padding: 0 10px;
  }

  .shell {
    padding-top: 18px;
  }

  .login-panel {
    grid-template-columns: 1fr;
    margin-top: 10px;
  }

  .login-index {
    display: none;
  }

  .login-copy,
  .login-form {
    grid-column: 1;
    padding: 26px;
  }

  .login-copy h2 {
    font-size: 25px;
  }

  .input-action {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .input-action input {
    border-right: 1px solid var(--line);
  }

  .console-content {
    padding: 20px 14px 28px;
  }

  .console-nav {
    grid-template-columns: repeat(4, 118px);
  }

  .nav-item {
    grid-template-columns: 1fr;
    gap: 3px;
    padding: 8px 12px;
    text-align: center;
  }

  .nav-number {
    display: block;
  }

  .page-heading {
    min-height: 64px;
  }

  .page-heading h2 {
    font-size: 23px;
  }

  .sync-state,
  .page-heading > .page-meta {
    display: none;
  }

  .panel-block {
    padding: 14px;
  }

  .compose-footer {
    align-items: stretch;
    flex-direction: column;
    padding: 10px 0 0 12px;
  }

  .compose-actions {
    width: calc(100% + 12px);
    margin-left: -12px;
  }

  .compose-actions .button {
    flex: 1;
    min-height: 44px;
    border-top: 1px solid var(--line);
  }

  .text-card-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .drop-zone {
    min-height: 190px;
    grid-template-columns: 52px 1fr;
  }

  .drop-zone > div:last-child {
    padding: 20px;
  }

  .drop-title {
    font-size: 18px;
  }

  .upload-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .action-spacer {
    display: none;
  }

  .delete-form,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .settings-grid {
    gap: 22px;
    padding: 22px;
  }

  .site-footer {
    width: calc(100% - 28px);
  }
}

/* === GROK LAYOUT V2 — chat-first (appended overrides; keeps gcard/gmd/gproc) === */

.grok-view {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.grok-page-heading {
  margin-bottom: 0 !important;
}

.grok-setup {
  padding: 0 !important;
  overflow: hidden;
}

.grok-setup-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  user-select: none;
}

.grok-setup-summary::-webkit-details-marker {
  display: none;
}

.grok-setup-title {
  font-weight: 650;
  font-size: 14px;
}

.grok-setup-hint {
  margin: 0;
  font-size: 12px;
}

.grok-setup-body {
  padding: 0 14px 14px;
  border-top: 1px solid var(--line);
}

.grok-setup-copy h3 {
  margin: 12px 0 6px;
  font-size: 15px;
}

.grok-setup-copy p {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
}

.grok-layout {
  position: relative;
  display: grid !important;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr) !important;
  gap: 14px !important;
  align-items: stretch;
  min-height: min(78vh, 820px) !important;
  height: min(78vh, 820px) !important;
  max-height: none !important;
  margin-bottom: 0 !important;
  padding: 12px !important;
}

.grok-sidebar {
  min-width: 0;
  min-height: 0;
  display: flex !important;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  padding: 10px 10px 12px;
  overflow: hidden;
}

.grok-sidebar-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  flex: 0 0 auto;
}

.grok-sidebar-titles h3 {
  margin: 2px 0 0;
  font-size: 15px;
  line-height: 1.2;
}

.grok-sidebar-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  justify-content: flex-end;
  align-items: center;
  flex-shrink: 0;
  min-width: 0;
}

.grok-sidebar-actions .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  white-space: nowrap;
  line-height: 1.2;
  box-sizing: border-box;
  min-height: 34px;
  height: 34px;
  padding: 0 10px;
  overflow: visible;
}

/* + new Live session (always visible in session sidebar, including mobile drawer) */
.grok-new-session-btn {
  min-width: 34px;
  width: 34px;
  height: 32px;
  padding: 0 !important;
  font-size: 20px !important;
  font-weight: 600;
  line-height: 1;
  border-radius: 10px;
}

.grok-new-session-panel {
  width: min(480px, 100%);
  max-height: min(88vh, 720px);
}

.grok-new-session-hint {
  margin: 0 0 12px !important;
  line-height: 1.45;
}

.grok-new-session-form label {
  display: block;
  margin: 10px 0 4px;
  font-size: 13px;
}

.grok-new-session-form .grok-cwd-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.grok-new-session-form .grok-cwd-row input {
  flex: 1 1 auto;
  min-width: 0;
}

.grok-new-session-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.grok-new-session-actions .button {
  min-width: 88px;
}

/* Browse folder modal above new-session modal */
#grokBrowseModal {
  z-index: 1300;
}

.grok-sidebar-close {
  display: none;
  min-width: 2.75em;
  padding: 0 12px !important;
  letter-spacing: 0.02em;
}

.grok-sync-status {
  margin: 0 !important;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--muted);
  flex: 0 0 auto;
}

.grok-meta-line {
  margin: 0 !important;
  font-size: 11.5px;
  flex: 0 0 auto;
}

.grok-search {
  width: 100%;
  margin: 0 !important;
  flex: 0 0 auto;
}

.grok-session-list {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow: auto !important;
  -webkit-overflow-scrolling: touch;
}

.grok-install-box {
  flex: 0 0 auto;
  max-height: 80px;
  overflow: auto;
  margin: 0 !important;
  font-size: 11px;
}

.grok-sidebar-backdrop {
  display: none;
}

.grok-chat-panel {
  display: flex !important;
  flex-direction: column !important;
  min-width: 0;
  min-height: 0 !important;
  height: 100% !important;
  max-height: none !important;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden !important;
}

.grok-chat-top {
  flex: 0 0 auto !important;
  padding: 10px 12px 8px !important;
}

.grok-chat-top-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.grok-sessions-toggle {
  display: none;
  flex-shrink: 0;
  margin-top: 2px;
}

.grok-chat-title-block {
  min-width: 0;
  flex: 1 1 auto;
}

.grok-chat-title-block h3 {
  margin: 0 !important;
  font-size: 15px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grok-chat-meta {
  margin: 3px 0 0 !important;
  font-size: 11.5px !important;
  line-height: 1.35;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.grok-chat-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  flex-shrink: 0;
  justify-content: flex-end;
}

.grok-chat-log {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow-x: hidden;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.grok-compose,
.grok-compose-bar {
  flex: 0 0 auto !important;
}

.grok-compose-bar {
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px)) !important;
}

.grok-compose-shell {
  width: min(780px, 100%) !important;
  margin: 0 auto;
  border-radius: 16px;
}

.grok-form-message {
  margin: 0;
  padding: 0 12px 6px;
  font-size: 12px;
}

.grok-form-message:empty {
  display: none !important;
}

.grok-effort-label {
  font-size: 12px;
}

/* Hide obsolete sync bar class if any remnant */
.grok-sync-bar {
  display: none !important;
}

/* ---------- Mobile / tablet: chat-first app shell ---------- */
@media (max-width: 900px) {
  .console-content:has([data-view-panel="grok"]:not(.hidden)) {
    padding: 10px 10px 12px !important;
  }

  .shell:has([data-view-panel="grok"]:not(.hidden)) {
    width: min(100% - 12px, var(--content)) !important;
    padding-top: 10px !important;
    padding-bottom: 8px !important;
  }

  .grok-view {
    gap: 8px;
    min-height: calc(100dvh - 120px);
  }

  .grok-page-heading h2 {
    font-size: 18px !important;
  }

  .grok-page-meta {
    display: none !important;
  }

  .grok-setup {
    border-radius: 12px;
  }

  .grok-setup-summary {
    padding: 10px 12px;
  }

  .grok-setup-copy p {
    display: none;
  }

  .grok-layout {
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: none !important;
    gap: 0 !important;
    flex: 1 1 auto;
    min-height: calc(100dvh - 168px) !important;
    height: calc(100dvh - 168px) !important;
    max-height: none !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  /* Session drawer */
  .grok-sidebar {
    position: fixed !important;
    z-index: 70;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(88vw, 320px) !important;
    max-width: 320px;
    height: 100dvh !important;
    max-height: none !important;
    border-radius: 0 !important;
    border: 0 !important;
    border-right: 1px solid var(--line) !important;
    padding:
      calc(12px + env(safe-area-inset-top, 0px))
      12px
      calc(12px + env(safe-area-inset-bottom, 0px)) !important;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.28);
  }

  .grok-view.grok-sessions-open .grok-sidebar {
    transform: translateX(0);
  }

  .grok-sidebar-close {
    display: inline-flex !important;
  }

  .grok-sidebar-backdrop {
    display: block !important;
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .grok-view.grok-sessions-open .grok-sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .grok-chat-panel {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: 100% !important;
    border-radius: 14px !important;
  }

  .grok-sessions-toggle {
    display: inline-flex !important;
  }

  .grok-chat-top {
    padding: 8px 8px 6px !important;
  }

  .grok-chat-title-block h3 {
    font-size: 14.5px !important;
  }

  .grok-chat-meta {
    -webkit-line-clamp: 1;
    font-size: 11px !important;
  }

  .grok-effort-label {
    display: none;
  }

  .grok-chat-actions .button {
    padding: 4px 8px;
    font-size: 12px;
  }

  .grok-chat-log {
    padding: 4px 0 8px !important;
  }

  .gchat-thread {
    width: 100% !important;
    padding: 4px 10px 8px !important;
    gap: 10px !important;
  }

  .gchat-empty {
    min-height: 160px;
    padding: 20px 12px;
  }

  .gmsg,
  .gmsg-user,
  .gmsg-assistant {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    grid-template-columns: none !important;
  }

  .gmsg-user {
    border-left: 3px solid rgba(80, 200, 220, 0.75) !important;
    padding-left: 10px !important;
  }

  .gmsg-assistant {
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(127, 127, 127, 0.1);
  }

  .gmsg-body,
  .gmsg-main,
  .gmsg-main-full {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    word-break: normal !important;
    overflow-wrap: break-word !important;
  }

  .gmsg-body {
    font-size: 14.5px;
    line-height: 1.55;
  }

  .gmsg-user .gmsg-body {
    max-width: 100% !important;
    width: 100% !important;
    padding: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    border: 0 !important;
    display: block !important;
  }

  .grok-compose-bar {
    padding: 6px 8px calc(8px + env(safe-area-inset-bottom, 0px)) !important;
  }

  .grok-compose-shell {
    width: 100% !important;
    max-width: none !important;
    border-radius: 14px !important;
    padding: 6px 8px 4px !important;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  }

  .grok-compose-shell textarea {
    min-height: 40px !important;
    max-height: 120px !important;
    font-size: 16px !important; /* prevent iOS zoom */
    padding: 4px 2px 4px !important;
  }

  .grok-compose-actions .button {
    min-height: 32px;
  }

  .gmd-pre {
    font-size: 12px;
    padding: 8px 10px;
  }

  .gchip {
    font-size: 10.5px;
    padding: 3px 7px;
  }

  .gcard > summary {
    padding: 8px 10px;
  }

  .gcard-body {
    padding: 0 10px 10px;
  }
}

@media (max-width: 480px) {
  .grok-layout {
    min-height: calc(100dvh - 148px) !important;
    height: calc(100dvh - 148px) !important;
  }

  .grok-chat-actions #grokRenameBtn {
    display: none;
  }

  .grok-page-heading .eyebrow {
    font-size: 10px;
  }

  .gmsg-head .gmsg-time {
    display: none;
  }

  .grok-session-item .item-actions {
    display: none;
  }
}

/* === Grok message width safety (fix vertical 一列 text) === */
[data-view-panel="grok"] .gmsg,
[data-view-panel="grok"] .gmsg-assistant,
[data-view-panel="grok"] .gmsg-main,
[data-view-panel="grok"] .gmsg-main-full,
[data-view-panel="grok"] .gmsg-body,
[data-view-panel="grok"] .gmsg-timeline,
[data-view-panel="grok"] .gtl-stream,
[data-view-panel="grok"] .gtl-answer,
[data-view-panel="grok"] .gmd {
  min-width: 0 !important;
  max-width: 100% !important;
  box-sizing: border-box;
}
[data-view-panel="grok"] .gmsg-assistant {
  display: block !important;
  width: 100% !important;
}
[data-view-panel="grok"] .gmsg-user {
  display: grid !important;
  grid-template-columns: 3px minmax(0, 1fr) !important;
  width: 100% !important;
}
[data-view-panel="grok"] .gmsg-body,
[data-view-panel="grok"] .gmsg-plain,
[data-view-panel="grok"] .gmd {
  word-break: normal !important;
  overflow-wrap: break-word !important;
  white-space: normal;
}
[data-view-panel="grok"] .gmsg-plain {
  white-space: pre-wrap !important;
}
[data-view-panel="grok"] .gtl-sum {
  list-style: none;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
}
[data-view-panel="grok"] .gtl-tool-line {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: var(--muted);
}
[data-view-panel="grok"] .gtl-muted {
  font-size: 12px;
  color: var(--muted);
  opacity: 0.75;
  padding: 4px 0;
}
[data-view-panel="grok"] .gtl-body {
  margin-top: 6px;
  min-width: 0;
  max-width: 100%;
}
[data-view-panel="grok"] .gtl-pre {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: anywhere;
  font-size: 12px;
  max-height: 240px;
  overflow-y: auto;
}
[data-view-panel="grok"] .gmsg.is-history {
  opacity: 1;
}

/* === v3 hard fix: full-width text, no vertical columns === */
[data-view-panel="grok"] .gchat-thread,
[data-view-panel="grok"] .gmsg,
[data-view-panel="grok"] .gmsg-body,
[data-view-panel="grok"] .gmsg-plain,
[data-view-panel="grok"] .gmd,
[data-view-panel="grok"] .gtl-stream,
[data-view-panel="grok"] .gtl-step,
[data-view-panel="grok"] .gtl-answer {
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
  writing-mode: horizontal-tb !important;
  grid-template-columns: none !important;
}
[data-view-panel="grok"] .gmsg-user {
  border-left: 3px solid rgba(80, 200, 220, 0.75) !important;
  padding-left: 10px !important;
}
[data-view-panel="grok"] .gmsg-plain,
[data-view-panel="grok"] .gmd-p {
  white-space: pre-wrap !important;
  word-break: normal !important;
  overflow-wrap: break-word !important;
}
[data-view-panel="grok"] .gtl-stream {
  margin: 4px 0 8px;
  padding: 0;
}
[data-view-panel="grok"] .gtl-step {
  margin: 2px 0;
}
[data-view-panel="grok"] .gtl {
  margin: 0;
  border: 0;
  background: transparent;
}
[data-view-panel="grok"] .gtl-sum {
  display: block;
  padding: 2px 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.4;
  cursor: pointer;
}
[data-view-panel="grok"] .gtl-tool-line {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--muted);
}
[data-view-panel="grok"] .gtl-thought-label {
  color: var(--muted);
  font-style: italic;
}

/* === TUI scrollback density (thinking.rs + tool/* collapsed) === */
[data-view-panel="grok"] .tui-proc {
  display: block !important;
  width: 100% !important;
  margin: 2px 0 10px;
  padding: 0;
  border: 0;
  background: transparent;
}
[data-view-panel="grok"] .tui-row {
  margin: 0;
  border: 0;
  background: transparent;
}
[data-view-panel="grok"] .tui-line,
[data-view-panel="grok"] .tui-row > summary {
  display: block;
  list-style: none;
  cursor: default;
  padding: 1px 0 1px 2px;
  margin: 0;
  border: 0;
  background: transparent;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--muted);
  user-select: text;
}
[data-view-panel="grok"] .tui-row > summary {
  cursor: pointer;
}
[data-view-panel="grok"] .tui-row > summary::-webkit-details-marker { display: none; }
[data-view-panel="grok"] .tui-line-thought {
  font-style: italic;
  font-weight: 600;
  color: var(--muted);
}
[data-view-panel="grok"] .tui-line-tool {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
  opacity: 0.92;
}
[data-view-panel="grok"] .tui-line-tool.is-running {
  color: var(--accent, #c8a96b);
  opacity: 1;
}
[data-view-panel="grok"] .tui-line-tool.is-failed {
  color: var(--error, #e07070);
}
[data-view-panel="grok"] .tui-muted {
  font-weight: 400;
  opacity: 0.85;
}
[data-view-panel="grok"] .tui-expand {
  margin: 2px 0 6px 8px;
  padding: 6px 8px;
  border-left: 2px solid rgba(127, 127, 127, 0.25);
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text);
  max-height: 220px;
  overflow: auto;
}
[data-view-panel="grok"] .tui-pre {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: anywhere;
  max-height: 180px;
  overflow: auto;
}
[data-view-panel="grok"] .tui-pre-err {
  color: var(--error, #e07070);
}
[data-view-panel="grok"] .tui-answer {
  display: block;
  width: 100%;
  margin: 2px 0 8px;
}
/* Hide legacy heavy process chrome if any remains */
[data-view-panel="grok"] .gproc-strip,
[data-view-panel="grok"] .gchat-divider {
  display: none !important;
}
[data-view-panel="grok"] .gtl-stream {
  /* legacy class still used in some paths — restyle flat */
  margin: 2px 0 8px;
  padding: 0;
  border: 0;
  background: transparent;
}

/* ==========================================================================
   Grok Mobile shell + animations (2026-07-17i)
   ========================================================================== */

@keyframes grok-fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes grok-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes grok-pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}
@keyframes grok-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
@keyframes grok-sheet-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
@keyframes grok-scale-pop {
  0% { transform: scale(0.92); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.grok-status-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
  min-height: 0;
}
.grok-status-chips:empty { display: none; }
.grok-status-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  line-height: 1.2;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(127, 127, 127, 0.08);
  animation: grok-scale-pop 0.28s ease both;
}
.grok-status-chip.live {
  border-color: rgba(200, 169, 107, 0.45);
  color: var(--accent, #c8a96b);
  background: rgba(200, 169, 107, 0.1);
}
.grok-status-chip.live::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: grok-pulse-dot 1.2s ease-in-out infinite;
}
.grok-status-chip.ok {
  border-color: rgba(105, 197, 138, 0.4);
  color: #5dbf88;
}
.grok-status-chip.warn {
  border-color: rgba(220, 160, 80, 0.45);
  color: #d4a24a;
}
.grok-status-chip.bad {
  border-color: rgba(255, 97, 97, 0.4);
  color: #e07070;
}

.grok-quickbar {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(127, 127, 127, 0.12);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.grok-quickbar::-webkit-scrollbar { display: none; }
.grok-quickbar[hidden] { display: none !important; }
.grok-chip-btn {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: rgba(127, 127, 127, 0.06);
  color: inherit;
  font: inherit;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
  white-space: nowrap;
}
.grok-chip-btn:active {
  transform: scale(0.96);
  background: rgba(200, 169, 107, 0.12);
  border-color: rgba(200, 169, 107, 0.4);
}
.grok-chip-btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}

.grok-fab-bottom {
  position: absolute;
  right: 14px;
  bottom: 88px;
  z-index: 5;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line-strong, var(--line));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  color: inherit;
  font-size: 18px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  animation: grok-scale-pop 0.25s ease both;
  backdrop-filter: blur(8px);
}
.grok-fab-bottom.hidden { display: none !important; }
.grok-fab-bottom:active { transform: scale(0.94); }

.grok-chat-panel {
  position: relative;
}

/* Message enter animation */
[data-view-panel="grok"] .gmsg,
[data-view-panel="grok"] .tui-proc {
  animation: grok-fade-up 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}
[data-view-panel="grok"] .tui-line,
[data-view-panel="grok"] .tui-row {
  animation: grok-fade-in 0.22s ease both;
}
[data-view-panel="grok"] .gchat-empty {
  animation: grok-fade-up 0.4s ease both;
}
[data-view-panel="grok"] .gchat-empty-mark {
  animation: grok-scale-pop 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* Session list polish */
.grok-session-item {
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
  animation: grok-fade-up 0.28s ease both;
}
.grok-session-item:active {
  transform: scale(0.985);
}
.grok-session-item.active {
  box-shadow: 0 0 0 1px rgba(200, 169, 107, 0.25);
}

/* Sheet (mobile more menu) */
.grok-sheet {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.grok-sheet.hidden { display: none !important; }
.grok-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  animation: grok-fade-in 0.2s ease both;
}
.grok-sheet-panel {
  position: relative;
  z-index: 1;
  width: min(480px, 100%);
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  border: 1px solid var(--line);
  border-bottom: 0;
  padding: 8px 10px calc(12px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.35);
  animation: grok-sheet-up 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.grok-sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: rgba(127, 127, 127, 0.35);
  margin: 4px auto 10px;
}
.grok-sheet-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 16px;
  padding: 14px 12px;
  border-radius: 12px;
  cursor: pointer;
}
.grok-sheet-item:active {
  background: rgba(200, 169, 107, 0.1);
}
.grok-sheet-item.danger { color: var(--error, #e07070); }
.grok-sheet-item.muted { color: var(--muted); text-align: center; margin-top: 4px; }

.grok-more-btn { min-width: 36px; }
.grok-send-btn {
  min-width: 64px;
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}
.grok-send-btn:not(:disabled):active {
  transform: scale(0.96);
}
.grok-icon-btn { min-width: 36px; }

/* Prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  .gmsg, .tui-proc, .tui-line, .tui-row, .gchat-empty, .gchat-empty-mark,
  .grok-session-item, .grok-status-chip, .grok-fab-bottom, .grok-sheet-panel {
    animation: none !important;
  }
}

/* ---------- Mobile-first shell ---------- */
@media (max-width: 900px) {
  /* Hide site chrome noise when Grok is active — more room for chat */
  .shell:has([data-view-panel="grok"]:not(.hidden)) {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  .console-content:has([data-view-panel="grok"]:not(.hidden)) {
    padding: 0 !important;
  }
  body:has([data-view-panel="grok"]:not(.hidden)) .site-footer,
  body:has([data-view-panel="grok"]:not(.hidden)) .console-nav {
    /* keep nav accessible but compact */
  }
  body:has([data-view-panel="grok"]:not(.hidden)) .site-footer {
    display: none !important;
  }

  .grok-view {
    gap: 0 !important;
    min-height: 100dvh !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    padding:
      env(safe-area-inset-top, 0px)
      0
      0 !important;
    background: var(--bg, #080808);
  }

  .grok-page-heading {
    display: none !important;
  }

  .grok-setup {
    margin: 0 10px 8px;
    border-radius: 14px;
    font-size: 14px;
  }
  .grok-setup-summary {
    padding: 12px 14px !important;
    font-size: 14px;
    min-height: 44px;
  }
  .grok-setup-title { font-size: 14px !important; }
  .grok-setup-hint { font-size: 12px !important; }
  .grok-setup-body {
    font-size: 15px;
  }
  .grok-setup-body input,
  .grok-setup-body select,
  .grok-setup-body textarea,
  .grok-setup-body button {
    font-size: 16px !important; /* no iOS zoom */
    min-height: 44px;
  }

  .grok-layout {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    border-radius: 0 !important;
  }

  .grok-chat-panel {
    border-radius: 0 !important;
    border-left: 0 !important;
    border-right: 0 !important;
    border-bottom: 0 !important;
    min-height: 0 !important;
    height: 100% !important;
    background: var(--surface, #101010) !important;
  }

  .grok-chat-top {
    padding:
      10px 10px 8px !important;
    backdrop-filter: blur(12px);
    background: color-mix(in srgb, var(--surface) 88%, transparent) !important;
  }

  .grok-chat-title-block h3 {
    font-size: 16px !important;
    font-weight: 650;
    letter-spacing: -0.01em;
  }

  .grok-chat-meta {
    display: none !important; /* chips replace dense meta on phone */
  }

  .grok-desk-only { display: none !important; }

  .grok-sessions-toggle {
    display: inline-flex !important;
    min-width: 40px;
    min-height: 40px;
    font-size: 16px;
    align-items: center;
    justify-content: center;
    border-radius: 12px !important;
  }

  .grok-chat-actions .button,
  .grok-chat-actions select {
    min-height: 36px;
    font-size: 13px;
  }

  .grok-effort-inline select {
    font-size: 14px !important;
    max-width: 78px;
    min-height: 36px;
  }

  .grok-chat-log {
    padding: 8px 0 12px !important;
    font-size: 15.5px;
    line-height: 1.55;
    -webkit-overflow-scrolling: touch;
  }

  .gchat-thread {
    padding: 4px 14px 16px !important;
    gap: 12px !important;
    max-width: 100% !important;
  }

  /* Typography scale — readable on phone */
  [data-view-panel="grok"] .gmsg-user .gmsg-body,
  [data-view-panel="grok"] .gmsg-plain {
    font-size: 15.5px !important;
    line-height: 1.55 !important;
  }
  [data-view-panel="grok"] .gmsg-assistant .gmsg-body,
  [data-view-panel="grok"] .gmd,
  [data-view-panel="grok"] .gmd-p {
    font-size: 15.5px !important;
    line-height: 1.6 !important;
  }
  [data-view-panel="grok"] .tui-line-thought {
    font-size: 13.5px !important;
  }
  [data-view-panel="grok"] .tui-line-tool {
    font-size: 12.5px !important;
    line-height: 1.4 !important;
  }
  [data-view-panel="grok"] .gmd-pre,
  [data-view-panel="grok"] .tui-pre {
    font-size: 12.5px !important;
  }
  [data-view-panel="grok"] .gmd-h {
    line-height: 1.3;
  }

  .gchat-empty h4 { font-size: 17px !important; }
  .gchat-empty p { font-size: 14px !important; line-height: 1.45; }

  /* Compose — thumb zone */
  .grok-compose-bar {
    padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    background: color-mix(in srgb, var(--surface) 94%, transparent) !important;
    backdrop-filter: blur(12px);
    border-top: 1px solid rgba(127, 127, 127, 0.14) !important;
  }
  .grok-compose-shell {
    border-radius: 20px !important;
    padding: 8px 10px 6px !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18) !important;
  }
  .grok-compose-shell textarea {
    font-size: 16px !important;
    line-height: 1.45 !important;
    min-height: 44px !important;
    max-height: 140px !important;
  }
  .grok-compose-actions .button {
    min-height: 40px !important;
    border-radius: 12px !important;
    font-size: 14px !important;
    padding: 0 12px !important;
  }
  .grok-send-btn {
    min-width: 72px !important;
    font-weight: 650;
  }
  .grok-compose-hint {
    font-size: 11.5px !important;
  }
  .grok-form-message {
    font-size: 12.5px !important;
    padding: 4px 12px 8px !important;
  }
  /* Mobile: pending attach previews must stay thumbnail-sized */
  .grok-image-preview {
    max-height: 72px !important;
    gap: 6px !important;
    margin-bottom: 6px !important;
  }
  .grok-image-chip {
    width: 56px !important;
    height: 56px !important;
  }
  .grok-image-chip img {
    width: 56px !important;
    height: 56px !important;
    max-width: 56px !important;
    max-height: 56px !important;
  }
  .grok-image-chip .rm {
    width: 18px !important;
    height: 18px !important;
    font-size: 13px !important;
  }
  .grok-new-session-panel {
    width: min(100%, 480px) !important;
    max-height: 90vh !important;
    padding: 14px 14px 16px !important;
  }
  .grok-yolo-row input[type="checkbox"] {
    width: 16px !important;
    height: 16px !important;
  }
  .gmsg-body img,
  .gchat-thread img {
    max-width: min(100%, 280px) !important;
    max-height: 220px !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain;
    border-radius: 10px;
  }

  .grok-fab-bottom {
    bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  }

  /* Sidebar drawer polish */
  .grok-sidebar {
    width: min(90vw, 340px) !important;
    padding-top: calc(14px + env(safe-area-inset-top, 0px)) !important;
    background: var(--surface) !important;
  }
  .grok-sidebar-titles h3 {
    font-size: 18px !important;
  }
  .grok-search {
    font-size: 16px !important;
    min-height: 42px;
    border-radius: 12px !important;
  }
  .grok-session-item {
    padding: 12px 12px !important;
    border-radius: 14px !important;
  }
  .grok-session-item .title {
    font-size: 15px !important;
  }
  .grok-session-item .meta,
  .grok-session-item .preview {
    font-size: 12.5px !important;
  }
  .grok-session-item .item-actions .button {
    min-height: 36px;
    font-size: 13px;
  }

  /* When chat is focused (session selected), tuck setup */
  .grok-view.grok-chat-focused .grok-setup {
    display: none;
  }
}

@media (max-width: 480px) {
  .grok-chat-title-block h3 {
    font-size: 15px !important;
  }
  .grok-status-chip {
    font-size: 10.5px;
    padding: 2px 7px;
  }
  .gchat-thread {
    padding: 4px 12px 14px !important;
  }
}

/* === Chronological timeline spacing (match TUI scrollback gaps) === */
[data-view-panel="grok"] .gchat-thread {
  display: flex !important;
  flex-direction: column !important;
  gap: 14px !important;
}
[data-view-panel="grok"] .gmsg-user {
  margin: 4px 0 2px !important;
}
[data-view-panel="grok"] .gmsg-assistant {
  margin: 4px 0 10px !important;
  padding-bottom: 10px !important;
  border-bottom: 1px solid rgba(127, 127, 127, 0.1) !important;
}
[data-view-panel="grok"] .tui-proc {
  display: flex !important;
  flex-direction: column !important;
  gap: 6px !important;
  margin: 2px 0 8px !important;
  padding: 6px 0 6px 2px !important;
  border-left: 2px solid rgba(127, 127, 127, 0.14);
  padding-left: 10px !important;
}
[data-view-panel="grok"] .tui-row,
[data-view-panel="grok"] .tui-line {
  margin: 0 !important;
  padding-top: 3px !important;
  padding-bottom: 3px !important;
}
[data-view-panel="grok"] .tui-line-tool + .tui-line-tool,
[data-view-panel="grok"] .tui-row + .tui-row {
  /* gap handled by flex on .tui-proc */
}
[data-view-panel="grok"] .tui-answer {
  margin-top: 2px !important;
}

/* === Ultra-compact chat stream spacing (TUI density) === */
.gchat-thread {
  gap: 4px !important;
  padding: 4px 12px 8px !important;
}

[data-view-panel="grok"] .gchat-thread {
  display: flex !important;
  flex-direction: column !important;
  gap: 3px !important;
  padding: 2px 10px 6px !important;
}

[data-view-panel="grok"] .gmsg {
  margin: 0 !important;
  padding: 0 !important;
}

[data-view-panel="grok"] .gmsg-user {
  margin: 6px 0 1px !important;
  padding-left: 8px !important;
  border-left-width: 2px !important;
}

[data-view-panel="grok"] .gmsg-assistant {
  margin: 1px 0 4px !important;
  padding-bottom: 4px !important;
  border-bottom: 1px solid rgba(127, 127, 127, 0.08) !important;
}

[data-view-panel="grok"] .gmsg-body {
  line-height: 1.4 !important;
  font-size: 14.5px !important;
}

[data-view-panel="grok"] .gmsg-plain,
[data-view-panel="grok"] .gmd-p {
  line-height: 1.4 !important;
  margin: 0 0 0.25em !important;
}

[data-view-panel="grok"] .gmd > :first-child { margin-top: 0 !important; }
[data-view-panel="grok"] .gmd > :last-child { margin-bottom: 0 !important; }
[data-view-panel="grok"] .gmd-h {
  margin: 0.35em 0 0.15em !important;
  line-height: 1.25 !important;
}
[data-view-panel="grok"] .gmd-ul,
[data-view-panel="grok"] .gmd-ol {
  margin: 0.2em 0 0.2em 1.1em !important;
  padding: 0 !important;
}
[data-view-panel="grok"] .gmd-ul li,
[data-view-panel="grok"] .gmd-ol li {
  margin: 0.05em 0 !important;
}
[data-view-panel="grok"] .gmd-code {
  margin: 0.3em 0 !important;
}
[data-view-panel="grok"] .gmd-pre {
  padding: 6px 8px !important;
  margin: 0 !important;
  line-height: 1.35 !important;
}

[data-view-panel="grok"] .tui-proc {
  display: flex !important;
  flex-direction: column !important;
  gap: 0 !important;
  margin: 1px 0 2px !important;
  padding: 0 0 0 8px !important;
  border-left: 1px solid rgba(127, 127, 127, 0.12) !important;
  background: transparent !important;
}

[data-view-panel="grok"] .tui-row,
[data-view-panel="grok"] .tui-line,
[data-view-panel="grok"] .tui-row > summary {
  margin: 0 !important;
  padding: 0 !important;
  line-height: 1.28 !important;
  min-height: 0 !important;
}

[data-view-panel="grok"] .tui-line-thought {
  font-size: 12px !important;
  line-height: 1.28 !important;
  padding: 0 !important;
}

[data-view-panel="grok"] .tui-line-tool {
  font-size: 11.5px !important;
  line-height: 1.25 !important;
  padding: 0 !important;
}

[data-view-panel="grok"] .tui-expand {
  margin: 1px 0 3px 6px !important;
  padding: 3px 6px !important;
  max-height: 160px !important;
  font-size: 12px !important;
  line-height: 1.35 !important;
}

[data-view-panel="grok"] .tui-answer {
  margin: 0 0 2px !important;
}

[data-view-panel="grok"] .gmsg-status {
  margin: 0 0 2px !important;
}

[data-view-panel="grok"] .gmsg-pill {
  padding: 0 6px !important;
  font-size: 10px !important;
}

/* kill loose animation offset that adds visual gap */
[data-view-panel="grok"] .gmsg,
[data-view-panel="grok"] .tui-proc {
  animation-duration: 0.18s !important;
}

@media (max-width: 900px) {
  [data-view-panel="grok"] .gchat-thread {
    gap: 3px !important;
    padding: 2px 10px 8px !important;
  }
  [data-view-panel="grok"] .gmsg-body {
    font-size: 14.5px !important;
    line-height: 1.4 !important;
  }
  [data-view-panel="grok"] .tui-line-tool {
    font-size: 11.5px !important;
  }
  [data-view-panel="grok"] .tui-line-thought {
    font-size: 12px !important;
  }
}
/* ==========================================================================
   GROK REMOTE — layout cleanup + mobile shell (final authority)
   Fixes stacked conflicting rules: fill remaining viewport below topbar+nav,
   keep chat column flex (log scrolls, compose sticky), session drawer on phone.
   ========================================================================== */

.gchat-empty-mobile { display: none; }
.gchat-empty-desk { display: block; margin: 0; }

/* Desktop: stable two-column workspace */
@media (min-width: 901px) {
  .grok-view {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
  }
  .grok-layout {
    display: grid !important;
    grid-template-columns: minmax(260px, 300px) minmax(0, 1fr) !important;
    gap: 14px !important;
    min-height: min(78vh, 840px) !important;
    height: min(78vh, 840px) !important;
    max-height: none !important;
    padding: 12px !important;
    align-items: stretch;
  }
  .grok-sidebar {
    position: relative !important;
    transform: none !important;
    width: auto !important;
    height: auto !important;
    max-height: none !important;
  }
  .grok-sidebar-close,
  .grok-sessions-toggle,
  .grok-sidebar-backdrop {
    display: none !important;
  }
  .grok-chat-panel {
    min-height: 0 !important;
    height: 100% !important;
    max-height: none !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
  }
  .grok-chat-log {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
  }
  .grok-desk-only { display: inline-flex !important; }
}

/* Phone / tablet: app-like remaining-viewport shell */
@media (max-width: 900px) {
  .gchat-empty-desk { display: none !important; }
  .gchat-empty-mobile { display: block !important; margin: 0; line-height: 1.5; }

  /* Kill legacy stack that forced short session list + overflow:visible chat */
  [data-view-panel="grok"] .panel-block.grok-layout {
    border: 0 !important;
    padding: 0 !important;
    background: transparent !important;
  }
  [data-view-panel="grok"] .grok-chat-panel {
    overflow: hidden !important;
    min-height: 0 !important;
    max-height: none !important;
  }
  [data-view-panel="grok"] .grok-session-list {
    max-height: none !important;
  }

  html.grok-remote-active,
  body.grok-remote-active {
    height: 100% !important;
    max-height: 100dvh !important;
    overflow: hidden !important;
  }

  body.grok-remote-active .site-frame {
    min-height: 0 !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }

  /* Compact topbar */
  body.grok-remote-active .topbar {
    flex: 0 0 auto !important;
    min-height: 48px !important;
    max-height: 52px !important;
  }
  body.grok-remote-active .brand-mark {
    width: 48px !important;
    font-size: 18px !important;
  }
  body.grok-remote-active .brand-lockup {
    min-width: 0 !important;
  }
  body.grok-remote-active .brand-lockup > div {
    padding: 0 10px !important;
  }
  body.grok-remote-active .brand-lockup h1 {
    font-size: 14px !important;
  }
  body.grok-remote-active .brand-lockup p,
  body.grok-remote-active .brand-zh {
    display: none !important;
  }
  body.grok-remote-active .session-block {
    padding: 0 10px !important;
    gap: 6px !important;
    font-size: 12px !important;
  }
  body.grok-remote-active .site-footer {
    display: none !important;
  }

  body.grok-remote-active .shell {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }

  body.grok-remote-active .console {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    display: flex !important;
    flex-direction: column !important;
    border: 0 !important;
    background: var(--bg, #080808) !important;
  }

  /* Horizontal nav — compact strip */
  body.grok-remote-active .console-nav {
    flex: 0 0 auto !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    grid-template-columns: none !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
    border-bottom: 1px solid var(--line) !important;
    border-right: 0 !important;
    background: var(--nav) !important;
    scrollbar-width: none;
  }
  body.grok-remote-active .console-nav::-webkit-scrollbar { display: none; }
  body.grok-remote-active .console-nav .nav-item {
    flex: 0 0 auto !important;
    min-width: auto !important;
    width: auto !important;
    min-height: 40px !important;
    padding: 6px 12px !important;
    border-top: 2px solid transparent !important;
    border-bottom: 0 !important;
    border-left: 0 !important;
    border-right: 1px solid var(--line) !important;
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
    grid-template-columns: none !important;
    white-space: nowrap;
    font-size: 12.5px !important;
  }
  body.grok-remote-active .console-nav .nav-item.active {
    border-top-color: var(--red) !important;
  }
  body.grok-remote-active .console-nav .nav-number {
    display: none !important;
  }

  body.grok-remote-active .console-content {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
  }

  body.grok-remote-active .grok-view {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    gap: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    background: var(--bg, #080808) !important;
  }

  body.grok-remote-active .grok-page-heading,
  body.grok-remote-active .grok-desk-heading {
    display: none !important;
  }

  body.grok-remote-active .grok-layout {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: none !important;
    gap: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    background: transparent !important;
    overflow: hidden !important;
  }

  /* Session drawer */
  body.grok-remote-active .grok-sidebar {
    position: fixed !important;
    z-index: 80 !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: min(88vw, 320px) !important;
    max-width: 320px !important;
    height: 100dvh !important;
    max-height: none !important;
    border-radius: 0 !important;
    border: 0 !important;
    border-right: 1px solid var(--line) !important;
    padding:
      calc(10px + env(safe-area-inset-top, 0px))
      12px
      calc(12px + env(safe-area-inset-bottom, 0px)) !important;
    transform: translateX(-105%) !important;
    transition: transform 0.22s ease !important;
    box-shadow: 8px 0 28px rgba(0, 0, 0, 0.3);
    background: var(--surface) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }
  body.grok-remote-active .grok-view.grok-sessions-open .grok-sidebar {
    transform: translateX(0) !important;
  }
  body.grok-remote-active .grok-sidebar-close {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-width: 2.75em !important;
    min-height: 34px !important;
    height: 34px !important;
    padding: 0 12px !important;
    line-height: 1 !important;
    white-space: nowrap !important;
    box-sizing: border-box !important;
  }
  body.grok-remote-active .grok-sidebar-actions {
    flex-wrap: nowrap !important;
  }
  body.grok-remote-active .grok-sidebar-actions .button {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    height: 34px !important;
    min-height: 34px !important;
    white-space: nowrap !important;
  }
  body.grok-remote-active .grok-sidebar-backdrop {
    display: block !important;
    position: fixed !important;
    inset: 0 !important;
    z-index: 75 !important;
    background: rgba(0, 0, 0, 0.48) !important;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  body.grok-remote-active .grok-view.grok-sessions-open .grok-sidebar-backdrop {
    opacity: 1 !important;
    pointer-events: auto !important;
  }
  body.grok-remote-active .grok-session-list {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: auto !important;
  }

  /* Chat column fills remaining height */
  body.grok-remote-active .grok-chat-panel {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    border-radius: 0 !important;
    border: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    background: var(--surface) !important;
  }

  body.grok-remote-active .grok-chat-top {
    flex: 0 0 auto !important;
    padding: 8px 10px 6px !important;
    border-bottom: 1px solid var(--line) !important;
  }
  body.grok-remote-active .grok-chat-top-row {
    align-items: center !important;
    gap: 8px !important;
  }
  body.grok-remote-active .grok-sessions-toggle {
    display: inline-flex !important;
    min-width: 40px !important;
    min-height: 40px !important;
    align-items: center;
    justify-content: center;
    border-radius: 12px !important;
    flex-shrink: 0 !important;
  }
  body.grok-remote-active .grok-chat-title-block {
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }
  body.grok-remote-active .grok-chat-title-block h3 {
    font-size: 15px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  body.grok-remote-active .grok-chat-meta {
    display: none !important;
  }
  body.grok-remote-active .grok-status-chips {
    margin-top: 3px !important;
    gap: 4px !important;
  }
  body.grok-remote-active .grok-status-chip {
    font-size: 10.5px !important;
    padding: 2px 7px !important;
  }
  body.grok-remote-active .grok-chat-actions {
    flex-shrink: 0 !important;
    gap: 4px !important;
    flex-wrap: nowrap !important;
  }
  body.grok-remote-active .grok-desk-only {
    display: none !important;
  }
  body.grok-remote-active .grok-effort-label {
    display: none !important;
  }
  body.grok-remote-active .grok-effort-inline select {
    max-width: 72px !important;
    min-height: 34px !important;
    font-size: 12px !important;
  }
  body.grok-remote-active .grok-quickbar {
    margin-top: 6px !important;
    padding-top: 6px !important;
    gap: 5px !important;
  }
  body.grok-remote-active .grok-chip-btn {
    font-size: 11.5px !important;
    padding: 5px 9px !important;
  }

  body.grok-remote-active .grok-chat-log {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior: contain !important;
    padding: 6px 0 10px !important;
  }

  body.grok-remote-active .gchat-thread {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 4px 12px 12px !important;
    gap: 12px !important;
    box-sizing: border-box !important;
  }

  body.grok-remote-active .gchat-empty {
    min-height: 180px !important;
    padding: 24px 16px !important;
  }

  /* Messages: single column, no avatar grid squeeze */
  body.grok-remote-active .gmsg,
  body.grok-remote-active .gmsg-user,
  body.grok-remote-active .gmsg-assistant {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    grid-template-columns: none !important;
  }
  body.grok-remote-active .gmsg-avatar {
    display: none !important;
  }
  body.grok-remote-active .gmsg-user {
    border-left: 3px solid rgba(80, 200, 220, 0.7) !important;
    padding: 2px 0 2px 10px !important;
    margin: 2px 0 !important;
  }
  body.grok-remote-active .gmsg-user .gmsg-body {
    max-width: 100% !important;
    width: 100% !important;
    padding: 0 !important;
    background: transparent !important;
    border: 0 !important;
    border-radius: 0 !important;
  }
  body.grok-remote-active .gmsg-body,
  body.grok-remote-active .gmsg-main,
  body.grok-remote-active .gmsg-main-full,
  body.grok-remote-active .gmd,
  body.grok-remote-active .gmsg-plain {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    overflow-wrap: break-word !important;
    word-break: break-word !important;
  }
  body.grok-remote-active .gmd-pre,
  body.grok-remote-active .gcard-pre,
  body.grok-remote-active .gtl-pre {
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Compose sticky bottom */
  body.grok-remote-active .grok-compose,
  body.grok-remote-active .grok-compose-bar {
    flex: 0 0 auto !important;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px)) !important;
    border-top: 1px solid rgba(127, 127, 127, 0.14) !important;
    background: color-mix(in srgb, var(--surface) 96%, transparent) !important;
  }
  body.grok-remote-active .grok-compose-shell {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    border-radius: 16px !important;
    padding: 8px 10px 6px !important;
    box-sizing: border-box !important;
  }
  body.grok-remote-active .grok-compose-shell textarea {
    font-size: 16px !important; /* prevent iOS zoom */
    min-height: 40px !important;
    max-height: 120px !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }
  body.grok-remote-active .grok-compose-toolbar {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 8px !important;
    flex-wrap: wrap !important;
  }
  body.grok-remote-active .grok-compose-actions {
    display: flex !important;
    gap: 6px !important;
    margin-left: auto !important;
  }
  body.grok-remote-active .grok-compose-actions .button {
    min-height: 36px !important;
  }
  body.grok-remote-active .grok-form-message {
    padding: 0 12px 6px !important;
    margin: 0 !important;
  }
  body.grok-remote-active .grok-form-message:empty {
    display: none !important;
  }

  body.grok-remote-active .grok-fab-bottom {
    bottom: calc(84px + env(safe-area-inset-bottom, 0px)) !important;
    right: 12px !important;
  }

  /* Modal full-bleed on small screens */
  body.grok-remote-active .grok-modal-panel {
    width: min(100vw - 16px, 480px) !important;
    max-height: min(90dvh, 720px) !important;
    overflow: auto !important;
    margin: 8px !important;
  }
  body.grok-remote-active .grok-browse-bar {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
  }
  body.grok-remote-active .grok-browse-bar input {
    flex: 1 1 100% !important;
    min-width: 0 !important;
    font-size: 16px !important;
  }
}

@media (max-width: 480px) {
  body.grok-remote-active .console-nav .nav-item {
    padding: 6px 10px !important;
    font-size: 12px !important;
  }
  body.grok-remote-active .gchat-thread {
    padding: 4px 10px 10px !important;
  }
  body.grok-remote-active .grok-chat-title-block h3 {
    font-size: 14px !important;
  }
}

/* ── Emas Agent live terminal ───────────────────────────────── */
.agent-term-panel .agent-term-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.agent-term {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0a0c0b;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.03);
}
html[data-theme="light"] .agent-term {
  background: #121512;
}
.agent-term-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: linear-gradient(180deg, #141816 0%, #0e100f 100%);
}
.agent-term-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid rgba(255,255,255,0.08);
  color: #d8d8d3;
  background: rgba(255,255,255,0.04);
}
.agent-term-pill.is-idle { color: #9a9a94; }
.agent-term-pill.is-queue { color: #e0c36a; border-color: rgba(224,195,106,0.35); }
.agent-term-pill.is-run {
  color: #7dffa8;
  border-color: rgba(105,197,138,0.45);
  box-shadow: 0 0 0 1px rgba(105,197,138,0.12);
  animation: agent-term-pulse 1.4s ease-in-out infinite;
}
.agent-term-pill.is-ok { color: #69c58a; border-color: rgba(105,197,138,0.4); }
.agent-term-pill.is-bad { color: #ff7a7a; border-color: rgba(255,97,97,0.4); }
@keyframes agent-term-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.72; }
}
.agent-term-meta {
  flex: 1 1 180px;
  min-width: 0;
  color: #8e948e;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agent-term-screen {
  min-height: 280px;
  max-height: min(58vh, 560px);
  overflow: auto;
  padding: 12px 14px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Cascadia Mono", monospace;
  font-size: 12.5px;
  line-height: 1.5;
  color: #d7e0d7;
  white-space: pre-wrap;
  word-break: break-word;
  scrollbar-width: thin;
}
.agent-term-placeholder {
  color: #6d746d;
  line-height: 1.7;
}
.agent-term-line { margin: 0 0 2px; }
.agent-term-meta-line { color: #6f7a6f; }
.agent-term-dim { color: #7a857a; }
.agent-term-prompt { margin: 8px 0 6px; }
.agent-term-ps { color: #7dffa8; font-weight: 600; }
.agent-term-cmd { color: #f3f7f3; }
.agent-term-block {
  margin: 0 0 8px;
  white-space: pre-wrap;
}
.agent-term-out { color: #e6eee6; }
.agent-term-err { color: #ff9b9b; }
.agent-term-ok { color: #69c58a; }
.agent-term-cursor {
  display: inline-block;
  width: 8px;
  height: 14px;
  margin-top: 4px;
  background: #7dffa8;
  animation: agent-term-blink 1s step-end infinite;
  vertical-align: text-bottom;
}
@keyframes agent-term-blink {
  50% { opacity: 0; }
}
#agentTermFollowBtn.is-active {
  border-color: rgba(105,197,138,0.45);
  color: #9adbb2;
}
tr.agent-job-live td {
  background: rgba(105, 197, 138, 0.06);
}
.agent-job-detail-legacy { display: none !important; }
@media (max-width: 720px) {
  .agent-term-screen {
    min-height: 220px;
    max-height: 48vh;
    font-size: 12px;
  }
}

/* ============ 游戏分类 / 五子棋 ============ */
.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.game-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
  outline: none;
}

.game-card:hover,
.game-card:focus-visible {
  border-color: var(--line-hover);
  background: var(--card-hover);
  transform: translateY(-2px);
}

.game-card-top {
  display: flex;
  align-items: center;
  gap: 14px;
}

.game-card-icon {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 700;
  color: #f5f5f2;
  background: linear-gradient(135deg, #232323, #000);
  border: 1px solid var(--line-strong);
}

.game-card-titles .section-kicker {
  font-size: 11px;
}

.game-card h3 {
  margin: 2px 0 0;
  font-size: 20px;
}

.game-card-desc {
  margin: 0;
  color: var(--muted-2);
  font-size: 13px;
  line-height: 1.7;
}

.game-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.game-chip {
  font-size: 12px;
  color: var(--muted-2);
  border: 1px solid var(--line);
  padding: 3px 9px;
  background: var(--surface-2);
}

.game-card-play {
  align-self: flex-start;
  margin-top: auto;
}

.games-more-note {
  margin-top: 18px;
}

.gomoku-head-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.gomoku-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 26px;
  align-items: start;
}

.gomoku-main {
  min-width: 0;
}

.gomoku-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.gomoku-turn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-strong);
}

.g-turn-stone {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.gomoku-status-right {
  display: inline-flex;
  align-items: center;
  gap: 14px;
}

.gomoku-timer {
  font-family: Consolas, monospace;
  font-size: 16px;
  color: var(--red);
  min-width: 74px;
  text-align: right;
}

.gomoku-timer.is-idle {
  color: var(--muted);
}

.g-board-wrap {
  position: relative;
  width: min(100%, 640px);
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  touch-action: none;
}

#gomokuCanvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.35);
}

.g-banner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.48);
  border-radius: 6px;
  z-index: 5;
}

.g-banner-box {
  min-width: min(280px, 78%);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.g-banner-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-strong);
}

.g-banner-sub {
  color: var(--muted-2);
  font-size: 13px;
}

.g-banner-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 10px;
  flex-wrap: wrap;
}

.gomoku-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
}

.gomoku-timer-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted-2);
  font-size: 12px;
  border: 1px solid var(--line);
  padding: 8px 10px;
  background: var(--surface-2);
}

.gomoku-timer-select select {
  width: auto;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 4px 6px;
}

.gomoku-side {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.gomoku-players {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.g-player {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  padding: 12px 14px;
  transition: border-color 0.15s, background 0.15s;
}

.g-player.active {
  border-color: var(--red);
  background: var(--card-hover);
  box-shadow: inset 3px 0 0 var(--red);
}

.g-player-stone {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  color: var(--muted);
}

.g-stone-black {
  background: radial-gradient(circle at 35% 30%, #555, #000 75%);
  border: 1px solid #000;
}

.g-stone-white {
  background: radial-gradient(circle at 35% 30%, #fff, #cfcfcf 75%);
  border: 1px solid #999;
}

.g-stone-draw {
  border: 1px dashed var(--line-strong);
}

.g-player-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.g-player-name {
  font-weight: 600;
  color: var(--text-strong);
}

.g-player-label {
  font-size: 11px;
  color: var(--muted);
}

.g-player-score {
  font-family: Consolas, monospace;
  font-size: 22px;
  color: var(--text-strong);
}

.gomoku-settings-row {
  display: flex;
  justify-content: flex-end;
}

.g-moves-panel {
  border: 1px solid var(--line);
  background: var(--surface-2);
  padding: 14px;
}

.g-moves-list {
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  align-content: flex-start;
}

.g-move-chip {
  font-family: Consolas, monospace;
  font-size: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 3px 7px;
  color: var(--table-cell);
  white-space: nowrap;
}

.g-move-chip b {
  color: var(--text-strong);
  font-weight: 600;
}

.g-rules {
  border: 1px solid var(--line);
  background: var(--surface-2);
  padding: 12px 14px;
}

.g-rules summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-strong);
  user-select: none;
}

.g-rules ol {
  margin: 10px 0 2px;
  padding-left: 20px;
  color: var(--muted-2);
  font-size: 13px;
  line-height: 1.8;
}

.g-rules li + li {
  margin-top: 4px;
}

@media (max-width: 1100px) {
  .gomoku-layout {
    grid-template-columns: 1fr;
  }

  .gomoku-side {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }

  .g-rules {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .game-card-icon {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
    font-size: 20px;
  }

  .gomoku-side {
    grid-template-columns: 1fr;
  }

  .gomoku-turn {
    font-size: 16px;
  }

  .gomoku-status-right {
    width: 100%;
    justify-content: space-between;
  }
}

/* ============ 五子棋：模式选择 / 联机对战 ============ */
.gomoku-mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  max-width: 860px;
}

.gomoku-online-setup .settings-grid {
  max-width: 900px;
}

.gomoku-waiting {
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  padding: 34px 26px;
}

.gomoku-room-code {
  font-family: Consolas, monospace;
  font-size: 52px;
  font-weight: 700;
  letter-spacing: 10px;
  color: var(--text-strong);
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  padding: 12px 18px 12px 26px;
  user-select: all;
}

.gomoku-waiting-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 6px;
}

.gomoku-online-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-bottom: 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 13px;
  color: var(--muted-2);
}

.gomoku-room-chip {
  font-family: Consolas, monospace;
  color: var(--text-strong);
  font-size: 14px;
}

.gomoku-room-chip b {
  letter-spacing: 3px;
  margin-left: 4px;
}

.gomoku-opp-state {
  margin-left: auto;
  color: var(--green);
}

.gomoku-opp-state.gomoku-opp-off {
  color: var(--danger-text);
}

.gomoku-online-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px 14px;
  border: 1px solid var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger-text);
  font-size: 13px;
}

.gomoku-notice-actions {
  display: inline-flex;
  gap: 8px;
}

/* ============ 合体双星（同屏双人合作） ============ */
.coop-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 26px;
  align-items: start;
}

.coop-stage {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  aspect-ratio: 720 / 1000;
  touch-action: none;
}

#coopCanvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  touch-action: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.35);
}

.coop-hud {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  z-index: 6;
  pointer-events: none;
}

.coop-hud .button {
  pointer-events: auto;
}

.coop-hud-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: rgba(0, 0, 0, 0.38);
  padding: 8px 12px;
  border-radius: 8px;
}

.coop-score-label {
  font-size: 11px;
  color: #ddd;
}

.coop-score {
  font-family: Consolas, monospace;
  font-size: 22px;
  color: #fff;
}

.coop-hud-mid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: rgba(0, 0, 0, 0.38);
  padding: 8px 12px;
  border-radius: 8px;
}

.coop-hearts {
  color: #ff5c5c;
  font-size: 18px;
  letter-spacing: 2px;
}

.coop-combo {
  color: #ffd76a;
  font-weight: 700;
  font-size: 14px;
}

.coop-hud-right {
  display: flex;
  gap: 8px;
}

.coop-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.52);
  border-radius: 8px;
  z-index: 8;
}

.coop-menu-box {
  width: min(88%, 400px);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  padding: 26px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  align-items: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.coop-menu-box h3 {
  margin: 0;
  font-size: 24px;
}

.coop-difficulty {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.coop-diff-btn.is-active {
  border-color: var(--red);
  color: var(--text-strong);
  background: var(--card-hover);
}

.coop-best {
  min-height: 18px;
}

.coop-start {
  min-width: 180px;
}

.coop-tips {
  margin: 0;
  color: var(--muted-2);
  font-size: 12px;
  line-height: 1.8;
}

.coop-menu-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.coop-over-score {
  margin: 0;
  font-size: 15px;
  color: var(--muted-2);
}

.coop-over-score strong {
  color: var(--text-strong);
  font-size: 22px;
  font-family: Consolas, monospace;
}

.coop-side {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.coop-stats {
  border: 1px solid var(--line);
  background: var(--surface-2);
  padding: 14px;
}

@media (max-width: 1100px) {
  .coop-layout {
    grid-template-columns: 1fr;
  }

  .coop-side {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

@media (max-width: 640px) {
  .coop-side {
    grid-template-columns: 1fr;
  }

  .coop-stage {
    max-width: 420px;
  }
}

/* ============ 双人共生（同屏双人：移动 + 射击） ============ */
.shooter-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 26px;
  align-items: start;
}

.shooter-stage {
  position: relative;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  aspect-ratio: 1280 / 800;
  touch-action: none;
  overflow: hidden;
  border-radius: 8px;
}

#shooterCanvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.35);
}

.shooter-hud {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  z-index: 6;
  pointer-events: none;
}

.shooter-hud .button {
  pointer-events: auto;
}

.shooter-hud-left,
.shooter-hud-mid,
.shooter-hud-right {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: rgba(0, 0, 0, 0.4);
  padding: 7px 11px;
  border-radius: 8px;
}

.shooter-hearts {
  color: #ff5c5c;
  font-size: 17px;
  letter-spacing: 2px;
}

.shooter-wave {
  color: #ddd;
  font-size: 12px;
}

.shooter-score {
  font-family: Consolas, monospace;
  font-size: 21px;
  color: #fff;
  text-align: center;
}

.shooter-combo {
  color: #ffd76a;
  font-weight: 700;
  font-size: 13px;
  text-align: center;
}

.shooter-weapon {
  color: #9adbb2;
  font-size: 12px;
  text-align: right;
}

.shooter-hud-right {
  align-items: flex-end;
}

.shooter-touch {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  border-radius: 8px;
}

.shooter-zone-label {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  color: rgba(255, 255, 255, 0.5);
  background: rgba(0, 0, 0, 0.25);
  padding: 4px 10px;
  border-radius: 12px;
  letter-spacing: 2px;
}

.shooter-zone-move {
  left: 12px;
}

.shooter-zone-aim {
  right: 12px;
}

.shooter-joy-base {
  position: absolute;
  width: 92px;
  height: 92px;
  margin-left: -46px;
  margin-top: -46px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
}

.shooter-joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42px;
  height: 42px;
  margin-left: -21px;
  margin-top: -21px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
}

.shooter-aim-base {
  border-color: rgba(255, 215, 106, 0.65);
  background: rgba(255, 215, 106, 0.10);
}

.shooter-aim-base .shooter-joy-knob {
  background: rgba(255, 215, 106, 0.9);
}

.shooter-rotate-hint {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.82);
}

.shooter-rotate-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  color: #fff;
  padding: 26px;
}

.shooter-rotate-icon {
  font-size: 58px;
  animation: shooter-rotate 1.6s ease-in-out infinite;
}

@keyframes shooter-rotate {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
}

.shooter-rotate-box p {
  margin: 0;
  font-size: 16px;
  line-height: 1.8;
}

.shooter-rotate-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.shooter-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 8px;
  z-index: 8;
}

.shooter-menu-box {
  width: min(88%, 420px);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  padding: 26px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  align-items: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.shooter-menu-box h3 {
  margin: 0;
  font-size: 24px;
}

.shooter-diff-btn.is-active {
  border-color: var(--red);
  color: var(--text-strong);
  background: var(--card-hover);
}

.shooter-wave-banner {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 34px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 3px 14px rgba(0, 0, 0, 0.8);
  letter-spacing: 4px;
  z-index: 7;
  pointer-events: none;
  white-space: nowrap;
}

.shooter-wave-banner.shooter-wave-boss {
  color: #ff9ff3;
  font-size: 38px;
}

.shooter-side {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (max-width: 1100px) {
  .shooter-layout {
    grid-template-columns: 1fr;
  }

  .shooter-side {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

@media (max-width: 640px) {
  .shooter-side {
    grid-template-columns: 1fr;
  }

  .shooter-wave-banner {
    font-size: 24px;
    letter-spacing: 2px;
  }

  .shooter-wave-banner.shooter-wave-boss {
    font-size: 27px;
  }
}

/* 手机横屏：游戏区优先，隐藏侧栏，画布尽量占满 */
@media (max-height: 540px) and (orientation: landscape) {
  .shooter-side {
    display: none;
  }

  .shooter-layout {
    grid-template-columns: 1fr;
  }

  .shooter-stage {
    max-width: none;
    width: min(100%, calc((100dvh - 118px) * 1.6));
  }

  .shooter-zone-label {
    font-size: 11px;
    padding: 3px 8px;
  }
}

/* 全屏模式（真全屏 API 或移动端伪全屏）：隐藏站点骨架，游戏占满视口 */
body.shooter-fullscreen .topbar,
body.shooter-fullscreen .console-nav,
body.shooter-fullscreen .site-footer,
body.shooter-fullscreen .shooter-side,
body.shooter-fullscreen #shooterPanel .page-heading {
  display: none !important;
}

body.shooter-fullscreen .shell {
  width: 100%;
  padding-top: 0;
}

body.shooter-fullscreen .console {
  grid-template-columns: 1fr;
  min-height: 100dvh;
  border: 0;
}

body.shooter-fullscreen .console-content {
  padding: 8px;
}

body.shooter-fullscreen .shooter-layout {
  grid-template-columns: 1fr;
  gap: 0;
}

body.shooter-fullscreen .shooter-stage {
  max-width: none;
  width: min(100%, calc((100dvh - 20px) * 1.6));
}

body.shooter-fullscreen .shooter-hud {
  top: 8px;
  left: 10px;
  right: 10px;
}
