:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --ink: #1c1917;
  --muted: #78716c;
  --accent: #0f766e;
  --accent-hover: #0d9488;
  --danger: #b91c1c;
  --border: #e7e5e4;
  --shadow: 0 8px 24px rgba(28, 25, 23, 0.08);
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, #ccfbf1 0%, transparent 40%),
    radial-gradient(circle at top right, #fde68a 0%, transparent 35%),
    var(--bg);
  min-height: 100vh;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

.header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}
.brand h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: -0.02em;
}
.tagline { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.95rem; }

.auth-area { display: flex; align-items: center; gap: 0.75rem; }
.user-info { display: flex; align-items: center; gap: 0.6rem; }
.avatar { border-radius: 50%; object-fit: cover; background: var(--border); }
.hidden { display: none !important; }

.gate { display: flex; justify-content: center; padding: 2rem 0; }
.gate-card { max-width: 420px; text-align: center; }
.gate-card h2 { margin-top: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  background: rgba(255,255,255,0.55);
  padding: 0.35rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  width: fit-content;
}
.tab {
  border: none;
  background: transparent;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}
.tab.active {
  background: var(--accent);
  color: white;
}

.panel { animation: fade 0.2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

label { display: block; font-weight: 600; margin-bottom: 0.4rem; }
textarea, input[type="file"] {
  width: 100%;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  background: white;
}
textarea:focus { outline: 2px solid #99f6e4; border-color: var(--accent); }

.row { display: flex; gap: 0.5rem; margin-top: 0.75rem; flex-wrap: wrap; }
.btn {
  border: none;
  border-radius: 10px;
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-danger { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.hint { color: var(--muted); font-size: 0.85rem; margin: 0.5rem 0 0; }
.status { min-height: 1.25rem; margin: 0.75rem 0; color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); }
.success { color: var(--accent); }

.notes-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}
.note-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.note-text {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0 0 0.75rem;
  line-height: 1.45;
}
.note-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.8rem;
}
.note-actions { display: flex; gap: 0.4rem; }

.images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.85rem;
}
.images-more {
  display: flex;
  justify-content: center;
  margin-top: 1rem;
}
.image-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  aspect-ratio: 1;
}
.image-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.image-card .overlay {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem;
  background: linear-gradient(transparent, rgba(0,0,0,0.65));
}
.image-card .overlay .btn { padding: 0.3rem 0.55rem; font-size: 0.75rem; }

.footer {
  margin-top: 2.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.gsi-wrap { display: flex; justify-content: center; min-height: 40px; }

@media (max-width: 600px) {
  .brand h1 { font-size: 1.3rem; }
  .tabs { width: 100%; }
  .tab { flex: 1; }
}

.gate-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.1rem 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.gate-divider::before,
.gate-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.password-form {
  text-align: left;
  display: grid;
  gap: 0.55rem;
}
.password-form input[type="password"] {
  width: 100%;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  background: white;
}
.password-form input[type="password"]:focus {
  outline: 2px solid #99f6e4;
  border-color: var(--accent);
}
.password-form .btn { width: 100%; margin-top: 0.25rem; }
#panel-pinboard:focus { outline: none; }

/* ---------- Search Bar ---------- */
.search-wrap {
  margin: 1rem 0 0.5rem;
}
.search-input {
  width: 100%;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 1rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.search-input:focus {
  outline: 2px solid #99f6e4;
  border-color: var(--accent);
}

/* ---------- Cheat sheets ---------- */
.cheats-toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0.15rem 0 0.75rem;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.cheats-toolbar .search-wrap { margin-top: 0; }
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.65rem;
}
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.chip.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.cheat-section { margin: 1.1rem 0 1.4rem; }
.cheat-section h3 {
  margin: 0 0 0.55rem;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.cheat-row {
  display: grid;
  grid-template-columns: minmax(9rem, 1.1fr) minmax(8rem, 2fr) auto;
  gap: 0.75rem;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.45rem;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.cheat-row:hover { border-color: #99f6e4; }
.cheat-row:focus {
  outline: 2px solid #99f6e4;
}
.cheat-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
}
.cheat-keys kbd {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  display: inline-block;
  min-width: 1.55rem;
  max-width: 100%;
  padding: 0.18rem 0.45rem;
  border: 1px solid #d6d3d1;
  border-bottom-width: 3px;
  border-radius: 6px;
  background: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
}
.cheat-action { line-height: 1.35; }
.cheat-tools { display: flex; flex-wrap: wrap; gap: 0.3rem; justify-content: flex-end; }
.cheat-copy { font-size: 1rem; padding: 0.3rem 0.55rem; }
.cheat-form { margin-top: 1.5rem; }
.cheat-form h3 { margin: 0 0 0.85rem; font-size: 1rem; }
.cheat-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}
.cheat-form-grid label { margin: 0; }
.cheat-form-grid input,
.cheat-form-grid select {
  width: 100%;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  background: white;
  margin-top: 0.3rem;
}
.cheat-action-field { grid-column: 1 / -1; }
@media (max-width: 640px) {
  .cheat-row {
    grid-template-columns: 1fr;
  }
  .cheat-tools { justify-content: flex-start; }
  .cheat-form-grid { grid-template-columns: 1fr; }
}

/* ---------- Drag & Drop ---------- */
.upload-card {
  transition: border-color 0.2s, background-color 0.2s, transform 0.2s;
}
.upload-card.drag-over {
  border: 2px dashed var(--accent);
  background-color: #f0fdfa;
  transform: scale(1.01);
}

/* ---------- Image Card cursor & Lightbox ---------- */
.image-card {
  cursor: pointer;
}
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: fade 0.15s ease;
}
.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(4px);
}
.lightbox-dialog {
  position: relative;
  z-index: 1001;
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 90vw;
  max-height: 90vh;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.lightbox-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 1002;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border: none;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.lightbox-close:hover {
  background: rgba(0, 0, 0, 0.8);
}
.lightbox-body {
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f172a;
}
.lightbox-body img {
  max-width: 85vw;
  max-height: 75vh;
  object-fit: contain;
  display: block;
}
.lightbox-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.lightbox-title {
  font-size: 0.85rem;
  color: var(--muted);
  word-break: break-all;
}
