:root {
  --bg: #eef0f3;
  --panel: #ffffff;
  --ink: #1f2329;
  --ink-2: #4a505a;
  --muted: #6b7280;
  --line: #e3e6eb;
  --soft: #f4f5f7;
  --dark: #262a33;
  --accent: #3b4cca;
  --accent-soft: #e4e7f6;
  --success: #17703f;
  --danger: #c62828;
  --warn: #b45309;
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 15px; -webkit-font-smoothing: antialiased; }
button, input { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

.ico { display: inline-flex; line-height: 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid transparent; border-radius: 10px;
  padding: 9px 16px; font-weight: 650; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn-dark, .btn-primary { background: var(--dark); color: #fff; }
.btn-dark:hover, .btn-primary:hover { background: #111318; }
.btn-light { background: var(--soft); color: var(--ink); border-color: var(--line); }
.btn-light:hover { background: #e9ebef; }
.btn-light.danger { color: var(--danger); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--soft); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #115a32; }
.btn-run { background: var(--accent); color: #fff; padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; justify-content: center; padding: 12px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px;
  border: 0; background: transparent; border-radius: 8px; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { background: var(--soft); }
.icon-btn.sm { width: 28px; height: 28px; }
.seg { display: inline-flex; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: #fff; }
.seg .btn { border-radius: 0; padding: 11px 18px; font-size: 16px; }
.seg .seg-right { background: #fff; border: 0; }
.seg .seg-right:hover { background: var(--soft); }

/* ---------- inputs ---------- */
.input, .field input, .auth-form input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--soft); outline: none;
}
.input:focus, .field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: #fff; }
.field { display: grid; gap: 6px; margin: 14px 0 0; }
.field > span { font-weight: 600; font-size: 14px; }
.form-error { color: var(--danger); margin: 10px 0 0; font-size: 14px; }
.search-wrap { position: relative; margin: 18px 0 14px; }
.search-wrap .ico { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-wrap .input { padding-left: 44px; }

/* ---------- auth ---------- */
.auth-page { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(420px, 100%); background: var(--panel); border-radius: 20px; padding: 32px; box-shadow: 0 10px 40px rgba(20, 24, 40, .08); }
.auth-card h1 { font-size: 28px; font-weight: 800; margin-top: 22px; }
.auth-card .muted { margin: 6px 0 4px; }
.auth-form .btn { margin-top: 22px; }
.auth-switch { text-align: center; margin: 18px 0 0; color: var(--muted); }

/* ---------- shell ---------- */
.app-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { display: flex; flex-direction: column; padding: 18px 12px; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; color: var(--ink); text-decoration: none; letter-spacing: -0.02em; }
.brand img { width: 30px; height: 30px; }
.brand.big { font-size: 20px; }
.sidebar nav { display: grid; gap: 4px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: 14px; }
.nav-item:hover { background: #e5e7eb; }
.nav-item.active { background: #e1e4ea; color: var(--ink); }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; padding: 6px; border-radius: 10px; cursor: pointer; text-align: left; }
.user-chip:hover { background: #e5e7eb; }
.user-name { flex: 1; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main-panel { background: var(--panel); margin: 10px 10px 10px 0; border-radius: 22px; padding: 44px 48px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 26px; }
.page-head h1 { font-size: 42px; font-weight: 900; letter-spacing: -0.035em; }
.rule { border: 0; border-top: 1px solid var(--line); margin: 14px 0 22px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; padding: 6px 13px; border-radius: 8px; font-size: 14px; cursor: pointer; color: var(--ink-2); text-decoration: none; }
.chip:hover { background: var(--soft); }
.chip.active { background: #e1e4ea; border-color: #d4d8e0; color: var(--ink); font-weight: 600; }
.empty { color: var(--muted); padding: 40px 0; }

/* ---------- cards ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.card { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; cursor: pointer; overflow: hidden; display: flex; flex-direction: column; transition: box-shadow .15s, transform .15s; }
.card:hover, .card:focus-visible { box-shadow: 0 8px 26px rgba(20, 24, 40, .09); transform: translateY(-2px); outline: none; }
.card-thumb { height: 150px; display: grid; place-items: center; position: relative; }
.type-badge { position: absolute; right: 10px; bottom: 10px; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 700; color: var(--ink); }
.card-body { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 10px; }
.card-body h3 { font-size: 16px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-foot { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px 8px 16px; border-top: 1px solid var(--line); }
.status { font-size: 13px; font-weight: 700; }
.status.pub { color: var(--success); }
.status.priv { color: var(--muted); }
.link { font-weight: 600; text-decoration: none; }

.tone-pink { background: #fce7f1; color: #b03a6f; }
.tone-blue { background: #e3f1fb; color: #1f6c99; }
.tone-violet { background: #ece8fd; color: #5b45c8; }
.tone-teal { background: #e0f2f5; color: #1e6f7e; }

/* ---------- avatars ---------- */
.avatar { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 800; flex: none; border: 2px solid #fff; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.xs { width: 26px; height: 26px; font-size: 10px; }
.avatars { display: flex; align-items: center; }
.avatars .avatar + .avatar { margin-left: -8px; }
.online-dot { width: 9px; height: 9px; border-radius: 50%; background: #22c55e; margin-left: 6px; box-shadow: 0 0 0 3px #22c55e33; }

/* ---------- popovers & modal ---------- */
.popover { position: fixed; z-index: 50; background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 16px 50px rgba(20, 24, 40, .16); padding: 22px; width: 380px; max-width: calc(100vw - 24px); }
.popover h3 { font-size: 20px; font-weight: 800; }
.popover h4 { margin: 18px 0 8px; font-size: 14px; }
.pop-head { display: flex; align-items: center; justify-content: space-between; }
.popover.menu { width: 220px; padding: 6px; border-radius: 12px; }
.menu-item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.menu-item:hover { background: var(--soft); }
.menu-item.danger { color: var(--danger); }
.code-input { font-family: var(--mono); font-size: 22px; letter-spacing: .3em; }
.invite-code { font-family: var(--mono); font-size: 34px; font-weight: 700; letter-spacing: .25em; text-align: center; padding: 14px; background: var(--soft); border-radius: 12px; margin-top: 14px; cursor: copy; }
.member-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.member-list li { display: flex; align-items: center; gap: 10px; }
.badge { display: inline-block; margin-left: 8px; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); vertical-align: middle; }
.badge.danger { background: #fde2e2; color: var(--danger); }

.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(30, 34, 42, .28); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 20px; }
.modal { background: #fff; border-radius: 22px; padding: 34px 38px; width: min(640px, 100%); max-height: calc(100vh - 40px); overflow: auto; box-shadow: 0 30px 80px rgba(20, 24, 40, .25); }
.modal.wide { width: min(1100px, 100%); }
.modal h2 { font-size: 30px; font-weight: 800; }
.modal > .muted, .modal p.muted { margin: 4px 0 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.tpl-list { display: grid; gap: 8px; max-height: 330px; overflow: auto; padding: 2px 4px 2px 2px; }
.tpl { display: flex; align-items: center; gap: 16px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.tpl:hover { background: var(--soft); }
.tpl.selected { background: #e4e7ee; border-color: #4554a8; }
.tpl input { margin-left: auto; width: 22px; height: 22px; accent-color: var(--accent); }
.tpl-icon { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 10px; flex: none; }
.tpl-text { display: grid; gap: 2px; }
.tpl-text strong { font-size: 17px; font-weight: 800; }
.tpl-text span { color: var(--ink-2); font-size: 14px; }

#toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--dark); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; z-index: 100; transition: .2s; max-width: calc(100vw - 40px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- learn ---------- */
.learn-list { display: grid; gap: 10px; max-width: 760px; }
.learn-item { display: flex; align-items: center; gap: 16px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: inherit; }
a.learn-item:hover { background: var(--soft); }

/* ---------- editor ---------- */
.editor-shell { display: grid; grid-template-rows: auto 1fr auto; height: 100vh; background: #fff; }
.editor-header { display: flex; align-items: center; gap: 12px; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.editor-titles { display: grid; flex: 1; min-width: 0; }
.type-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.editor-title { border: 1px solid transparent; background: none; font-size: 17px; font-weight: 800; padding: 1px 4px; margin-left: -5px; border-radius: 6px; max-width: 420px; }
.editor-title:hover:not([readonly]), .editor-title:focus { border-color: var(--line); outline: none; }
.editor-header-right { display: flex; align-items: center; gap: 8px; }
.presence { display: flex; margin-right: 6px; }
.presence .avatar + .avatar { margin-left: -6px; }
.editor-main { display: grid; grid-template-columns: 50% 6px 1fr; min-height: 0; }
.editor-main.only-code { grid-template-columns: 1fr 0 0 !important; }
.editor-main.only-preview { grid-template-columns: 0 0 1fr !important; }
.editor-main.only-code .pane-preview, .editor-main.only-preview .pane-code { display: none; }
.pane { display: grid; grid-template-rows: auto 1fr auto; min-width: 0; min-height: 0; }
.pane-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; background: var(--soft); border-bottom: 1px solid var(--line); min-height: 44px; }
.pane-actions { display: flex; align-items: center; gap: 6px; }
.pane-label { font-weight: 700; font-size: 13px; padding-left: 4px; }
.file-tabs { display: flex; gap: 4px; overflow-x: auto; }
.file-tab { border: 1px solid transparent; background: none; padding: 5px 10px; border-radius: 7px; font-family: var(--mono); font-size: 12px; cursor: pointer; color: var(--ink-2); display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.file-tab:hover { background: #e7e9ee; }
.file-tab.active { background: #fff; border-color: var(--line); color: var(--ink); font-weight: 700; }
.file-tabs.light { margin: 8px 0; }
.tab-dot { width: 7px; height: 7px; border-radius: 50%; }
.code-host { min-height: 0; overflow: hidden; background: #282c34; }
.code-host .cm-editor { height: 100%; }
.code-host.blocks-host { background: #fff; position: relative; }
.splitter { background: var(--line); cursor: col-resize; }
.splitter:hover { background: #c9cdd6; }
.preview-host { min-height: 0; background: #fff; position: relative; }
.preview-frame { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
.preview-empty { display: grid; place-items: center; height: 100%; color: var(--muted); }
.console { max-height: 160px; overflow: auto; font: 12px/1.5 var(--mono); background: #1e222a; color: #d4d4d4; padding: 6px 10px; border-top: 1px solid #000; }
.console .log-error { color: #ff8a80; }
.console .log-warn { color: #ffd479; }
.auto-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); cursor: pointer; user-select: none; }
.editor-footer { padding: 4px 14px; border-top: 1px solid var(--line); font-size: 12px; }
.save-status::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #22c55e; margin-right: 6px; vertical-align: 1px; }
.save-status.offline::before { background: #f59e0b; }
.popover.team-pop { width: 340px; }
.popover.team-pop p { margin: 8px 0 0; font-size: 14px; }

/* yjs remote cursors */
.cm-ySelectionInfo { font-family: var(--font) !important; font-weight: 700; font-size: 11px !important; padding: 1px 4px !important; border-radius: 4px 4px 4px 0; opacity: 1 !important; top: -1.25em !important; }

/* ---------- admin ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.stat { border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.stat-n { font-size: 34px; font-weight: 900; letter-spacing: -0.03em; }
.stat-l { color: var(--muted); font-size: 14px; font-weight: 600; }
.stat.warn { border-color: #f5c99b; background: #fff8f0; }
.stat.warn .stat-n { color: var(--warn); }
.rules-box { margin-top: 26px; border: 1px dashed #cfd3db; border-radius: 14px; padding: 18px 22px; background: #fafbfc; }
.rules-box h3 { font-size: 16px; }
.rules-box ul { margin: 10px 0 0; padding-left: 20px; color: var(--ink-2); line-height: 1.6; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table.compact td { padding: 6px 10px; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--soft); }
.table tr.deleted td { opacity: .55; }
.table tr.susp td { background: #fff6ed; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.flag { display: inline-block; font-size: 12px; font-weight: 800; padding: 3px 8px; border-radius: 999px; margin: 2px 4px 2px 0; white-space: nowrap; }
.flag.ai { background: #fde2e2; color: #b42318; }
.flag.ev { background: #ffedd5; color: #9a3412; }
.flag.sm { margin-left: 6px; padding: 1px 6px; }
.inline-form { display: grid; grid-template-columns: 1fr 1.5fr 1fr auto; gap: 10px; margin: 16px 0 20px; }
.big-code { font-family: var(--mono); font-size: 15px; font-weight: 700; background: var(--soft); padding: 3px 8px; border-radius: 6px; }
.detail-head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.detail-actions { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.detail h3 { margin: 26px 0 10px; font-size: 17px; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 20px 0 0; font-size: 14px; }
.meta dt { color: var(--muted); font-weight: 600; }
.meta dd { margin: 0; }
.code-view { background: #282c34; color: #e6e6e6; font: 13px/1.5 var(--mono); padding: 14px 16px; border-radius: 10px; max-height: 420px; overflow: auto; margin: 0; white-space: pre; }
.code-view.sm { max-height: 160px; font-size: 12px; white-space: pre-wrap; }
.event-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: 14px; }
.event-list li.susp { background: #fff6ed; border-radius: 8px; padding: 4px 8px; }

/* ---------- play ---------- */
.play-body { display: grid; grid-template-rows: auto 1fr; height: 100vh; background: #fff; }
.play-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.play-stage { min-height: 0; }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .sidebar nav { display: flex; }
  .sidebar-foot { margin: 0 0 0 auto; border: 0; padding: 0; }
  .main-panel { margin: 0; border-radius: 0; padding: 24px 18px; }
  .page-head h1 { font-size: 32px; }
  .editor-main { grid-template-columns: 1fr !important; grid-template-rows: 1fr 1fr; }
  .splitter { display: none; }
  .inline-form { grid-template-columns: 1fr; }
}
