/* === Variables === */
:root {
  --bg: #111;
  --panel: #181818;
  --panel-alt: #1f1f1f;
  --border: #2a2a2a;
  --accent: #FDE404;
  --accent-muted: #d8c35a;
  --text: #dcdcdc;
  --muted: #9a9a9a;
  --sidebar-w: 260px;
  --banner-color: #1e1e1e;
  font-size: 16px;
}

[data-theme="light"] {
  --bg: #f2f2f2;
  --panel: #ffffff;
  --panel-alt: #eaeaea;
  --border: #d0d0d0;
  --accent: #c9a800;
  --accent-muted: #a88e00;
  --text: #1a1a1a;
  --muted: #666666;
  --banner-color: #ffffff;
}

/* === Reset & Base === */
* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Inter", system-ui, sans-serif;
  line-height: 1.5;
  transition: padding-left 0.25s ease;
}

code {
  font-family: "Cascadia Code", Consolas, monospace;
  background: var(--panel-alt);
  padding: 0.1rem 0.3rem;
  border-radius: 6px;
  color: var(--accent-muted);
}

/* === Layout === */
header.page-header {
  position: relative;
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem 1rem;
}

header.page-header h1 {
  margin: 0;
  font-size: 2rem;
  font-weight: 600;
}

header.page-header .tagline {
  margin-top: 0.5rem;
  color: var(--muted);
  max-width: 720px;
}

main {
  max-width: 960px;
  margin: 0 auto 3rem;
  padding: 0 1.5rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* === Panels === */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

#entry-count {
  color: var(--muted);
  font-size: 0.9rem;
}

/* === File Picker === */
.file-picker {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.file-picker .button {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.1rem;
  font-weight: 600;
  cursor: pointer;
}

.file-picker .button.ghost {
  background: transparent;
  border: 2px solid var(--accent);
  color: var(--accent);
}

.file-picker .button.ghost:hover {
  background: var(--accent);
  color: var(--bg);
}

.file-picker .button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#file-label { color: var(--muted); }

/* === Meta & Status === */
.meta { margin-top: 1.5rem; }

.meta-lines {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.meta-block {
  background: var(--panel-alt);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border);
  margin-bottom: 0.1rem;
  font-size: 0.97rem;
  color: var(--text);
  box-shadow: 0 1px 0 0 #181818;
}

.status {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 0.85rem;
}

#status-info { margin-top: 1.5rem; }

/* === Search === */
.search-container {
  width: 100%;
  margin-top: 1rem;
}

.search-wrapper {
  position: relative;
  width: 100%;
}

.search-wrapper .search-icon,
.search-wrapper .search-clear {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text);
  font-size: 1rem;
  z-index: 2;
}

.search-wrapper .search-icon {
  left: 1rem;
  pointer-events: none;
}

.search-wrapper .search-clear {
  right: 1rem;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.search-wrapper .search-clear:hover { opacity: 1; }

#search {
  width: 100%;
  padding: 0.75rem 3rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 1rem;
  appearance: none;
  -webkit-appearance: none;
}

#search::-webkit-search-cancel-button,
#search::-moz-search-cancel-button { display: none; }

#search:focus { outline: 1px solid var(--accent); }

/* === Filters === */
.filters-container {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
  width: 100%;
}

.filters-container .spacer { flex: 1 1 auto; }

