/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #fff;
  --bg-secondary: #f5f5f5;
  --text: #1a1a1a;
  --text-secondary: #666;
  --border: #d4d4d4;
  --border-light: #e8e8e8;
  --accent: #1a1a1a;
  --accent-hover: #444;
  --danger: #c00;
  --radius: 4px;
  --max-width: 1200px;
  --nav-height: 56px;
}

html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

/* === Navbar === */
.navbar {
  height: var(--nav-height);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 2rem;
  position: sticky; top: 0; background: var(--bg); z-index: 100;
}
.navbar .logo { font-size: 1.2rem; font-weight: 700; letter-spacing: 0.05em; }
.navbar nav { display: flex; gap: 1.5rem; align-items: center; }
.navbar nav a { color: var(--text-secondary); font-size: 0.9rem; transition: color .15s; }
.navbar nav a:hover { color: var(--text); text-decoration: none; }
.navbar .user-menu { display: flex; gap: 1rem; align-items: center; }
.navbar .user-menu .username { color: var(--text-secondary); font-size: 0.85rem; }

/* === Layout === */
.container { max-width: var(--max-width); margin: 0 auto; padding: 2rem; }
.page-title { font-size: 1.5rem; font-weight: 600; margin-bottom: 1.5rem; }

/* === Buttons === */
.btn {
  display: inline-block; padding: 0.55rem 1.2rem; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); border-radius: var(--radius);
  font-size: 0.9rem; cursor: pointer; transition: all .15s; text-align: center;
}
.btn:hover { background: var(--bg-secondary); text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.3rem 0.8rem; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* === Forms === */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; margin-bottom: 0.35rem; color: var(--text-secondary); }
.form-input {
  width: 100%; padding: 0.6rem 0.8rem; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 0.9rem; outline: none; transition: border-color .15s;
}
.form-input:focus { border-color: var(--accent); }
textarea.form-input { resize: vertical; min-height: 80px; }

.form-card {
  max-width: 400px; margin: 4rem auto; padding: 2rem;
  border: 1px solid var(--border-light); border-radius: var(--radius);
}
.form-card h2 { font-size: 1.25rem; margin-bottom: 1.5rem; text-align: center; }
.form-card .form-extra { text-align: center; margin-top: 1rem; font-size: 0.85rem; color: var(--text-secondary); }

/* === Cards === */
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.5rem; }
.gallery-card {
  border: 1px solid var(--border-light); border-radius: var(--radius);
  overflow: hidden; transition: box-shadow .15s; cursor: pointer;
}
.gallery-card:hover { box-shadow: 0 2px 12px rgba(0,0,0,0.08); text-decoration: none; }
.gallery-card .card-cover {
  height: 180px; background: var(--bg-secondary);
  display: flex; align-items: center; justify-content: center;
  color: var(--border); font-size: 2.5rem; overflow: hidden;
}
.gallery-card .card-cover img { width: 100%; height: 100%; object-fit: cover; }
.gallery-card .card-body { padding: 1rem; }
.gallery-card .card-body h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.25rem; }
.gallery-card .card-body p { font-size: 0.85rem; color: var(--text-secondary); }
.gallery-card .card-body .card-meta { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.5rem; }

