/* ===== BOARDELLO — CSS ===== */
:root {
  --bg: #F5F2EB;
  --bg2: #EDEADF;
  --surface: #FFFEF9;
  --border: #D8D3C5;
  --border2: #C4BDB0;
  --text: #1A1714;
  --text2: #5A5550;
  --text3: #9A948D;
  --accent: #2B4D2E;
  --accent-light: #E8F0E8;
  --accent2: #8B3A1A;
  --accent2-light: #F5EAE4;
  --danger: #C0392B;
  --danger-light: #FAE8E6;
  --font-display: 'DM Serif Display', serif;
  --font-body: 'DM Sans', sans-serif;
  --font-mono: 'DM Mono', monospace;
  --radius: 4px;
  --radius-lg: 8px;
  --sidebar-w: 220px;
  --transition: 0.18s ease;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== AUTH ===== */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.auth-box {
  text-align: center;
  padding: 3rem;
}
.auth-logo { margin-bottom: 2.5rem; }
.logo-text {
  font-family: var(--font-display);
  font-size: 3rem;
  color: var(--text);
  display: block;
  letter-spacing: -0.02em;
}
.logo-sub {
  font-size: 14px;
  color: var(--text3);
  display: block;
  margin-top: 0.25rem;
  font-style: italic;
}
.auth-note {
  margin-top: 1rem;
  font-size: 12px;
  color: var(--text3);
}

/* ===== LAYOUT ===== */
#app {
  display: flex;
  min-height: 100vh;
}
#app.hidden { display: none; }

#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 2rem 0;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform var(--transition);
}
.sidebar-logo {
  padding: 0 1.5rem 2rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.sidebar-logo .logo-text { font-size: 1.8rem; }

.nav-links { list-style: none; flex: 1; }
.nav-links li { }
.nav-link {
  display: block;
  padding: 0.65rem 1.5rem;
  color: var(--text2);
  text-decoration: none;
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0.01em;
  transition: color var(--transition), background var(--transition);
  border-left: 2px solid transparent;
}
.nav-link:hover { color: var(--text); background: var(--bg); }
.nav-link.active {
  color: var(--accent);
  font-weight: 500;
  border-left: 2px solid var(--accent);
  background: var(--accent-light);
}

.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}
.user-email {
  display: block;
  font-size: 11px;
  color: var(--text3);
  margin-bottom: 0.5rem;
  word-break: break-all;
  font-family: var(--font-mono);
}
.btn-logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--text3);
  font-size: 12px;
  padding: 4px 12px;
  cursor: pointer;
  border-radius: var(--radius);
  font-family: var(--font-body);
  transition: all var(--transition);
}
.btn-logout:hover { color: var(--danger); border-color: var(--danger); }

#main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 2.5rem;
  max-width: 1200px;
}

.hamburger {
  display: none;
  position: fixed;
  top: 1rem; left: 1rem;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 18px;
  border-radius: var(--radius);
}

/* ===== SECTIONS ===== */
.section { }
.section.hidden { display: none; }
.section.active { display: block; }

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
  gap: 1rem;
}
.section-header h1 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 400;
  letter-spacing: -0.02em;
}
.header-actions { display: flex; gap: 0.75rem; }

/* ===== BUTTONS ===== */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius);
  font-family: var(--font-body);
  transition: opacity var(--transition);
  letter-spacing: 0.02em;
}
.btn-primary:hover { opacity: 0.85; }
.btn-secondary {
  background: var(--surface);
  color: var(--text2);
  border: 1px solid var(--border);
  padding: 7px 18px;
  font-size: 13px;
  cursor: pointer;
  border-radius: var(--radius);
  font-family: var(--font-body);
  transition: all var(--transition);
}
.btn-secondary:hover { border-color: var(--border2); color: var(--text); }
.btn-danger {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 7px 16px;
  font-size: 13px;
  cursor: pointer;
  border-radius: var(--radius);
  font-family: var(--font-body);
}

/* ===== FILTERS ===== */
.filters-bar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  align-items: center;
}
.search-input {
  flex: 1;
  min-width: 200px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}
.search-input:focus { border-color: var(--border2); }
.filter-select {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text2);
  cursor: pointer;
  outline: none;
}
.filter-select:focus { border-color: var(--border2); }

.games-count {
  font-size: 12px;
  color: var(--text3);
  margin-bottom: 1rem;
  font-family: var(--font-mono);
}

/* ===== GAMES GRID ===== */
.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}
.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition);
}
.game-card:hover {
  border-color: var(--border2);
  transform: translateY(-2px);
}
.game-card-img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: var(--bg2);
}
.game-card-img-placeholder {
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text3);
  text-align: center;
  padding: 0.5rem;
}
.game-card-body {
  padding: 0.6rem 0.75rem 0.75rem;
}
.game-card-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.game-card-meta {
  font-size: 11px;
  color: var(--text3);
  font-family: var(--font-mono);
}
.game-card-pos {
  display: inline-block;
  margin-top: 4px;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 2px;
}
.game-card-expansion {
  display: inline-block;
  margin-top: 4px;
  background: var(--accent2-light);
  color: var(--accent2);
  font-size: 10px;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: 2px;
}