.filters-container .action-buttons {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

.filters-container .filter-types {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.filter-checkbox {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  user-select: none;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  transition: all 0.2s;
}

.filter-checkbox:hover { border-color: var(--accent); }

.filter-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
}

.filter-checkbox span {
  font-size: 0.85rem;
  font-weight: 500;
}

/* Color-coded filter checkboxes */
.filter-checkbox:has(#filter-single) {
  border-color: rgba(154, 154, 154, 0.6);
  background: rgba(154, 154, 154, 0.1);
}
.filter-checkbox:has(#filter-single) input { accent-color: #9a9a9a; }

.filter-checkbox:has(#filter-empty) {
  border-color: rgba(128, 128, 128, 0.6);
  background: rgba(128, 128, 128, 0.1);
}
.filter-checkbox:has(#filter-empty) input { accent-color: #808080; }

.filter-checkbox:has(#filter-modified) {
  border-color: rgba(201, 178, 74, 0.6);
  background: rgba(201, 178, 74, 0.15);
}
.filter-checkbox:has(#filter-modified) input { accent-color: var(--accent-muted); }

/* === Buttons === */
button {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

button.ghost:not(:disabled):hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

button.danger {
  background: #e05050;
  color: white;
  border: none;
}

button.danger:hover { background: #c73e3e; }

/* === Entries === */
#entries {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.entry-card {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: opacity 0.35s ease, transform 0.35s ease,
              max-height 0.35s ease, margin 0.35s ease, padding 0.35s ease;
}

.entry-card.removing {
  opacity: 0;
  transform: translateY(-16px) scale(0.98);
  max-height: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  overflow: hidden;
  pointer-events: none;
}

.entry-card.modified { border-color: var(--accent); }

/* === Entry Header & Badges === */
.entry-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.entry-heading h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.entry-heading .badges {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

.badge-warning {
  border-color: rgba(201, 178, 74, 0.6);
  background: rgba(201, 178, 74, 0.15);
  color: var(--accent-muted);
}

/* === Entry Editor === */
.segment-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  margin-top: 0.5rem;
}

.segment-container:has(textarea:focus) {
  outline: 1px solid var(--accent);
  outline-offset: -2px;
}

.entry-editor {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.editor-shell {
  position: relative;
  width: 100%;
}

.editor-shell .text-highlight,
.editor-shell textarea {
  box-sizing: border-box;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 15px;
  line-height: 20px;
  padding: 0.75rem;
  min-height: 120px;
  font-variant-ligatures: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-weight: 400;
  letter-spacing: 0;
}

.editor-shell .text-highlight {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--panel);
  color: var(--text);
  pointer-events: none;
}

.editor-shell textarea {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  color: transparent;
  border: none;
  border-radius: 8px;
  resize: none;
  overflow: hidden;
  outline: none;
  caret-color: var(--accent);
}

/* === Token Chips === */
.token-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  border: 1px solid rgba(201, 178, 74, 0.55);
  background: rgba(201, 178, 74, 0.2);
  color: var(--accent) !important;
  font-weight: 600;
  margin: 0 0.1rem;
  font-size: 0.95em !important;
}

.highlight-empty { opacity: 0.45; }

/* === Entry Actions === */
.entry-actions,
.entry-helper {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.entry-actions { justify-content: space-between; }
.entry-helper { flex-wrap: wrap; }

.entry-btn-group {
  display: flex;
  gap: 0.5rem;
}

.entry-btn-group .delete-msg {
  color: #e05050;
  border-color: rgba(224, 80, 80, 0.4);
  padding: 0.55rem 0.7rem;
}

.entry-btn-group .delete-msg:not(:disabled):hover {
  background: var(--panel-alt);
  border-color: var(--panel-alt);
  color: #e05050;
}

/* === Game Config === */
#game-config-loader { margin: 1.5rem 0; }

.game-config-loader {
  position: relative;
  width: 100%;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  z-index: 2;
  border: 1px solid #444;
  border-radius: 18px;
}

.game-config-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(to right, var(--banner-color), transparent),
              var(--game-bg-url, none) center/cover no-repeat;
  opacity: 0.95;
  z-index: 1;
  pointer-events: none;
  transition: background-image 0.4s;
}

.game-config-content {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 960px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 2em;
}

.game-config-dropdown {
  display: flex;
  align-items: center;
  gap: 0.7em;
  margin: 0.5em 0 1em;
}

.game-config-label {
  font-weight: 600;
  font-size: 1.05em;
  color: var(--accent);
}

.game-config-select-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.game-config-select {
  padding: 0.35em 2.2em 0.35em 0.7em;
  font-size: 1em;
  border-radius: 6px;
  border: 1px solid var(--text);
  background: transparent;
  color: var(--text);
  appearance: none;
  outline: none;
  font-weight: 500;
  max-width: fit-content;
}

.game-config-select option { color: #222; }

.game-icon {
  height: 2.2em;
  width: auto;
  margin-left: 5px;
  display: none;
}

/* === Floating Toolbar === */
.floating-toolbar {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  gap: 0.5rem;
  z-index: 900;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.5rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

.floating-toolbar button {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 1rem;
  padding: 0;
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.floating-toolbar button:not(:disabled):hover {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

.floating-toolbar button:disabled { opacity: 0.35; }

/* === Modals === */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.75rem;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  transform: translateY(12px);
  transition: transform 0.2s;
}

.modal-overlay.open .modal-card { transform: translateY(0); }

.modal-card h3 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.modal-desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.modal-card input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.modal-card input:focus { border-color: var(--accent); }

.modal-error {
  color: #e05050;
  font-size: 0.82rem;
  font-weight: 500;
  min-height: 1.2em;
  display: none;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.modal-danger h3 {
  color: #e05050;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Modal extensions */
.modal-card.modal-wide {
  max-width: 480px;
}

.modal-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-top: 0.25rem;
}

.modal-textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 0.95rem;
  font-family: "Cascadia Code", Consolas, monospace;
  outline: none;
  resize: vertical;
  min-height: 60px;
  transition: border-color 0.15s;
}

.modal-textarea:focus { border-color: var(--accent); }

.modal-attr-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.modal-attr-row input[type="text"] {
  flex: 1;
  font-family: "Cascadia Code", Consolas, monospace;
  letter-spacing: 0.05em;
}

.modal-attr-row input[type="number"] {
  width: 64px;
  text-align: center;
  padding: 0.65rem 0.4rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  -moz-appearance: textfield;
  appearance: textfield;
}

.modal-attr-row input[type="number"]::-webkit-inner-spin-button,
.modal-attr-row input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.modal-attr-row input[type="number"]:focus { border-color: var(--accent); }

/* Edit dropdown */
.edit-dropdown {
  position: absolute;
  bottom: 100%;
  right: 0;
  margin-bottom: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.35rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  z-index: 100;
  display: flex;
  flex-direction: column;
  min-width: 170px;
}

.edit-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s;
}

.edit-dropdown-item:hover {
  background: var(--panel-alt);
}

/* Edit button in entry button group */
.entry-btn-group .edit-msg {
  color: var(--text);
  border-color: var(--border);
  padding: 0.55rem 0.7rem;
}

.entry-btn-group .edit-msg:not(:disabled):hover {
  background: var(--panel-alt);
  border-color: var(--panel-alt);
  color: var(--text);
}

/* === Folder Sidebar === */
.folder-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--panel);
  border-right: 1px solid var(--border);
  z-index: 800;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
}

body.sidebar-open .folder-sidebar { transform: translateX(0); }
body.sidebar-open { padding-left: var(--sidebar-w); }
body.resizing, body.resizing .folder-sidebar { transition: none !important; }

.folder-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  gap: 0.5rem;
}

.folder-sidebar-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl;
  text-align: left;
  flex: 1;
}

.folder-sidebar-actions {
  display: flex;
  gap: 0.35rem;
}

.folder-sidebar-actions button {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 0;
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  cursor: pointer;
}

.folder-sidebar-actions button:hover {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

.folder-file-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.5rem;
}

.folder-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: none;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 400;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s;
}

.folder-item:hover,
.folder-item.ctx-target {
  background: var(--panel-alt) !important;
  color: var(--text) !important;
  font-weight: 400;
}

.folder-resize-handle {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 801;
}

.folder-resize-handle:hover,
.folder-resize-handle:active { background: var(--accent); opacity: 0.4; }

.folder-item.active {
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
}

/* === Folder Context Menu === */
.folder-ctx-menu {
  position: fixed;
  z-index: 1100;
  min-width: 150px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.35rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.95);
  transition: opacity 0.12s, transform 0.12s;
}