/* === Messages === */
.message { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.message-error { background: #fef2f2; border: 1px solid #fecaca; color: var(--danger); }
.message-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }

/* === Utilities === */
.text-center { text-align: center; }
.text-secondary { color: var(--text-secondary); font-size: 0.85rem; }
.mt-1 { margin-top: 1rem; }
.mt-2 { margin-top: 2rem; }
.hidden { display: none !important; }

/* === Dashboard Stats === */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card {
  padding: 1.25rem; border: 1px solid var(--border-light); border-radius: var(--radius); text-align: center;
}
.stat-card .stat-number { font-size: 2rem; font-weight: 700; }
.stat-card .stat-label { font-size: 0.85rem; color: var(--text-secondary); }

/* === Gallery View === */
.gallery-viewer { position: relative; }
/* === Main Image Area === */
.gallery-viewer .main-image-area {
  display: flex; justify-content: center; align-items: center;
  background: var(--bg-secondary);
  min-height: 400px;
}
.gallery-viewer .main-image-area .miv-wrap {
  display: inline-block; position: relative;
}
.gallery-viewer .main-image-area .miv-wrap img {
  vertical-align: top;
}
.gallery-viewer .main-image-area img {
  max-height: 85vh; max-width: 100%; object-fit: contain; transition: opacity .4s ease;
}
.gallery-viewer .main-image-area img.fade-out { opacity: 0; }

.img-loader {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: transparent; z-index: 5;
}
.img-loader.active { display: flex; }
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Viewer floating buttons — fixed at viewport corners */
.back-btn, .fs-btn {
  position: fixed; z-index: 20;
  width: 34px; height: 34px; border-radius: 50%; border: none;
  background: rgba(0,0,0,0.35); color: #fff; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s; flex-shrink: 0;
}
.back-btn { top: 8px; left: 8px; }
.fs-btn { top: 8px; right: 8px; }
.back-btn:hover, .fs-btn:hover { background: rgba(0,0,0,0.7); }

/* Hide non-image children in fullscreen (keep buttons visible) */
:fullscreen .share-container > .gallery-viewer > *:not(.main-image-area),
:-webkit-full-screen .share-container > .gallery-viewer > *:not(.main-image-area) { display: none; }
:fullscreen .share-container > :not(.gallery-viewer):not(.back-btn):not(.fs-btn),
:-webkit-full-screen .share-container > :not(.gallery-viewer):not(.back-btn):not(.fs-btn) { display: none; }

/* Anchor dots */
.anchor-dot {
  position: absolute; width: 24px; height: 24px;
  border: 2px solid #fff; border-radius: 50%; background: rgba(0,0,0,0.5);
  cursor: pointer; transform: translate(-50%, -50%); transition: all .2s;
  display: flex; align-items: center; justify-content: center;
}
.anchor-dot::after {
  content: ''; width: 8px; height: 8px; background: #fff; border-radius: 50%;
}
.anchor-dot:hover { background: rgba(0,0,0,0.8); transform: translate(-50%, -50%) scale(1.2); }
.anchor-dot .anchor-label {
  position: absolute; top: -24px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.8); color: #fff; padding: 2px 8px;
  border-radius: 3px; font-size: 0.75rem; white-space: nowrap; pointer-events: none; opacity: 0;
  transition: opacity .15s;
}
.anchor-dot:hover .anchor-label { opacity: 1; }

