:root {
  --canvas-bg: #12141c;
  --canvas-dot: rgba(255, 255, 255, 0.07);
  --sidebar-bg: #f3f4f8;
  --sidebar-border: #e1e2ea;
  --pill-bg: #ffffff;
  --pill-border: #dcdde5;
  --pill-shadow: 0 2px 5px rgba(20, 20, 30, 0.12);
  --text-dark: #23242f;
  --text-muted: #7a7c8c;
  --topbar-bg: #191b24;
  --topbar-text: #eceef5;
  --accent: #ffcf5c;
  --accent-glow: rgba(255, 207, 92, 0.55);
  --danger: #ff6b6b;
  --radius-pill: 9px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font);
  color: var(--text-dark);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---------- Topbar ---------- */

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--topbar-bg);
  color: var(--topbar-text);
  flex: 0 0 auto;
  z-index: 20;
}

.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-emoji { font-size: 20px; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: 0.2px; }
.brand-sub { font-size: 12px; color: #9295a8; }

.topbar-actions { display: flex; gap: 8px; }

.topbar-actions button {
  background: #262838;
  color: var(--topbar-text);
  border: 1px solid #34364a;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.topbar-actions button:hover { background: #313346; }
.topbar-actions button:active { transform: translateY(1px); }
#reset-btn:hover { background: #4a2430; border-color: #6b2e3d; }

/* ---------- Main layout ---------- */

#main {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

/* ---------- Canvas (crafting workspace) ---------- */

#canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

#canvas {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background-color: var(--canvas-bg);
  background-image: radial-gradient(var(--canvas-dot) 1.4px, transparent 1.4px);
  background-size: 22px 22px;
  touch-action: none;
}

#canvas-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  color: #6c6f82;
  font-size: 12.5px;
  pointer-events: none;
  margin: 0;
  user-select: none;
  text-align: center;
  width: 90%;
}

/* An element sitting on the canvas */
.instance {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  border-radius: var(--radius-pill);
  box-shadow: var(--pill-shadow);
  font-size: 15px;
  white-space: nowrap;
  cursor: grab;
  user-select: none;
  touch-action: none;
  z-index: 1;
  transition: box-shadow 0.15s ease;
}
.instance.dragging {
  cursor: grabbing;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
  z-index: 50;
}
.instance.pending {
  opacity: 0.55;
  pointer-events: none;
  animation: pulse 0.9s ease-in-out infinite;
}
.instance.merge-target {
  box-shadow: 0 0 0 3px var(--accent-glow), var(--pill-shadow);
}
.instance.spawn-pop { animation: pop-in 0.22s ease-out; }
.instance.first-discovery {
  animation: pop-in 0.22s ease-out, glow-ring 1.4s ease-out;
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.85; }
}
@keyframes pop-in {
  0% { transform: translate(-50%, -50%) scale(0.4); opacity: 0; }
  70% { transform: translate(-50%, -50%) scale(1.08); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
@keyframes glow-ring {
  0% { box-shadow: 0 0 0 0 var(--accent-glow), var(--pill-shadow); }
  60% { box-shadow: 0 0 0 14px rgba(255, 207, 92, 0); box-shadow: 0 0 0 14px transparent, var(--pill-shadow); }
  100% { box-shadow: var(--pill-shadow); }
}

/* Ghost element that follows the pointer while dragging in from the sidebar */
.drag-ghost {
  position: fixed;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  border-radius: var(--radius-pill);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
  font-size: 15px;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  z-index: 100;
  opacity: 0.95;
}

.emoji { font-size: 16px; line-height: 1; }

/* ---------- Sidebar ---------- */

#sidebar {
  flex: 0 0 var(--sidebar-w, 300px);
  background: var(--sidebar-bg);
  border-left: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#sidebar-search-wrap {
  padding: 12px;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

#sidebar-search {
  flex: 1 1 auto;
  padding: 8px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--pill-border);
  background: #fff;
  font-size: 13.5px;
  outline: none;
}
#sidebar-search:focus { border-color: #b9bcd4; }

#sidebar-count {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

#sidebar-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  border-radius: var(--radius-pill);
  box-shadow: var(--pill-shadow);
  font-size: 14px;
  cursor: grab;
  user-select: none;
  touch-action: none;
  height: fit-content;
}
.sidebar-item:active { cursor: grabbing; }
.sidebar-item.newly-added { animation: pop-in 0.25s ease-out; }

.sidebar-empty {
  color: var(--text-muted);
  font-size: 13px;
  padding: 8px 4px;
}

/* ---------- Toasts ---------- */

#toast-stack {
  position: fixed;
  top: 60px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}

