:root {
  --bg-primary: #121418;
  --bg-secondary: #1e222b;
  --bg-card: #272d3b;
  --accent: #e67e22;
  --accent-hover: #f39c12;
  --text-primary: #f0f4f8;
  --text-secondary: #9ba5b7;
  --border-color: #384252;
  --success: #2ecc71;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

#app-container {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  position: relative;
}

/* TOP HEADER */
#header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  z-index: 20;
  gap: 15px;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.title-container h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.3px;
}

.level-select-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.level-dropdown {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  max-width: 280px;
  transition: all 0.15s ease;
}

.level-dropdown:hover {
  border-color: #53647d;
  background: #303746;
}

.title-container span {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 260px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.progress-bar-bg {
  width: 100%;
  height: 10px;
  background: #14171d;
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #d35400, #f39c12, #2ecc71);
  border-radius: 5px;
  transition: width 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.header-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 1;
}

#btn-save {
  width: 88px;
  justify-content: center;
  flex-shrink: 0;
}

.btn {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.btn:hover {
  background: #323b4e;
  border-color: #4a566b;
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-icon {
  padding: 7px 10px;
  font-size: 1rem;
}

.btn.active {
  background: var(--accent);
  color: #fff;
  border-color: #d35400;
}

.btn.dirty {
  border-color: var(--accent);
  color: #f8c291;
}

.btn.saved {
  border-color: var(--success);
  color: var(--success);
}

/* GOOGLE AUTH & USER PROFILE BADGE */
.auth-container {
  display: flex;
  align-items: center;
  margin-left: 4px;
}

.btn-login {
  background: #2b3344;
  border-color: #46536e;
  white-space: nowrap;
}

.google-g {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  color: #4285f4;
  font-weight: 900;
  font-size: 0.78rem;
  font-family: Arial, sans-serif;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 4px 10px 4px 5px;
}

.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  background: #384252;
}

.user-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  max-width: 95px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  background: transparent;
  border: none;
  border-left: 1px solid var(--border-color);
  padding-left: 8px;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-logout:hover {
  color: #fff;
}

/* GAME CANVAS WRAPPER */
#game-wrapper {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #181b22;
  overflow: hidden;
  cursor: crosshair;
}

#game-wrapper.dragging {
  cursor: grabbing;
}

#phaser-container {
  width: 100%;
  height: 100%;
}

/* FLOATING CONTROLS */
.floating-controls {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 15;
}

.float-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(30, 34, 43, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  color: #fff;
  font-size: 1.2rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: all 0.15s ease;
}

.float-btn:hover {
  background: rgba(45, 52, 66, 0.95);
  transform: scale(1.05);
}

/* TOAST MESSAGE */
#toast-msg {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(26, 30, 39, 0.95);
  border: 1px solid var(--border-color);
  color: #fff;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  transition: all 0.25s ease;
  z-index: 30;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

#toast-msg.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* BOTTOM PALETTE DOCK */
#palette-bar {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 20;
  flex-shrink: 0;
}

.palette-status-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.active-color-name {
  font-weight: 700;
  color: #fff;
}

.palette-scroll {
  display: flex;
  align-items: center;
  gap: 12px;
  overflow-x: auto;
  padding: 10px 8px 12px 8px;
  scroll-behavior: smooth;
}

.palette-scroll::-webkit-scrollbar {
  height: 6px;
}

.palette-scroll::-webkit-scrollbar-thumb {
  background: #384252;
  border-radius: 3px;
}

/* COLOR SWATCH ITEM */
.color-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.color-swatch:hover {
  transform: translateY(-2px);
}

.swatch-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  font-weight: 800;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
  position: relative;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.color-swatch.active .swatch-circle {
  border-color: #fff;
  transform: scale(1.18);
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.5), 0 6px 14px rgba(0, 0, 0, 0.4);
}

.swatch-badge {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-secondary);
  background: var(--bg-card);
  padding: 2px 7px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
}

.color-swatch.completed .swatch-circle {
  opacity: 0.85;
}