.loading-state {
  grid-column: 1/-1;
  text-align: center;
  color: var(--text3);
  padding: 3rem;
  font-style: italic;
}
.error-state {
  grid-column: 1/-1;
  text-align: center;
  color: var(--danger);
  padding: 3rem;
}

/* ===== MODAL ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(26,23,20,0.5);
}
.modal-box {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 2rem;
  border: 1px solid var(--border);
}
.modal-close {
  position: absolute;
  top: 1rem; right: 1rem;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text3);
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

/* MODAL CONTENT */
.modal-inner { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.modal-cover {
  width: 160px;
  flex-shrink: 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.modal-cover img { width: 100%; display: block; }
.modal-info { flex: 1; min-width: 200px; }
.modal-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 400;
  margin-bottom: 0.25rem;
  line-height: 1.2;
}
.modal-year { font-size: 13px; color: var(--text3); margin-bottom: 1rem; }
.modal-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}
.modal-stat-item { }
.modal-stat-label { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.05em; }
.modal-stat-val { font-size: 15px; font-weight: 500; font-family: var(--font-mono); }

.modal-position-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 1rem;
}
.modal-position-title {
  font-size: 11px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}
.modal-position-code {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 500;
  color: var(--accent);
}
.modal-position-desc { font-size: 12px; color: var(--text3); margin-top: 2px; }

.modal-edit-pos {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  align-items: center;
}
.modal-edit-pos input {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 14px;
  width: 80px;
  background: var(--surface);
  color: var(--text);
}
.modal-personal {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.personal-field label {
  display: block;
  font-size: 11px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 3px;
}
.personal-field input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
}
.modal-plays {
  margin-top: 1rem;
  font-size: 13px;
  color: var(--text2);
}
.modal-last-play {
  font-size: 12px;
  color: var(--text3);
  font-style: italic;
}

/* ===== MAP ===== */
.map-hint {
  font-size: 13px;
  color: var(--text3);
  margin-bottom: 1rem;
  font-style: italic;
}
.map-canvas {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  min-height: 500px;
  overflow: hidden;
}
#shelves-container {
  position: relative;
  width: 100%;
  height: 600px;
}
.shelf-block {
  position: absolute;
  background: var(--bg2);
  border: 2px solid var(--border2);
  border-radius: var(--radius);
  cursor: grab;
  user-select: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: border-color var(--transition);
}
.shelf-block:hover { border-color: var(--accent); }
.shelf-block.selected { border-color: var(--accent); border-width: 2px; }
.shelf-block.dragging { cursor: grabbing; opacity: 0.85; z-index: 10; }
.shelf-label {
  background: var(--accent);
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.1rem;
  text-align: center;
  padding: 4px 0;
  line-height: 1;
}
.shelf-rows {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 4px;
  gap: 3px;
}
.shelf-row {
  flex: 1;
  background: var(--surface);
  border-radius: 2px;
  border: 1px solid var(--border);
  font-size: 9px;
  color: var(--text3);
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  padding: 0 4px;
  min-height: 12px;
}
.shelf-desc-label {
  text-align: center;
  font-size: 9px;
  color: var(--text3);
  padding: 2px 4px;
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* SHELF EDITOR PANEL */
.shelf-editor {
  position: fixed;
  right: 2rem;
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 240px;
  z-index: 200;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}
.shelf-editor.hidden { display: none; }
.shelf-editor h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  margin-bottom: 1rem;
  font-weight: 400;
}
.shelf-editor label {
  display: block;
  font-size: 11px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.75rem;
  margin-bottom: 3px;
}
.shelf-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.shelf-input:focus { border-color: var(--border2); }
.shelf-editor-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

