/* ================= БАЗОВЫЕ ПЕРЕМЕННЫЕ ================= */
:root {
  --bg: #f5f5f7; --bg-gradient: none; --panel: rgba(255, 255, 255, 0.9);
  --text: #1d1d1f; --muted: #86868b; --accent: #0071e3; --accent-hover: #0077ed;
  --accent-shadow: rgba(0, 113, 227, 0.3); --border: rgba(0, 0, 0, 0.08);
  --highlight-bg: rgba(0, 0, 0, 0.03); --editor-bg: #1e1e1e;
  --editor-text: #d4d4d4; --editor-placeholder: #6e6e6e;
  --table-header: rgba(255, 255, 255, 0.95); --btn-text: #ffffff;
  --success: #34c759; --danger: #ff3b30; --warning: #ff9f0a; --site-bg: #ffffff;
  --hover-bg: rgba(0, 0, 0, 0.04); --sidebar-active: rgba(0, 113, 227, 0.1);
  --scrollbar-thumb: rgba(0, 0, 0, 0.2); --scrollbar-hover: rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] {
  --bg: #000000; --bg-gradient: radial-gradient(circle at top, #1a1a1a, #000);
  --panel: rgba(29, 29, 31, 0.7); --text: #f5f5f7; --muted: #a1a1a6;
  --accent: #2997ff; --accent-hover: #47a8ff; --accent-shadow: rgba(41, 151, 255, 0.3);
  --border: rgba(255, 255, 255, 0.1); --highlight-bg: rgba(255, 255, 255, 0.05);
  --editor-bg: #000000; --editor-text: #64d2ff; --editor-placeholder: #555555;
  --table-header: rgba(29, 29, 31, 0.9); --btn-text: #ffffff;
  --success: #30d158; --danger: #ff453a; --warning: #ffd60a; --site-bg: #f8fafc;
  --hover-bg: rgba(255, 255, 255, 0.05); --sidebar-active: rgba(41, 151, 255, 0.15);
  --scrollbar-thumb: rgba(255, 255, 255, 0.2); --scrollbar-hover: rgba(255, 255, 255, 0.4);
}

/* ================= ГЛОБАЛЬНЫЕ СТИЛИ ================= */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', sans-serif; }

body {
  background-color: var(--bg); background-image: var(--bg-gradient);
  color: var(--text); height: 100vh; display: flex; flex-direction: column;
  overflow: hidden; transition: background 0.3s, color 0.3s;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); }
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent; }

/* ================= ГЛОБАЛЬНАЯ ШАПКА ================= */
.global-header {
  background: var(--panel); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  padding: 16px 24px; display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border); z-index: 100; flex-shrink: 0; transition: background 0.3s;
}
.nav { display: flex; gap: 8px; }
.nav-btn {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 8px 16px; border-radius: 20px; cursor: pointer; font-weight: 600;
  font-size: 14px; transition: 0.2s; text-decoration: none;
}
.nav-btn:hover { background: var(--hover-bg); color: var(--text); }
.nav-btn.active { background: var(--sidebar-active); color: var(--accent); }
.theme-btn {
  background: var(--highlight-bg); border: 1px solid var(--border);
  color: var(--text); padding: 8px 16px; border-radius: 20px;
  cursor: pointer; font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px;
  transition: 0.2s;
}
.theme-btn:hover { background: var(--border); }

/* ================= СТРАНИЦЫ ================= */
main { flex: 1; display: flex; position: relative; overflow: hidden; }
.page { display: none; width: 100%; height: 100%; flex-direction: column; overflow-y: auto; }
.page.active { display: flex; }
.card {
  background: var(--panel); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-radius: 18px; border: 1px solid var(--border); padding: 24px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.04);
}

/* ================= SQL-ИГРА (глобальные заготовки) ================= */
.main-workspace { display: flex; flex: 1; padding: 24px; gap: 24px; overflow: hidden; height: 100%; }
.left-panel { width: 35%; display: flex; flex-direction: column; overflow-y: auto; }
.right-panel { width: 65%; display: flex; flex-direction: column; gap: 16px; min-height: 0; }

.story-title { font-size: 24px; font-weight: 700; margin-bottom: 16px; }
.story-text { font-size: 15px; line-height: 1.6; color: var(--muted); margin-bottom: 24px; }
.task-highlight {
  background: var(--highlight-bg); padding: 20px; border-radius: 12px;
  font-size: 15px; line-height: 1.6; margin-bottom: 24px;
  border-left: 4px solid var(--accent);
}

.btn-hint-toggle {
  background: var(--highlight-bg); border: 1px solid var(--border); color: var(--text);
  padding: 14px 20px; border-radius: 12px; cursor: pointer; font-weight: 600; font-size: 14px;
  width: 100%; text-align: left; display: flex; justify-content: space-between; align-items: center;
  transition: 0.2s; margin-top: auto;
}
.btn-hint-toggle:hover { background: var(--border); }

