@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;600;800&display=swap');

:root {
  --bg: #f0f2f5; --bg-card: #ffffff; --text: #1a1a2e; --text-secondary: #4a4a6a; --text-light: #8888aa;
  --border: #e4e6ed; --shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  --blue: #4a6cf7; --blue-light: #e8eeff; --green: #22c55e; --green-light: #dcfce7;
  --red: #ef4444; --purple: #8b5cf6; --purple-light: #ede9fe; --orange: #f59e0b;
  --radius: 16px; --radius-sm: 10px; --btn-text: #fff;
  --transition: 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  --canvas-bg: #1e293b;
}
[data-theme="dark"] {
  --bg: #0f0f1a; --bg-card: #1a1a2e; --text: #e8e8f0; --text-secondary: #8b8baa; --text-light: #5a5a7a;
  --border: #2a2a44; --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --blue: #5d7cff; --blue-light: #232a4d; --green: #22c55e; --green-light: #12351f;
  --red: #ef4444; --purple: #a78bfa; --purple-light: #2a2150; --canvas-bg: #0c0f1d;
}
[data-theme="cyber"] {
  --bg: #02040a; --bg-card: rgba(10, 14, 23, 0.92); --text: #cff9ff; --text-secondary: #7aa7b0; --text-light: #3f6069;
  --border: rgba(0, 255, 255, 0.55); --shadow: 0 0 32px rgba(0, 255, 255, 0.12);
  --blue: #0ff; --blue-light: rgba(0, 255, 255, 0.12); --green: #39ff14; --red: #ff003c; --btn-text: #02040a; --canvas-bg: #050510;
}
[data-theme="space"] {
  --bg: #0b1026; --bg-card: #151b3a; --text: #e6e9ff; --border: #28305e; --blue: #8b7bff; --green: #4ade80; --red: #f87171; --canvas-bg: #0d1330;
}
[data-theme="sunset"] {
  --bg: #fff4ec; --bg-card: #fffdfa; --text: #43242f; --border: #f5dcc9; --blue: #ff6a3d; --green: #0ea574; --red: #e11d48; --canvas-bg: #2b1a20;
}
[data-theme="ocean"] {
  --bg: #eaf6fb; --bg-card: #ffffff; --text: #0e2a3a; --border: #d2e7f2; --blue: #0891b2; --green: #059669; --red: #e11d48; --canvas-bg: #12283a;
}
[data-theme="forest"] {
  --bg: #0a1410; --bg-card: #12211a; --text: #e5f6ec; --border: #22402f; --blue: #34d399; --green: #a3e635; --red: #fb7185; --btn-text: #04150d; --canvas-bg: #0a1a12;
}
[data-theme="sakura"] {
  --bg: #fdf1f6; --bg-card: #fffafd; --text: #3c1f2f; --border: #f6dce8; --blue: #ec4899; --green: #0ea574; --red: #e11d48; --canvas-bg: #2a1622;
}
[data-theme="gold"] {
  --bg: #0d0a05; --bg-card: #181207; --text: #f6ead0; --border: #3b2f16; --blue: #f2c14e; --green: #9fbe3a; --red: #f87171; --btn-text: #231a05; --canvas-bg: #120e05;
}
[data-theme="retro"] {
  --bg: #f2e9d8; --bg-card: #fbf5e7; --text: #3f3222; --border: #e0d2b4; --blue: #b45309; --green: #4d7c0f; --red: #b91c1c; --btn-text: #fff8ec; --canvas-bg: #1f1a10;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
::selection { background: var(--blue); color: var(--btn-text); }
body { background: var(--bg); color: var(--text); font-family: 'Inter', sans-serif; min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; transition: 0.6s ease; }

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

#bg, #math-bg { position: fixed; inset: 0; pointer-events: none; }
#bg { z-index: -2; } #math-bg { z-index: -1; opacity: 0.85; }

.card, .profile-card, .lang-panel, .theme-panel, .game-wrapper { position: relative; z-index: 1; }
.card { display: none; flex-direction: column; align-items: center; background: var(--bg-card); padding: 32px 36px; border-radius: var(--radius); box-shadow: var(--shadow); width: 520px; max-width: 100%; border: 1px solid var(--border); }
.card.active { display: flex; animation: fadeUp 0.35s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }
.card-wide { width: 620px; }

.logo { font-family: 'JetBrains Mono', monospace; font-weight: 800; font-size: 34px; margin-bottom: 4px; }
.logo span { color: var(--blue); }
.subtitle { color: var(--text-secondary); font-size: 15px; margin-bottom: 26px; }
.section-title { font-weight: 700; color: var(--text-light); align-self: flex-start; margin: 0 0 14px 0; text-transform: uppercase; font-size: 11px; letter-spacing: 2px; }

input { width: 100%; padding: 14px 18px; font-size: 15px; font-family: inherit; background: var(--bg); color: var(--text); border: 2px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 14px; outline: none; transition: 0.2s; }
input:focus { border-color: var(--blue); box-shadow: 0 0 0 4px color-mix(in srgb, var(--blue) 15%, transparent); }

.btn { padding: 14px 28px; font-size: 15px; font-weight: 600; font-family: inherit; border: none; border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition); display: inline-flex; align-items: center; justify-content: center; width: 100%; }
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(0.97); }
.btn-primary { background: var(--blue); color: var(--btn-text); }
.btn-success { background: var(--green); color: var(--btn-text); }
.btn-warning { background: var(--orange); color: var(--btn-text); }
.btn-danger { background: var(--red); color: var(--btn-text); }
.btn-purple { background: var(--purple); color: var(--btn-text); }
.btn-secondary { background: var(--bg); color: var(--text); border: 2px solid var(--border); }
.btn-outline { background: transparent; color: var(--text-secondary); border: 2px solid var(--border); }
.btn-group { display: flex; gap: 10px; width: 100%; flex-wrap: wrap; }
.btn-group .btn { flex: 1; min-width: 80px; }