/* ===== STATS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 2.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}
.stat-card-wide { grid-column: span 2; }
.stat-label {
  font-size: 11px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}
.stat-value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 400;
  color: var(--text);
  letter-spacing: -0.02em;
}
.stat-value.positive { color: var(--accent); }
.stat-value.negative { color: var(--danger); }

.stats-section-title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 400;
  margin-bottom: 1rem;
}

.plays-chart {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 2rem;
  min-height: 160px;
}
.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 120px;
}
.chart-bar-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1; }
.chart-bar {
  width: 100%;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  min-height: 3px;
  transition: height 0.4s ease;
}
.chart-bar-label { font-size: 10px; color: var(--text3); font-family: var(--font-mono); }
.chart-bar-val { font-size: 10px; color: var(--text2); font-family: var(--font-mono); }

.top-played-list, .recent-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 2rem;
}
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  gap: 1rem;
}
.list-row:last-child { border-bottom: none; }
.list-row-title { color: var(--text); font-weight: 500; flex: 1; }
.list-row-meta { font-family: var(--font-mono); font-size: 12px; color: var(--text3); white-space: nowrap; }

/* ===== CHAT ===== */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 200px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.chat-message { display: flex; }
.chat-message.assistant { justify-content: flex-start; }
.chat-message.user { justify-content: flex-end; }
.msg-bubble {
  max-width: 75%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.6;
}
.chat-message.assistant .msg-bubble {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 2px var(--radius-lg) var(--radius-lg) var(--radius-lg);
}
.chat-message.user .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-lg) 2px var(--radius-lg) var(--radius-lg);
}
.msg-bubble.typing {
  font-style: italic;
  color: var(--text3);
}
.chat-input-bar {
  display: flex;
  border-top: 1px solid var(--border);
  padding: 1rem;
  gap: 0.75rem;
  align-items: flex-end;
  background: var(--surface);
}
#chat-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 14px;
  resize: none;
  outline: none;
  background: var(--bg);
  color: var(--text);
  max-height: 120px;
  overflow-y: auto;
}
#chat-input:focus { border-color: var(--border2); }
.btn-send {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius);
  font-family: var(--font-body);
  white-space: nowrap;
  transition: opacity var(--transition);
  align-self: flex-end;
}
.btn-send:hover { opacity: 0.85; }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== MAP HIGHLIGHT ===== */
.shelf-block.highlighted {
  border-color: var(--accent2) !important;
  border-width: 3px !important;
  box-shadow: 0 0 0 3px var(--accent2-light);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  #sidebar {
    transform: translateX(-100%);
  }
  #sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.1);
  }
  #main {
    margin-left: 0;
    padding: 1.25rem;
    padding-top: 3.5rem;
  }
  .hamburger { display: block; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-card-wide { grid-column: span 2; }
  .modal-inner { flex-direction: column; }
  .modal-cover { width: 100%; max-height: 200px; overflow: hidden; }
  .shelf-editor { right: 1rem; left: 1rem; width: auto; transform: none; top: auto; bottom: 1rem; }
}

@media (max-width: 480px) {
  .games-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card-wide { grid-column: span 1; }
}

/* ===== AUTH FORM ===== */
.auth-input {
  display: block;
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}
.auth-input:focus { border-color: var(--border2); }
.auth-box .btn-primary { width: 100%; padding: 11px; font-size: 15px; margin-top: 0.25rem; }
.auth-switch { margin-top: 1rem; font-size: 13px; color: var(--text3); }
.auth-switch a { color: var(--accent); text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }
.auth-error {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 1rem;
}
.auth-error.hidden { display: none; }
#auth-register-form.hidden, #auth-login-form.hidden { display: none; }

/* ===== FIX AUTH HIDDEN ===== */
#auth-screen.hidden { display: none !important; }
#app.hidden { display: none !important; }

/* ===== SHELF ROWS & BLOCKS ===== */
.shelf-row {
  display: flex;
  align-items: center;
  gap: 3px;
  flex: 1;
  min-height: 18px;
}
.shelf-row-label {
  font-size: 9px;
  color: var(--text3);
  font-family: var(--font-mono);
  width: 10px;
  flex-shrink: 0;
  text-align: center;
}
.shelf-cells {
  display: flex;
  gap: 2px;
  flex: 1;
}
.shelf-cell {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 8px;
  color: var(--text3);
  font-family: var(--font-mono);
  text-align: center;
  padding: 1px 0;
  cursor: default;
  min-height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.shelf-cell.highlighted-cell {
  background: var(--accent2);
  color: #fff;
  border-color: var(--accent2);
  font-weight: 700;
}

/* ===== MODAL SHELF MINIATURE ===== */
.modal-shelf-mini { margin-top: 0.75rem; }
.mini-shelf-wrap {
  display: inline-block;
  border: 1.5px solid var(--border2);
  border-radius: var(--radius);
  overflow: hidden;
  min-width: 100px;
  max-width: 200px;
}
.mini-shelf-header {
  background: var(--accent);
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.9rem;
  text-align: center;
  padding: 2px 0;
}
.mini-shelf-rows { padding: 4px; display: flex; flex-direction: column; gap: 3px; }
.mini-row { display: flex; align-items: center; gap: 3px; }
.mini-row-label { font-size: 8px; color: var(--text3); font-family: var(--font-mono); width: 8px; text-align: center; flex-shrink: 0; }
.mini-cells { display: flex; gap: 2px; flex: 1; }
.mini-cell {
  flex: 1;
  height: 12px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 1px;
}
.mini-cell-active {
  background: var(--accent2);
  border-color: var(--accent2);
  box-shadow: 0 0 0 1px var(--accent2-light);
}
.mini-shelf-desc { font-size: 9px; color: var(--text3); text-align: center; padding: 2px 4px; font-style: italic; }