.toast {
  background: #1c1e29;
  color: #f2f3f8;
  border: 1px solid #33354a;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
  animation: toast-in 0.2s ease-out, toast-out 0.3s ease-in 2.7s forwards;
  max-width: 280px;
}
.toast.discovery { border-color: var(--accent); }
.toast.error { border-color: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(-6px); }
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  #main { flex-direction: column; }
  #sidebar { flex: 0 0 40%; max-width: none; border-left: none; border-top: 1px solid var(--sidebar-border); }
  #dict-panel.open { flex: 0 0 45%; border-right: none; border-bottom: 1px solid var(--sidebar-border); }
  .resizer { display: none; }
  .brand-sub { display: none; }
}
.persian-name {
    font-size: 0.85em;
    color: #888;
    margin-left: 5px;
    direction: rtl; /* Important for correct Persian rendering */
}
/*after dic update*/

.dict-btn { flex: 0 0 auto; width: 22px; height: 22px; margin-left: 2px; padding: 0; border: none;
  border-radius: 50%; background: transparent; font-size: 12px; line-height: 1; cursor: pointer; }
.dict-btn:hover { background: #dfe2f0; }

#dict-panel {
  flex: 0 0 var(--dict-w, 380px); /* a real column: the canvas is pushed over, never covered */
  display: none;
  flex-direction: column;
  min-width: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
}
#dict-panel.open { display: flex; }

.dict-header { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--sidebar-border); }
.dict-title { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 700; }
.dict-title .emoji { font-size: 22px; }
.dict-close { border: none; background: transparent; font-size: 16px; color: var(--text-muted);
  cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.dict-close:hover { background: #e4e6ef; color: var(--text-dark); }
.dict-body { flex: 1 1 auto; overflow-y: auto; padding: 14px 16px 20px; }

.dict-section h3 { margin: 16px 0 8px; font-size: 12px; letter-spacing: .6px;
  text-transform: uppercase; color: var(--text-muted); }
.dict-status { color: var(--text-muted); font-size: 13.5px; margin: 8px 0; }
.dict-error { color: #c0392b; }
.dict-entry { margin-bottom: 14px; }
.dict-headword { font-size: 17px; font-weight: 600; }
.dict-pos { font-size: 12px; font-style: italic; font-weight: 400; color: var(--text-muted); margin-left: 6px; }
.dict-senses { margin: 6px 0 0; padding: 0 22px; }
.dict-senses > li { margin-bottom: 8px; font-size: 14.5px; line-height: 1.55; }
.dict-def { margin: 0; }
.dict-examples { margin: 4px 0 0; padding: 0 18px; font-size: 13px; color: var(--text-muted); }


/*dictionary png in the sidebar*/
.dict-btn {
  display: flex;
  align-items: center;
  justify-content: center;
}
.dict-btn img {
  width: 20px;
  height: 20px;
  display: block;
  pointer-events: none; /* the click goes to the button, not the image */
}

/* ---------- Dictionary: pronunciation row and English/Persian toggle ---------- */

.dict-pron {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--sidebar-border);
}
.dict-pron-label {
  margin-right: auto; font-size: 12px; letter-spacing: 0.6px;
  text-transform: uppercase; color: var(--text-muted);
}
.dict-audio-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border: 1px solid var(--pill-border); border-radius: var(--radius-pill);
  background: #fff; color: var(--text-dark); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: background 0.15s ease, box-shadow 0.15s ease;
}
.dict-audio-btn:hover:not(:disabled) { background: #eef0fa; }
.dict-audio-btn.playing { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.dict-audio-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.dict-tabs {
  flex: 0 0 auto; display: flex; gap: 4px; margin: 10px 14px 0;
  padding: 3px; background: #e4e6ef; border-radius: 10px;
}
.dict-tab {
  flex: 1 1 0; padding: 7px 10px; border: none; border-radius: 8px;
  background: transparent; color: var(--text-muted); font-size: 13.5px;
  font-weight: 600; cursor: pointer;
}
.dict-tab:hover { color: var(--text-dark); }
.dict-tab.active { background: #fff; color: var(--text-dark); box-shadow: 0 1px 3px rgba(20, 20, 30, 0.15); }
.dict-tab.empty:not(.active) { opacity: 0.6; }

/* ---------- Drag handles between the panels ---------- */

.resizer {
  flex: 0 0 6px;
  margin: 0 -3px; /* sits on the border without taking any room */
  position: relative;
  z-index: 60;
  cursor: col-resize;
  touch-action: none;
}
.resizer::after {
  content: "";
  position: absolute;
  inset: 0 2px;
  background: transparent;
  transition: background 0.15s ease;
}
.resizer:hover::after,
#main.resizing .resizer::after { background: var(--accent); opacity: 0.55; }
#main.resizing { cursor: col-resize; user-select: none; }