.profile-card { position: fixed; top: 20px; right: 20px; background: var(--bg-card); padding: 12px 18px; border-radius: var(--radius-sm); border: 1px solid var(--border); box-shadow: var(--shadow); z-index: 100; display: none; text-align: right; }
.profile-card .name { font-weight: 800; color: var(--blue); font-size: 15px; font-family: 'JetBrains Mono', monospace; }
.profile-card .elo { color: var(--text-secondary); font-size: 13px; font-weight: 600; margin-top: 2px; }

.room-list { width: 100%; background: var(--bg); border-radius: var(--radius-sm); padding: 6px; max-height: 160px; overflow-y: auto; margin-bottom: 16px; border: 1px solid var(--border); }
.room-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); border-radius: 8px; transition: background 0.2s; }
.room-item:hover { background: var(--blue-light); }

.game-wrapper { width: 100%; padding: 16px; border-radius: var(--radius); }
.game-header { width: 100%; display: flex; justify-content: space-between; align-items: center; background: var(--bg); padding: 10px 18px; border-radius: var(--radius-sm); margin-bottom: 14px; border: 1px solid var(--border); }

/* --- Таймеры --- */
.time-controls { display: flex; gap: 8px; margin-bottom: 16px; overflow-x: auto; padding-bottom: 5px; width: 100%; }
.time-btn { padding: 8px 14px; background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: var(--radius-sm); font-weight: 600; cursor: pointer; transition: var(--transition); white-space: nowrap; }
.time-btn:hover { border-color: var(--blue); }
.time-btn.active { background: var(--blue); color: var(--btn-text); border-color: var(--blue); }
.player-info { display: flex; align-items: center; gap: 12px; font-weight: bold; color: var(--text); }
.timer { background: var(--bg); padding: 6px 12px; border-radius: 6px; font-family: 'JetBrains Mono', monospace; font-size: 16px; border: 2px solid var(--border); transition: 0.3s; }
.timer.active { background: var(--green-light); border-color: var(--green); color: var(--green); }
.timer.danger { background: var(--red); color: white; border-color: var(--red); animation: pulse 1s infinite; }
.timer.hidden { display: none; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.7; } 100% { opacity: 1; } }

/* --- Lichess Layout --- */
.game-layout { display: flex; gap: 20px; align-items: stretch; width: 100%; }
.main-column { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-column { width: 320px; display: flex; flex-direction: column; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }

canvas#gameCanvas { background: var(--canvas-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: inset 0 0 30px rgba(0,0,0,0.5); object-fit: contain; width: 100%; height: auto; aspect-ratio: 8/5; margin-bottom: 15px;}
.controls { background: var(--bg-card); padding: 16px; border-radius: var(--radius-sm); border: 1px solid var(--border); }

/* --- 2 Базы --- */
.bases-container { display: flex; gap: 15px; margin-bottom: 12px; }
.base-group { flex: 1; display: flex; flex-direction: column; gap: 5px; }
.base-group label { font-size: 12px; font-weight: 700; color: var(--text-light); text-transform: uppercase; }
.base-group .btn { padding: 10px; font-size: 14px; margin-top: 0; }
.base-group input { margin-bottom: 0; padding: 10px 14px; font-family: 'JetBrains Mono', monospace; font-size: 14px; }

/* --- Калькулятор --- */
.calc-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; margin-top: 4px; }
.calc-btn { padding: 10px 2px; cursor: pointer; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; font-weight: 600; font-family: 'JetBrains Mono', monospace; font-size: 13px; transition: 0.15s; color: var(--text); }
.calc-btn:hover { border-color: var(--blue); background: var(--blue-light); color: var(--blue); }
.calc-btn:active { transform: scale(0.9); }
.calc-btn.var-btn { color: var(--blue); font-weight: 800; font-size: 15px; }
.calc-btn.func-btn { color: var(--purple); }
.calc-btn.op-btn { color: var(--orange); font-size: 15px; }
.calc-btn.del-btn { color: var(--red); font-size: 13px; }