.hint-wrapper { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.3s ease-out; margin-top: 0; }
.hint-wrapper.expanded { grid-template-rows: 1fr; margin-top: 16px; }
.hint-inner { overflow: hidden; min-height: 0; border-radius: 12px; background: var(--highlight-bg); border: 1px solid transparent; padding: 0 20px; transition: padding 0.3s ease-out; }
.hint-wrapper.expanded .hint-inner { padding: 20px; border: 1px solid var(--border); }

/* Редактор (IDE Style) — терминал всегда тёмный */
.editor-section {
  background: var(--editor-bg); border-radius: 16px; border: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.editor-header { padding: 12px 20px; border-bottom: 1px solid rgba(255,255,255,0.1); display: flex; justify-content: space-between; align-items: center; }
.editor-header span { color: #888; font-size: 12px; font-family: 'JetBrains Mono', monospace; }

textarea {
  width: 100%; height: 140px; background: transparent; border: none;
  color: var(--editor-text); padding: 20px; font-family: 'JetBrains Mono', monospace;
  font-size: 16px; resize: none; outline: none; line-height: 1.5;
}
textarea::placeholder { color: var(--editor-placeholder); }

.editor-actions { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.1); display: flex; gap: 12px; align-items: center; }
.btn {
  padding: 10px 20px; border-radius: 8px; border: none;
  cursor: pointer; font-weight: 600; font-size: 14px; transition: 0.2s;
}
.btn-outline { background: transparent; border: 1px solid #555; color: #ccc; }
.btn-outline:hover { background: rgba(255,255,255,0.1); color: #fff; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-next { background: var(--success); color: #fff; display: none; }
.btn-next:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================
   СООБЩЕНИЯ В ТЕРМИНАЛЕ — ВСЕГДА ЧИТАЕМЫ НА ЧЁРНОМ ФОНЕ.
   ============================================================ */
.editor-section .message-box {
  margin-top: 16px;
  font-weight: 500;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 8px;
  color: #d4d4d4;
  background: transparent;
  border: 1px solid transparent;
  min-height: 20px;
  word-break: break-word;
}
.editor-section .message-box:empty { display: none; }
.editor-section .message-box.success {
  background: rgba(52, 199, 89, 0.15); color: #34c759;
  border: 1px solid rgba(52, 199, 89, 0.3);
}
.editor-section .message-box.error {
  background: rgba(255, 59, 48, 0.15); color: #ff3b30;
  border: 1px solid rgba(255, 59, 48, 0.3);
}

/* Таблица */
.table-section { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--panel); border-radius: 16px; border: 1px solid var(--border); }
.table-wrap { overflow: auto; flex: 1; }
table { width: 100%; border-collapse: collapse; font-size: 14px; text-align: left; }
th, td { padding: 12px 20px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: var(--table-header); color: var(--muted); font-weight: 600; position: sticky; top: 0; backdrop-filter: blur(10px); z-index: 2; }
td { color: var(--text); }
tr:hover td { background: var(--highlight-bg); }

/* ================= CMS-ИГРА ================= */
.app-container { display: flex; flex: 1; overflow: hidden; width: 100%; height: 100%; }
.sidebar { width: 260px; background: var(--panel); backdrop-filter: blur(20px); border-right: 1px solid var(--border); padding: 20px 12px; display: flex; flex-direction: column; }
.menu-item { padding: 10px 12px; border-radius: 8px; cursor: pointer; color: var(--text); font-size: 14px; margin-bottom: 4px; transition: 0.2s; }
.menu-item:hover { background: var(--hover-bg); }
.menu-item.active { background: var(--sidebar-active); color: var(--accent); font-weight: 600; }

.main-content { flex: 1; display: flex; flex-direction: column; overflow-y: auto; padding: 32px; min-width: 0; }
.page-header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 24px; }
.page-title { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.page-subtitle { font-size: 15px; color: var(--muted); margin-top: 4px; }
.table-card { background: var(--panel); backdrop-filter: blur(20px); border-radius: 18px; border: 1px solid var(--border); overflow: hidden; }

.editor-view { display: none; flex-direction: column; min-width: 0; }
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; min-width: 0; }
.editor-main, .editor-side { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.form-group { display: flex; flex-direction: column; gap: 8px; min-width: 0; margin-bottom: 12px; }
.form-group label { font-weight: 600; font-size: 14px; color: var(--muted); }
.form-group input, .form-group select {
  width: 100%; padding: 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); font-size: 15px; outline: none; transition: 0.2s;
}
.form-group input:focus, .form-group select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--sidebar-active); }
.form-group textarea { min-height: 80px; resize: vertical; padding: 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font-family: inherit; outline: none; }
.form-group textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--sidebar-active); }