.color-swatch.completed .swatch-circle::after {
  content: "✓";
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--success);
  color: #fff;
  font-size: 0.75rem;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-secondary);
}

.color-swatch.completed .swatch-badge {
  color: var(--success);
  border-color: rgba(46, 204, 113, 0.4);
}

/* MODAL DIALOGS */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

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

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 24px;
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  transform: scale(0.95);
  transition: transform 0.25s ease;
}

.modal-overlay.open .modal-card {
  transform: scale(1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px;
}

.close-btn:hover {
  color: #fff;
}

.modal-body {
  overflow: auto;
  display: flex;
  justify-content: center;
}

.modal-body img {
  max-width: 100%;
  max-height: 65vh;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

/* CELEBRATION MODAL */
.celebrate-card {
  text-align: center;
  align-items: center;
  padding: 36px 30px;
}

.celebrate-card h2 {
  font-size: 2rem;
  color: #f1c40f;
  margin-top: 10px;
}

.celebrate-card p {
  color: var(--text-secondary);
  font-size: 1.05rem;
  max-width: 380px;
}

/* GALLERY HUB VIEW (LEFT SIDEBAR + RIGHT UNCOLORED CHOICES GRID) */
.gallery-view {
  flex: 1;
  min-height: 0;
  display: flex;
  background: var(--bg-primary);
  overflow: hidden;
}

.gallery-sidebar {
  width: 240px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.sidebar-bottom {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
}

.settings-panel {
  flex: 1;
  min-height: 240px;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.settings-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.settings-card h3 {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
}

.settings-card p {
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.sidebar-heading {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  padding: 0 10px 8px 10px;
}

.filter-nav-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}

.filter-nav-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.filter-nav-btn.active {
  background: var(--bg-card);
  border-color: var(--accent);
  color: #fff;
}

.filter-count {
  background: #14171d;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
}

.filter-nav-btn.active .filter-count {
  background: var(--accent);
  color: #fff;
  border-color: #d35400;
}

.gallery-main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.gallery-header-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gallery-header-row h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
}

.gallery-subtitle {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 20px;
  padding-bottom: 30px;
}

.puzzle-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.puzzle-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
}

.puzzle-card-thumb-wrap {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #f4f1ea;
  overflow: hidden;
  position: relative;
  border-bottom: 1px solid var(--border-color);
}

.puzzle-card-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.puzzle-card-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(18, 20, 24, 0.85);
  color: #f0f4f8;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.puzzle-card-badge.completed {
  background: rgba(46, 204, 113, 0.92);
  color: #fff;
  border-color: #27ae60;
}

.puzzle-card-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.puzzle-card-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.puzzle-card-meta {
  font-size: 0.78rem;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.gallery-empty {
  grid-column: 1 / -1;
  background: var(--bg-secondary);
  border: 1px dashed var(--border-color);
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.gallery-tag-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.tag-filter-pill {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 5px 13px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-transform: capitalize;
}

.tag-filter-pill:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.tag-filter-pill.active {
  background: var(--accent);
  color: #fff;
  border-color: #d35400;
}

.puzzle-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
}

.puzzle-card-tag {
  background: #1a1e26;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1px 7px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: lowercase;
}

.puzzle-card-tag.free-tag {
  background: rgba(46, 204, 113, 0.16);
  color: #2ecc71;
  border-color: rgba(46, 204, 113, 0.45);
}

.puzzle-card.locked .puzzle-card-thumb {
  filter: brightness(0.82);
  transition: filter 0.18s ease;
}

.puzzle-card.locked:hover .puzzle-card-thumb {
  filter: brightness(0.95);
}

.puzzle-card-lock-pill {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(18, 20, 24, 0.9);
  color: #f39c12;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 8px;
  border: 1px solid rgba(243, 156, 18, 0.55);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.puzzle-card-free-pill {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(46, 204, 113, 0.92);
  color: #fff;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 8px;
  border: 1px solid #27ae60;
}
