
:root {
  --bg: #0f0f1a;
  --bg2: #1a1a2e;
  --bg3: #252540;
  --panel: #16213e;
  --border: #2a2a4a;
  --text: #c8c8d4;
  --text2: #8888a0;
  --accent: #e94560;
  --accent2: #0f3460;
  --green: #4ecca3;
  --blue: #4d9de0;
  --red: #e94560;
  --yellow: #f0c040;
  --radius: 8px;
  --font: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Courier New', 'Fira Code', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

#app { height: 100vh; display: flex; flex-direction: column; }

/* ── login ── */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh;
}
.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 3rem 2.5rem;
  text-align: center;
  min-width: 340px;
}
.login-card h1 { font-size: 1.8rem; color: var(--accent); margin-bottom: 0.5rem; }
.login-sub { color: var(--text2); font-size: 0.9rem; margin-bottom: 1.5rem; }
.login-card input {
  width: 100%; padding: 0.7rem 1rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-size: 1rem; margin-bottom: 1rem; outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  width: 100%; padding: 0.7rem;
  background: var(--accent); color: white; border: none;
  border-radius: var(--radius); font-size: 1rem;
  cursor: pointer; font-weight: 600;
}
.login-card button:hover { opacity: 0.9; }
.login-error { color: var(--red); font-size: 0.85rem; margin-top: 0.75rem; min-height: 1.2rem; }

/* ── main ── */
#main-screen { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ── top bar ── */
#top-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.5rem 1rem;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  gap: 1rem; flex-shrink: 0;
}
.tabs { display: flex; gap: 0.25rem; }
.tab {
  padding: 0.5rem 1.2rem; background: transparent;
  border: none; color: var(--text2); font-size: 0.9rem;
  cursor: pointer; border-radius: var(--radius); font-weight: 500;
}
.tab:hover { background: var(--bg3); color: var(--text); }
.tab.active { background: var(--accent); color: white; }
.top-right { display: flex; align-items: center; gap: 0.75rem; }
#chapter-select {
  padding: 0.4rem 0.7rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 0.85rem; outline: none;
}
#chapter-select:focus { border-color: var(--accent); }
.user-badge {
  font-size: 0.8rem; color: var(--accent); font-weight: 600;
  background: var(--bg3); padding: 0.3rem 0.7rem; border-radius: 20px;
}
.btn-icon {
  background: none; border: 1px solid var(--border);
  color: var(--text2); cursor: pointer; border-radius: 50%;
  width: 26px; height: 26px; font-size: 0.75rem;
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }

/* ── tab content ── */
#tab-content { flex: 1; overflow: hidden; }

/* ── 3-panel layout ── */
.panels {
  display: flex; height: 100%; gap: 0; overflow: hidden;
}
.panel-left {
  width: 22%; min-width: 240px; background: var(--panel);
  border-right: 1px solid var(--border); display: flex;
  flex-direction: column; overflow: hidden;
}
.panel-center {
  flex: 1; display: flex; flex-direction: column; overflow-y: auto;
  padding: 1rem;
}
.panel-right {
  width: 26%; min-width: 260px; background: var(--panel);
  border-left: 1px solid var(--border); display: flex;
  flex-direction: column; overflow: hidden;
}