.gallery-controls {
  display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1rem;
}
.gallery-controls .nav-btn {
  width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 50%;
  background: var(--bg); cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; transition: all .15s;
}
.gallery-controls .nav-btn:hover { background: var(--accent); color: #fff; }
.gallery-controls .image-counter { font-size: 0.85rem; color: var(--text-secondary); }

/* === Thumbnail Strip === */
.thumbnail-strip {
  display: flex; gap: 0.5rem; padding: 0.75rem 0; overflow-x: auto; justify-content: center;
}
.thumbnail-strip .thumb {
  width: 60px; height: 60px; border: 2px solid transparent; cursor: pointer;
  border-radius: var(--radius); overflow: hidden; flex-shrink: 0; opacity: 0.6; transition: all .15s;
}
.thumbnail-strip .thumb.active { border-color: var(--accent); opacity: 1; }
.thumbnail-strip .thumb img { width: 100%; height: 100%; object-fit: cover; }

/* === Image Manager === */
.image-manager { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; }
.image-card {
  border: 1px solid var(--border-light); border-radius: var(--radius); overflow: hidden; position: relative;
}
.image-card .img-wrap { height: 150px; background: var(--bg-secondary); overflow: hidden; }
.image-card .img-wrap img { width: 100%; height: 100%; object-fit: cover; }
.image-card .img-info { padding: 0.5rem; font-size: 0.75rem; }
.image-card .img-actions { display: flex; gap: 0.25rem; padding: 0 0.5rem 0.5rem; }

/* === Canvas Editor Modal === */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal-body {
  background: var(--bg); border-radius: var(--radius); padding: 1.5rem;
  max-width: 90vw; max-height: 90vh; overflow: auto;
}
.modal-body h3 { margin-bottom: 1rem; }
.editor-tools { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.editor-canvas-wrap { border: 1px solid var(--border); display: inline-block; }

/* === Anchor Editor === */
.anchor-editor { position: relative; display: inline-block; cursor: crosshair; }
.anchor-editor .edit-dot {
  position: absolute; width: 20px; height: 20px; border: 2px solid #e00;
  border-radius: 50%; background: rgba(255,0,0,0.3); transform: translate(-50%, -50%);
  cursor: pointer; z-index: 10;
}
.anchor-editor .edit-dot:hover { background: rgba(255,0,0,0.6); }
.anchor-editor .edit-dot.selected { background: rgba(255,0,0,0.8); border-color: #fff; border-width: 3px; transform: translate(-50%, -50%) scale(1.3); }

/* === Home Hero === */
.hero { text-align: center; padding: 3rem 2rem; }
.hero h1 { font-size: 2.5rem; font-weight: 300; letter-spacing: 0.1em; margin-bottom: 0.5rem; }
.hero p { color: var(--text-secondary); font-size: 1rem; margin-bottom: 1.5rem; }

/* === Share Page === */
.share-page { background: #f8f8f8; }
.share-page .navbar { display: none; }
.share-container {
  max-width: 1400px; margin: 0 auto; padding: 1rem;
  min-height: 100vh; display: flex; flex-direction: column; justify-content: center;
}
.share-container .gallery-viewer .main-image-area { background: #f8f8f8; }
.share-container .gallery-viewer .main-image-area img { max-height: 88vh; }
.share-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.25rem; text-align: center; }

/* Fullscreen: image covers viewport (after share rules to win specificity tie) */
:fullscreen .gallery-viewer .main-image-area,
:-webkit-full-screen .gallery-viewer .main-image-area {
  position: fixed; inset: 0; background: #000; min-height: 0;
  display: flex; align-items: center; justify-content: center;
}
:fullscreen .gallery-viewer .main-image-area .miv-wrap,
:-webkit-full-screen .gallery-viewer .main-image-area .miv-wrap {
  display: inline-block; position: relative;
}
:fullscreen .gallery-viewer .main-image-area .miv-wrap img,
:-webkit-full-screen .gallery-viewer .main-image-area .miv-wrap img {
  max-height: 100vh; max-width: 100vw;
  vertical-align: top; object-fit: contain;
}

/* Rotate prompt for mobile fullscreen */
.rotate-prompt {
  display: none; position: fixed; inset: 0; z-index: 999;
  background: #000; color: #fff;
  flex-direction: column; align-items: center; justify-content: center;
  font-size: 1rem;
}
.rotate-prompt .rotate-icon {
  width: 48px; height: 48px; border: 3px solid #fff; border-radius: 8px;
  margin-bottom: 1.5rem; position: relative;
  animation: rotateHint 1.6s ease-in-out infinite;
}
.rotate-prompt .rotate-icon::after {
  content: ''; position: absolute; top: 4px; left: 50%; margin-left: -1px;
  width: 2px; height: 16px; background: #fff; border-radius: 1px;
}
@keyframes rotateHint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
}

/* === Anchor Target Grid === */
.target-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; max-height: 300px; overflow-y: auto; }
.target-thumb {
  width: 100%; aspect-ratio: 1; border: 2px solid var(--border-light);
  border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: border-color .15s;
  display: flex; align-items: center; justify-content: center;
}
.target-thumb img { width: 100%; height: 100%; object-fit: cover; }
.target-thumb:hover { border-color: var(--text-secondary); }
.target-thumb.selected { border-color: var(--accent); border-width: 3px; }
.target-thumb.no-target { background: var(--bg-secondary); font-size: 0.75rem; color: var(--text-secondary); }
.target-thumb.no-target.selected { border-color: var(--accent); background: #e0e0e0; }

/* === Manage Toolbar === */
.manage-toolbar { margin-bottom: 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border-light); }
.manage-actions { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.75rem; }
.manage-settings { display: flex; gap: 1.5rem; align-items: center; flex-wrap: wrap; }


/* === Anchor Label Always Visible === */
.anchor-dot .anchor-label.always-show { opacity: 1; }

/* === Toast === */
#toast-container { position: fixed; top: 12px; left: 12px; z-index: 9999; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.toast { padding: 6px 14px; border-radius: var(--radius); font-size: 0.8rem; box-shadow: 0 2px 8px rgba(0,0,0,0.12); animation: toast-in .2s ease; pointer-events: auto; }
.toast-success { background: #166534; color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* === Toggle Switch === */
.toggle-label { display: inline-flex; align-items: center; gap: 0.5rem; cursor: pointer; font-size: 0.85rem; user-select: none; }
.toggle-label input { display: none; }
.toggle-switch { position: relative; width: 36px; height: 20px; background: var(--border); border-radius: 10px; transition: background .15s; flex-shrink: 0; }
.toggle-switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform .15s; }
.toggle-label input:checked + .toggle-switch { background: var(--accent); }
.toggle-label input:checked + .toggle-switch::after { transform: translateX(16px); }

/* === Responsive === */
@media (max-width: 768px) {
  .navbar { padding: 0 1rem; }
  .container { padding: 1rem; }
  .hero h1 { font-size: 1.8rem; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}