.folder-ctx-menu.open {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

.folder-ctx-menu .ctx-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s;
}

.folder-ctx-menu .ctx-item:hover {
  background: var(--panel-alt);
}

.folder-ctx-menu .ctx-item.danger {
  color: #e05050;
}

.folder-ctx-menu .ctx-item.danger:hover {
  background: rgba(224, 80, 80, 0.12);
}

/* Inline rename input inside folder item */
.folder-rename-input {
  width: 100%;
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--panel-alt);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
}

/* === Responsive === */
.folder-sidebar-tab {
  display: none;
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 56px;
  border-radius: 0 8px 8px 0;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: none;
  font-size: 0.8rem;
  cursor: pointer;
  z-index: 810;
  padding: 0;
  align-items: center;
  justify-content: center;
}
.folder-sidebar-tab:hover { background: var(--accent); color: var(--bg); border-color: var(--accent); }

@media (max-width: 640px) {
  header.page-header { padding-top: 1.5rem; }
  main { padding-bottom: 2rem; }

  .entry-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .entry-helper { justify-content: space-between; }

  /* Sidebar: full-width overlay on mobile */
  body.sidebar-open { padding-left: 0 !important; }
  .folder-sidebar {
    width: 100% !important;
    max-width: none !important;
    height: 100dvh !important;
  }
  .folder-resize-handle { display: none; }

  /* Minimize tab: right edge of sidebar */
  body.sidebar-open:not(.sidebar-minimized) #folder-minimize-btn {
    display: flex;
    left: auto;
    right: 0;
    border-radius: 8px 0 0 8px;
    border-right: none;
    border-left: 1px solid var(--border);
  }

  /* Reopen tab: left edge of screen */
  body.sidebar-minimized #folder-reopen-btn {
    display: flex;
    left: 0;
  }
  body.sidebar-minimized .folder-sidebar { transform: translateX(-100%) !important; }
}