.panel-header {
  padding: 0.6rem 0.8rem; font-size: 0.8rem; font-weight: 600;
  color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.panel-scroll {
  flex: 1; overflow-y: auto; padding: 0.3rem 0;
}
.panel-bottom {
  padding: 0.6rem 0.8rem; border-top: 1px solid var(--border); flex-shrink: 0;
}

/* ── list items ── */
.list-item {
  padding: 0.4rem 0.8rem; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  font-size: 0.82rem; transition: background 0.1s;
  display: flex; align-items: center; gap: 0.4rem;
}
.list-item:hover { background: rgba(255,255,255,0.04); }
.list-item.active { background: rgba(233,69,96,0.12); border-left: 3px solid var(--accent); }
.list-item .key { font-family: var(--mono); font-size: 0.7rem; color: var(--text2); }
.list-item .val { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.dot.green { background: var(--green); }
.dot.blue { background: var(--blue); }
.dot.white { background: #ffffff; }

/* ── tags ── */
.tags-row { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; }
.tag-badge {
  display: inline-flex; align-items: center; gap: 3px;
  background: var(--bg3); color: var(--text);
  border-radius: 4px; padding: 2px 6px; font-size: 0.72rem;
}
.tag-badge .tag-remove {
  background: none; border: none; color: var(--text2); cursor: pointer;
  font-size: 0.8rem; padding: 0; line-height: 1;
}
.tag-badge .tag-remove:hover { color: var(--accent); }
.tag-add-btn {
  background: var(--bg3); color: var(--text2); border: 1px dashed var(--border);
  border-radius: 4px; width: 22px; height: 22px; cursor: pointer;
  font-size: 1rem; line-height: 1; padding: 0; display: inline-flex; align-items: center; justify-content: center;
}
.tag-add-btn:hover { border-color: var(--accent); color: var(--accent); }
.tag-input {
  width: 100px; padding: 2px 5px; font-size: 0.72rem; border: 1px solid var(--accent);
  border-radius: 4px; background: var(--bg); color: var(--text); outline: none;
}
.tag-add-wrap { display: inline-flex; align-items: center; gap: 3px; position: relative; }
.tag-confirm-btn {
  background: var(--green); color: var(--bg); border: none;
  border-radius: 4px; width: 20px; height: 20px; cursor: pointer;
  font-size: 0.7rem; line-height: 1; padding: 0; font-weight: bold;
}
.tag-confirm-btn:hover { filter: brightness(1.2); }

.tag-dropdown {
  position: absolute; top: 100%; left: 0; z-index: 100;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 4px; max-height: 140px; overflow-y: auto;
  min-width: 120px; box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.tag-drop-item {
  padding: 2px 8px; cursor: pointer; font-size: 0.72rem; white-space: nowrap;
}
.tag-drop-item:hover { background: var(--accent); color: white; }

.comment-input {
  width: 100%; padding: 0.4rem 0.6rem; font-size: 0.8rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); outline: none;
}
.comment-input:focus { border-color: var(--accent); }

/* ── forms ── */
textarea, input[type="text"], input[type="number"], input[type="password"] {
  width: 100%; padding: 0.5rem 0.7rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-family: var(--font); font-size: 0.85rem; outline: none; resize: vertical;
}
textarea:focus, input:focus { border-color: var(--accent); }
textarea.readonly { background: var(--bg2); color: var(--text2); cursor: default; }
textarea.en-editor { font-size: 0.85rem; min-height: 60px; }
textarea.ru-editor { font-size: 0.9rem; min-height: 80px; }
textarea.adapt-editor { border-left: 3px solid var(--green); }
textarea.trans-editor { border-left: 3px solid var(--blue); }

label { display: block; font-size: 0.75rem; color: var(--text2); margin-bottom: 0.2rem; font-weight: 600; }

.editor-block { margin-bottom: 1rem; }
.editor-block .info { font-size: 0.72rem; color: var(--text2); margin-top: 0.2rem; }

.btn {
  padding: 0.5rem 1.2rem; border: none; border-radius: var(--radius);
  font-size: 0.85rem; font-weight: 600; cursor: pointer;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--accent); color: white; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--red); color: white; }
.btn-success { background: var(--green); color: var(--bg); }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.75rem; }

.btn-row { display: flex; gap: 0.5rem; margin-top: 0.75rem; }

input.search {
  width: 100%; padding: 0.5rem 0.7rem;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-size: 0.82rem; outline: none; margin: 0.5rem;
  width: calc(100% - 1rem);
}
input.search:focus { border-color: var(--accent); }

.search-row { display: flex; gap: 0; align-items: center; margin: 0.5rem 0.5rem 0 0.5rem; }
.search-row input.search { margin: 0; flex: 1; }
.filter-toggle {
  background: var(--bg); border: 1px solid var(--border); color: var(--text2);
  border-radius: var(--radius); cursor: pointer; padding: 0.35rem 0.5rem;
  font-size: 0.8rem; margin-left: 0.3rem;
}
.filter-toggle:hover { border-color: var(--accent); color: var(--accent); }

