:root {
  --bg-1: #0b0d12;
  --bg-2: #121827;
  --card: #f6f3ee;
  --ink: #151515;
  --muted: #a9b1c2;
  --accent: #f5b841;
  --accent-2: #5ec9a7;
  --danger: #f27d7d;
  --shadow: 0 18px 40px rgba(0,0,0,0.35);
}

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&display=swap');

* { box-sizing: border-box; }

body {
  font-family: "Space Grotesk", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 20% -10%, #243045 0, transparent 60%),
              radial-gradient(1200px 600px at 90% 0%, #1c2a3b 0, transparent 60%),
              linear-gradient(160deg, var(--bg-1), var(--bg-2));
  color:#e9ecf3;
  margin:0;
  min-height:100vh;
  overflow:auto;
  user-select: text;
  -webkit-user-select: text;
}

.layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 14px 14px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  min-height: 100vh;
}

.wrap {
  max-width: 900px;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: calc(100vh - 26px);
}

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

.brand {
  font-size: 16px;
  letter-spacing: 0.8px;
  font-weight: 600;
  color: #f3f4f8;
  text-transform: uppercase;
}

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

.import-label {
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06);
  color: #f4f6fb;
  font-size: 12px;
  min-width: 140px;
}

.desktop-only {
  display: inline-flex;
}

.mobile-only {
  display: none;
}

.mobile-actions {
  display: none;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
}

.mobile-actions.open {
  display: flex;
}

.file-btn input {
  display: none;
}

.btn {
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: #f1f4fa;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border 120ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.28);
}

.btn.primary {
  background: var(--accent);
  color: #101010;
  border-color: transparent;
}

.btn.reveal {
  background: var(--accent-2);
  color: #0d1512;
  border-color: transparent;
}

.btn.danger {
  background: rgba(242,125,125,0.18);
  border-color: rgba(242,125,125,0.4);
  color: #ffdada;
}

.magic {
  background: linear-gradient(135deg, #f5b841, #ffef9a);
  color: #1a1400;
  border: none;
}

.ai-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 10px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
}

.dots {
  display: inline-block;
  width: 22px;
  text-align: left;
}

.dots::after {
  content: ".";
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0% { content: "."; }
  25% { content: ".."; }
  50% { content: "..."; }
  75% { content: ""; }
  100% { content: "."; }
}

.ai-indicator.idle .dots::after {
  content: "";
  animation: none;
}

.ai-indicator:not(.idle) {
  animation: aiGlow 0.9s linear infinite;
}

.ai-indicator.error {
  animation: none;
  background: rgba(255, 92, 92, 0.2);
  border-color: rgba(255, 92, 92, 0.8);
  color: #ffe1e1;
}

@keyframes aiGlow {
  0% {
    background: rgba(46, 204, 113, 0.18);
    border-color: rgba(46, 204, 113, 0.55);
    color: #dfffe8;
  }
  50% {
    background: rgba(88, 255, 164, 0.25);
    border-color: rgba(88, 255, 164, 0.75);
    color: #f0fff6;
  }
  100% {
    background: rgba(26, 188, 156, 0.18);
    border-color: rgba(26, 188, 156, 0.55);
    color: #dfffe8;
  }
}

.card {
  background: var(--card);
  color: var(--ink);
  border-radius: 22px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  min-height: 140px;
  display: grid;
  gap: 14px;
  position: relative;
}

.card.editing {
  outline: 2px solid rgba(245,184,65,0.6);
}

.card h2 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 1.1px;
  color: #5b5b5b;
  text-transform: uppercase;
}

.card .face {
  font-size: 18px;
  line-height: 1.35;
  word-wrap: break-word;
}

.card .face[contenteditable="true"] {
  background: rgba(0,0,0,0.06);
  padding: 6px 8px;
  border-radius: 8px;
  outline: 1px dashed rgba(0,0,0,0.2);
}

.suggestion .face[contenteditable="true"] {
  background: rgba(0,0,0,0.08);
  padding: 6px 8px;
  border-radius: 8px;
  outline: 1px dashed rgba(255,255,255,0.2);
}

.card .back {
  padding-top: 10px;
  border-top: 1px dashed rgba(0,0,0,0.15);
  display: none;
}