.rich-editor-wrapper { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--panel); display: flex; flex-direction: column; }
.rich-editor-wrapper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--sidebar-active); }
.toolbar { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--border); background: var(--hover-bg); flex-wrap: wrap; align-items: center; }
.toolbar-btn { background: transparent; border: none; color: var(--text); padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 15px; font-weight: 500; transition: 0.2s; }
.toolbar-btn:hover { background: var(--border); }
.rich-editor { min-height: 350px; padding: 20px; outline: none; color: var(--text); font-size: 16px; line-height: 1.7; overflow-y: auto; word-wrap: break-word; }
.rich-editor:empty:before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }

.publish-box { background: var(--panel); backdrop-filter: blur(20px); border-radius: 16px; border: 1px solid var(--border); padding: 20px; }
.publish-box h3 { font-size: 16px; margin-bottom: 12px; }
.btn-cancel { background: var(--hover-bg); color: var(--text); border: 1px solid var(--border); padding: 12px 24px; border-radius: 12px; cursor: pointer; font-weight: 600; transition: 0.2s; }

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 20px; text-align: center; color: var(--muted); background: var(--panel); border-radius: 18px; border: 1px solid var(--border); }
.empty-state h3 { font-size: 20px; color: var(--text); margin-bottom: 8px; }

/* Просмотр сайта в CMS */
.site-view { display: none; width: 100%; height: 100%; background: var(--site-bg); color: #1e293b; overflow-y: auto; flex-direction: column; position: absolute; top: 0; left: 0; z-index: 100; }
.site-header { background: #1e293b; color: white; padding: 16px 40px; display: flex; justify-content: space-between; align-items: center; }
.article-container { max-width: 1200px; width: 100%; margin: 0 auto; padding: 40px 20px 80px; display: flex; flex-direction: column; }

.article-cover-wrapper { width: 100%; border-radius: 16px; overflow: hidden; margin-bottom: 32px; display: none; }
.article-cover-wrapper.active { display: block; }
.article-cover-wrapper img { width: 100%; height: auto; display: block; }

.article-category { display: inline-block; color: #3b82f6; font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 16px; }
.article-title { font-size: 42px; font-weight: 800; line-height: 1.2; margin-bottom: 20px; color: #0f172a; }
.article-subtitle { font-size: 20px; color: #475569; line-height: 1.5; margin-bottom: 32px; }
.article-meta { display: flex; align-items: center; gap: 16px; font-size: 15px; color: #64748b; padding-bottom: 32px; border-bottom: 1px solid #e2e8f0; margin-bottom: 32px; }
.article-body { font-size: 19px; line-height: 1.8; color: #334155; margin-bottom: 40px; word-wrap: break-word; }
.article-body h2 { font-size: 28px; margin: 32px 0 16px; font-weight: 700; color: #0f172a; }
.article-body blockquote { border-left: 4px solid #3b82f6; padding: 16px 20px; margin: 24px 0; font-style: italic; color: #64748b; background: #f8fafc; border-radius: 0 8px 8px 0; }
.btn-back-float { position: fixed; bottom: 30px; left: 30px; background: #1d2327; color: white; border: none; padding: 14px 28px; border-radius: 30px; cursor: pointer; font-weight: 600; box-shadow: 0 4px 20px rgba(0,0,0,0.3); z-index: 1000; transition: 0.2s; }
.btn-back-float:hover { background: #000; transform: scale(1.02); }

/* ================= МОДАЛЬНОЕ ОКНО ВХОДА ================= */
.auth-overlay {
  position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(11, 16, 32, 0.6); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center; z-index: 9999;
}
.auth-box {
  background: var(--panel); backdrop-filter: blur(30px); -webkit-backdrop-filter: blur(30px);
  border: 1px solid var(--border); padding: 40px; border-radius: 24px;
  width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}
.auth-box h2 { margin-top: 0; text-align: center; color: var(--text); font-size: 24px; margin-bottom: 24px; }
.auth-box label { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.auth-box input { width: 100%; padding: 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--hover-bg); color: var(--text); font-size: 15px; margin-bottom: 16px; outline: none; }
.auth-box input:focus { border-color: var(--accent); }
.auth-box .btn { width: 100%; margin-top: 10px; }

/* ============================================================
   SQL-СТРАНИЦА: переопределения, чтобы кнопки и терминал
   выглядели как в sqlgame.html. Работают только внутри
   #page-sql — CMS, админку и презентацию не трогают.
   ============================================================ */
#page-sql .btn {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.1);
}
#page-sql .btn:hover { background: rgba(255, 255, 255, 0.2); }
#page-sql .btn-submit {
  background: var(--accent); color: #fff; border: none;
  box-shadow: 0 4px 12px var(--accent-shadow);
}
#page-sql .btn-submit:hover { background: var(--accent-hover); transform: translateY(-1px); }
#page-sql .btn-next {
  background: var(--success); color: #fff; border: none;
}
#page-sql .btn-next:hover { opacity: 0.9; }
#page-sql .btn:disabled {
  opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none;
}
#page-sql textarea { color: #d4d4d4; }