.filter-panel {
  background: var(--bg); border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.7rem; font-size: 0.72rem;
}
.filter-section { margin-bottom: 0.4rem; }
.filter-section b { display: block; margin-bottom: 0.15rem; color: var(--text2); }
.filter-tags { display: flex; flex-wrap: wrap; gap: 0.2rem 0.5rem; }
.filter-tag { display: inline-flex; align-items: center; gap: 2px; cursor: pointer; white-space: nowrap; }
.filter-tag:hover { color: var(--accent); }
.filter-statuses { display: flex; flex-wrap: wrap; gap: 0.2rem 0.6rem; }
.filter-status { display: inline-flex; align-items: center; gap: 3px; cursor: pointer; white-space: nowrap; }
.filter-status:hover { color: var(--accent); }
.filter-cross { cursor: pointer; display: block; }
.filter-cross:hover { color: var(--accent); }
.filter-cb { margin: 0; accent-color: var(--accent); }

/* ── mode-select ── */
.mode-select {
  padding: 0.3rem 0.5rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-size: 0.82rem; outline: none;
}

/* ── commit form ── */
.commit-form { margin-top: 0.5rem; }
.commit-form input, .commit-form textarea {
  margin-bottom: 0.4rem; font-size: 0.8rem; min-height: auto;
}
.commit-form textarea { min-height: 50px; resize: vertical; }

/* ── toasts ── */
#toast-container {
  position: fixed; bottom: 1rem; right: 1rem;
  display: flex; flex-direction: column; gap: 0.5rem; z-index: 9999;
}
.toast {
  padding: 0.6rem 1rem; border-radius: var(--radius);
  font-size: 0.82rem; color: white; max-width: 360px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  animation: toastIn 0.3s ease;
}
.toast.success { background: var(--green); color: var(--bg); }
.toast.error { background: var(--red); }
.toast.info { background: var(--accent2); }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

/* ── status bar ── */
#status-bar {
  padding: 0.25rem 1rem; font-size: 0.72rem;
  color: var(--text2); background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-between;
  flex-shrink: 0;
}