.card.revealed .back {
  display: block;
}

.progress {
  padding:10px 12px;
  background: rgba(255,255,255,0.07);
  border-radius: 14px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.edit-bar {
  display: none;
  gap: 10px;
}

.edit-bar.show {
  display: flex;
}

.score {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.score .btn {
  justify-content: center;
  text-align: center;
}

.chat {
  flex: 1;
  min-height: 160px;
  overflow-y:auto;
  background: rgba(10,12,18,0.6);
  border-radius: 16px;
  padding:12px;
  border: 1px solid rgba(255,255,255,0.08);
  user-select: text;
  -webkit-user-select: text;
}

.chat.hidden {
  display: none;
}

.message {
  margin:8px 0;
  padding:10px 12px;
  border-radius:12px;
  font-size: 12px;
  line-height: 1.4;
  position: relative;
  user-select: text;
  -webkit-user-select: text;
}

.user {
  background: rgba(94,201,167,0.18);
  color: #d7fff1;
}

.ai {
  background: rgba(245,184,65,0.2);
  color: #fff6e0;
}

.msg-del {
  position: absolute;
  top: 6px;
  right: 8px;
  border: none;
  background: rgba(0,0,0,0.2);
  color: #fff;
  border-radius: 8px;
  padding: 2px 6px;
  cursor: pointer;
  font-size: 11px;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.input-row input {
  flex: 1;
  min-width: 220px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06);
  color: #f4f6fb;
  font-size: 12px;
}

.hint {
  font-size: 11px;
  color: var(--muted);
}

.panel {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.panel.collapsible .panel-body {
  display: none;
}

.panel.collapsible.open .panel-body {
  display: grid;
  gap: 8px;
}

.panel-toggle {
  background: none;
  border: none;
  color: #f0f4ff;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  padding: 0;
  font-size: 12px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.label {
  font-size: 11px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--muted);
}

.note-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.suggestion {
  display: none;
  background: rgba(0,0,0,0.15);
  border: 1px dashed rgba(255,255,255,0.2);
  border-radius: 10px;
  padding: 8px;
  gap: 8px;
}

.suggestion.visible {
  display: grid;
}

.panel.hidden {
  display: none;
}

.status {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.status strong {
  color: #f0f4ff;
  font-weight: 600;
}

.status.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 11px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(6,8,12,0.75);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal.open {
  display: flex;
}

.modal-card {
  width: min(720px, 92vw);
  max-height: 80vh;
  background: #0f1420;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px;
  display: grid;
  gap: 10px;
}

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

.modal-body {
  display: grid;
  gap: 8px;
  max-height: 60vh;
  overflow: hidden;
}

.modal-body .search-results {
  max-height: 55vh;
  overflow-y: auto;
}

.modal-body textarea {
  height: 140px;
  resize: vertical;
}

.modal-hint {
  font-size: 12px;
  color: var(--muted);
}

.create-card {
  display: grid;
  gap: 6px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
}

#createSuggestion {
  max-height: 40vh;
  overflow-y: auto;
  display: grid;
  gap: 8px;
  padding-right: 4px;
}

.label-list {
  display: grid;
  gap: 6px;
}

.label-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
}

.label-select,
.label-input {
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06);
  color: #f4f6fb;
  font-size: 12px;
}

.label-select {
  min-width: 160px;
}

.label-input {
  min-width: 180px;
}

.label-del {
  margin-left: auto;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.06);
  color: #f1f4fa;
  font-size: 11px;
  cursor: pointer;
}

.error {
  color: #ffb3b3;
  font-size: 12px;
}

@media (max-width: 820px) {
  .toolbar {
    gap: 8px;
  }
  .desktop-only {
    display: none;
  }
  .mobile-only {
    display: inline-flex;
  }
  .btn {
    padding: 10px 14px;
    font-size: 14px;
  }
  .card .face {
    font-size: 17px;
  }
  .chat {
    min-height: 120px;
  }
  .input-row {
    gap: 8px;
  }
  .input-row input {
    min-width: 160px;
  }
  .modal-card {
    width: 92vw;
    max-height: 85vh;
  }
}