/* --- Чат --- */
.chat-header { background: var(--bg); padding: 12px; font-weight: bold; font-size: 13px; text-transform: uppercase; border-bottom: 1px solid var(--border); color: var(--text-secondary); }
.chat-messages { flex: 1; padding: 12px; overflow-y: auto; max-height: 400px; display: flex; flex-direction: column; gap: 10px; font-size: 14px; }
.chat-msg { display: flex; flex-direction: column; }
.chat-msg .meta { font-size: 11px; color: var(--text-light); margin-bottom: 2px; }
.chat-msg .text { background: var(--bg); padding: 8px 12px; border-radius: 8px; display: inline-block; word-break: break-word; border: 1px solid var(--border); }
.chat-msg.me { align-items: flex-end; }
.chat-msg.me .text { background: var(--blue-light); color: var(--blue); border-color: var(--blue); }
.chat-input-area { display: flex; border-top: 1px solid var(--border); background: var(--bg); }
.chat-input-area input { border: none; border-radius: 0; margin: 0; background: transparent; }
.chat-input-area input:focus { box-shadow: none; border: none; }
.chat-input-area .btn { border-radius: 0; width: 60px; }
.game-actions { padding: 12px; border-top: 1px solid var(--border); background: var(--bg-card); display: flex; flex-direction: column; gap: 10px; }
.game-actions .btn { margin: 0; }

.turn { font-weight: bold; background: var(--blue-light); color: var(--blue); padding: 6px 16px; border-radius: 20px; font-size: 12px; letter-spacing: 0.5px; }
.lang-panel, .theme-panel { position: fixed; display: flex; gap: 5px; z-index: 100; background: var(--bg-card); padding: 8px; border-radius: 30px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.lang-panel { top: 20px; left: 20px; } .theme-panel { bottom: 20px; right: 20px; flex-wrap: wrap; justify-content: flex-end; max-width: 220px; }
.lang-btn { background: none; border: none; font-size: 20px; cursor: pointer; transition: 0.2s; filter: grayscale(50%); opacity: 0.8; }
.lang-btn:hover { transform: scale(1.2); } .lang-btn.active { filter: grayscale(0%); opacity: 1; transform: scale(1.1); }
.theme-btn { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--border); cursor: pointer; transition: 0.2s; }
.theme-btn:hover { transform: scale(1.15); } .theme-btn.active { border-color: var(--blue); box-shadow: 0 0 12px color-mix(in srgb, var(--blue) 50%, transparent); }
.theme-btn[data-theme="light"] { background: #f0f2f5; } .theme-btn[data-theme="dark"] { background: #0f0f1a; } .theme-btn[data-theme="cyber"] { background: #0ff; } .theme-btn[data-theme="space"] { background: #6a5ae0; } .theme-btn[data-theme="sunset"] { background: #ff6a3d; } .theme-btn[data-theme="ocean"] { background: #0891b2; } .theme-btn[data-theme="forest"] { background: #34d399; } .theme-btn[data-theme="sakura"] { background: #ec4899; } .theme-btn[data-theme="gold"] { background: #f2c14e; } .theme-btn[data-theme="retro"] { background: #b45309; }

.manual-content { width: 100%; text-align: left; background: var(--bg); padding: 18px; border-radius: var(--radius-sm); font-size: 14px; line-height: 1.7; max-height: 400px; overflow-y: auto; border: 1px solid var(--border); margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }
.error-msg { color: var(--red); font-weight: 600; min-height: 22px; margin-bottom: 12px; text-align: center; }
.error-msg-small { color: var(--red); font-size: 13px; text-align: center; min-height: 15px; margin-bottom: 5px; }

/* --- Mobile First Media Queries --- */
@media (min-width: 1200px) {
  .game-wrapper { max-width: 1260px; }
}
@media (max-width: 1199px) {
  .game-wrapper { max-width: 100%; }
}
@media (max-width: 900px) {
  .game-layout { flex-direction: column; }
  .chat-column { width: 100%; max-height: 350px; }
  .chat-messages { max-height: 150px; }
}
@media (max-width: 640px) {
  .card { padding: 24px 18px; }
  .logo { font-size: 28px; }
  .theme-panel { max-width: 170px; }
  .calc-btn { min-height: 44px; font-size: 14px; } /* Для пальцев */
  .bases-container { flex-direction: column; gap: 10px; }
  .game-header { flex-direction: column; gap: 10px; text-align: center; }
}