/* ── history modal ── */
.history-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.history-card {
  background: var(--panel); border-radius: 8px; width: 90%; max-width: 640px;
  max-height: 80vh; display: flex; flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.history-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.history-close {
  background: none; border: none; color: var(--text2); cursor: pointer;
  font-size: 1.2rem; padding: 0 0.3rem;
}
.history-close:hover { color: var(--accent); }
.history-list {
  overflow-y: auto; flex: 1; padding: 0.5rem 0;
}
.history-item {
  padding: 0.5rem 1rem; border-bottom: 1px solid var(--border);
}
.history-meta {
  display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center;
  font-size: 0.72rem; margin-bottom: 0.3rem;
}
.history-meta .hash { font-family: var(--mono); color: var(--accent); }
.history-val {
  font-family: var(--mono); font-size: 0.78rem; color: var(--text);
  background: var(--bg); padding: 0.35rem 0.5rem; border-radius: 4px;
  margin-bottom: 0.35rem; word-break: break-all;
}
.history-apply {
  font-size: 0.72rem; padding: 0.2rem 0.6rem; cursor: pointer;
}
.btn-sm { font-size: 0.75rem; padding: 0.25rem 0.6rem; }
.btn-secondary { background: var(--bg2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: white; border: none; }
.btn-primary:hover { filter: brightness(1.15); }

/* ── history (commit list) ── */
.commit-item {
  padding: 0.5rem 0.8rem; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  font-size: 0.8rem;
}
.commit-item:hover { background: rgba(255,255,255,0.04); }
.commit-item.active { background: rgba(233,69,96,0.12); border-left: 3px solid var(--accent); }
.commit-item .hash { font-family: var(--mono); color: var(--accent); font-size: 0.75rem; }
.commit-item .msg { font-weight: 600; margin: 0.15rem 0; }
.commit-item .meta { color: var(--text2); font-size: 0.7rem; }
.commit-item .files { color: var(--text2); font-size: 0.68rem; margin-top: 0.15rem; }

.diff-view {
  font-family: var(--mono); font-size: 0.78rem;
  white-space: pre-wrap; overflow: auto;
  background: var(--bg); padding: 1rem;
  border-radius: var(--radius); line-height: 1.4;
  height: 100%;
}
.diff-add { color: var(--green); }
.diff-del { color: var(--red); }
.diff-hdr { color: var(--yellow); }

/* ── sprite preview ── */
.sprite-preview-box {
  background: var(--bg); border-radius: var(--radius);
  padding: 0.5rem; margin-bottom: 1rem;
  text-align: center; min-height: 80px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); overflow-x: auto;
}
.sprite-preview-box img { image-rendering: pixelated; max-height: 200px; }
.sprite-preview-box canvas { image-rendering: pixelated; }

.upload-section {
  margin-bottom: 0.8rem; padding: 0.8rem;
  background: var(--panel); border-radius: var(--radius);
  border: 1px dashed var(--border);
}
.upload-section h4 { font-size: 0.8rem; color: var(--text2); margin-bottom: 0.5rem; }

.meta-row { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.meta-row label { flex: 1; font-size: 0.72rem; }
.meta-row input { font-size: 0.82rem; padding: 0.3rem 0.5rem; }

.radio-group { display: flex; gap: 1rem; margin-bottom: 0.5rem; }
.radio-group label { font-size: 0.78rem; color: var(--text); font-weight: 400; cursor: pointer; display: inline-flex; align-items: center; gap: 0.3rem; }

.collapse-header {
  cursor: pointer; padding: 0.5rem 0;
  font-size: 0.8rem; color: var(--text2); font-weight: 600;
  border-top: 1px solid var(--border); margin-top: 0.5rem;
}
.collapse-header:hover { color: var(--accent); }
.collapse-body { display: none; }
.collapse-body.open { display: block; }

/* ── file browser ── */
.file-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 0.8rem; font-size: 0.8rem;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.file-item:hover { background: rgba(255,255,255,0.04); }
.file-item .fname { flex: 1; font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item .fsize { color: var(--text2); font-size: 0.7rem; }
.file-item .factions { display: flex; gap: 0.3rem; }

.asset-upload { margin-bottom: 0.5rem; }

/* ── audio player ── */
audio { width: 100%; height: 30px; margin-top: 0.5rem; }

/* scrollbars */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }

/* ── raw actions / modal ── */
.raw-actions { margin-top: 0.5rem; }
.raw-warn {
  padding: 0.6rem 1rem; font-size: 0.72rem; color: var(--red);
  background: rgba(233,69,96,0.08); border-bottom: 1px solid rgba(233,69,96,0.2);
  line-height: 1.5;
}
.raw-toolbar {
  display: flex; gap: 0.4rem; align-items: center; padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.raw-toolbar select {
  padding: 0.3rem 0.4rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 0.78rem; outline: none;
}
.raw-toolbar select:focus { border-color: var(--accent); }
.raw-textarea {
  font-family: var(--mono); font-size: 0.76rem; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 0; padding: 0.75rem;
  resize: vertical; outline: none; min-height: 300px; flex: 1; width: 100%; box-sizing: border-box;
  tab-size: 2; margin: 0;
}
.raw-textarea:focus { border-color: var(--accent); }
.raw-status {
  padding: 0.3rem 1rem; font-size: 0.72rem; flex-shrink: 0; min-height: 1.2rem;
}

.drop-zone {
  border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 0.5rem; text-align: center; color: var(--text2);
  font-size: 0.68rem; cursor: pointer; transition: border-color 0.2s;
}
.drop-zone.dragover { border-color: var(--accent); color: var(--accent); }

.raw-buttons { display: flex; gap: 0.3rem; margin-bottom: 0.35rem; }
.raw-buttons .btn { flex: 1; font-size: 0.7rem; }
.drop-zone {
  border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 0.5rem; text-align: center; color: var(--text2);
  font-size: 0.68rem; cursor: pointer; transition: border-color 0.2s;
}
.drop-zone.dragover { border-color: var(--accent); color: var(--accent); }

/* ── admin panel ── */
.admin-wrap { padding: 1.5rem 2rem; max-width: 600px; }
.admin-wrap h2 { margin: 0 0 0.3rem; font-size: 1.1rem; }
.admin-add { display: flex; gap: 0.5rem; margin: 1rem 0 0.5rem; }
.admin-add input { flex: 1; }
.admin-list { margin-top: 1rem; }
.admin-list-header { padding: 0.4rem 0; border-bottom: 1px solid var(--border); margin-bottom: 0.3rem; }
.admin-user-row {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 0; border-bottom: 1px solid rgba(255,255,255,0.03);
}
.admin-user-name { flex: 1; font-weight: 600; }
.admin-user-token { font-size: 0.72rem; color: var(--text2); background: var(--bg); padding: 1px 5px; border-radius: 3px; }
