:root {
  --bg: #08090c;
  --panel: #101217;
  --panel-2: #0d0f14;
  --panel-hover: #151820;
  --border: #282d38;
  --border-soft: #20242e;
  --text: #f5f5f7;
  --muted: #9da3b2;
  --muted-2: #737a89;
  --accent: #7c6cff;
  --accent-soft: rgba(124,108,255,.13);
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  zoom: .9;
  margin: 0;
  background: radial-gradient(circle at 50% -20%, rgba(124,108,255,.10), transparent 34%), var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { color: inherit; }

.shell { width: min(1240px, calc(100% - 32px)); margin: 0 auto; padding: 18px 0 20px; }

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px 20px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(16,18,23,.88);
}
.eyebrow { margin: 0 0 4px; color: #b7bdca; font-size: 13px; font-weight: 500; }
h1 { margin: 0; font-size: clamp(28px, 3.1vw, 38px); line-height: 1.05; letter-spacing: -.035em; font-weight: 750; }
.subtitle { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

.workspace-add {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 12px;
  border: 1px solid #303542;
  border-radius: 9px;
  background: #151820;
  color: #aeb4c1;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.workspace-add:hover { color: #d0ccff; border-color: #5149a8; background: rgba(124,108,255,.08); }

.section-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.section-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: rgba(16,18,23,.86);
}
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 9px; }
.section-title-wrap { min-width: 0; }
.section-title { margin: 0; font-size: 18px; line-height: 1.1; letter-spacing: -.02em; }
.section-description { margin: 4px 0 0; color: var(--muted); font-size: 11px; }

/* Management is intentionally quiet; it should never compete with the primary click target. */
.edit-section { opacity: .52; }
.edit-section:hover { opacity: 1; color: #c0bbff; background: rgba(124,108,255,.07); }

.link-list { display: grid; gap: 6px; }
.link-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  padding: 7px 9px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: var(--panel-2);
  text-decoration: none;
  transition: background .15s ease, border-color .15s ease;
  cursor: pointer;
}
.link-row:hover { background: var(--panel-hover); border-color: #353b49; }
.link-icon, .manage-icon {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: #a79fff; font-size: 17px;
  overflow: hidden;
}
.link-icon img, .manage-icon img { width: 100%; height: 100%; object-fit: contain; padding: 5px; }
.link-copy { min-width: 0; }
.link-name { display: block; color: var(--text); font-size: 13px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-note { display: block; margin-top: 2px; color: var(--muted-2); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-arrow { color: #7f8695; font-size: 15px; }
.empty { padding: 8px 4px 7px; color: #686f7e; font-size: 11px; }

footer { padding: 12px 4px 0; color: #666d7b; font-size: 11px; }

.icon-btn, .tiny-btn {
  display: grid; place-items: center;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  color: var(--muted-2);
}
.icon-btn { width: 28px; height: 28px; border-radius: 8px; font-size: 16px; }
.tiny-btn { width: 28px; height: 28px; border-radius: 7px; font-size: 13px; }
.icon-btn:hover, .tiny-btn:hover { color: var(--text); background: #191c24; border-color: #303542; }
.tiny-btn.delete:hover { color: var(--danger); }
.close-btn { font-size: 19px; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  padding: 32px;
  background: rgba(0,0,0,.68);
  backdrop-filter: blur(5px);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(520px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 17px;
  background: #111318;
  box-shadow: 0 24px 80px rgba(0,0,0,.45);
}
.modal-wide { width: min(650px, 100%); }
.confirm-layer { z-index: 70; }
.confirm-modal { width: min(460px, 100%); }
.confirm-message { margin: 0; color: #b6bbc7; font-size: 13px; line-height: 1.6; }
.danger-btn { height: 38px; padding: 0 14px; border: 1px solid #a94545; border-radius: 9px; background: #8e3c3c; color: #fff; cursor: pointer; font-size: 12px; font-weight: 650; }
.danger-btn:hover { background: #a64545; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.modal-kicker { margin: 0 0 3px; color: #8178ff; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.modal h2 { margin: 0; font-size: 20px; }
.modal-subtitle { margin: 4px 0 0; color: var(--muted-2); font-size: 11px; }
form { display: grid; gap: 12px; }
label { display: grid; gap: 6px; color: #b5bac6; font-size: 12px; }
input {
  width: 100%; height: 40px; padding: 0 11px;
  border: 1px solid #303542; border-radius: 9px;
  outline: none; background: #0c0e12; color: var(--text);
}
input:focus { border-color: #655be5; box-shadow: 0 0 0 3px rgba(124,108,255,.10); }
.optional { color: #686f7d; }

.manage-toolbar { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.manage-list { display: grid; gap: 6px; }
.manage-row {
  display: grid;
  grid-template-columns: 34px minmax(0,1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 8px 9px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: #0d0f14;
}
.manage-copy { min-width: 0; }
.manage-copy strong { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.manage-copy small { display: block; margin-top: 2px; color: var(--muted-2); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.manage-actions { display: flex; gap: 2px; }
.manage-empty { padding: 22px 10px; border: 1px dashed #303542; border-radius: 10px; color: #737a89; font-size: 12px; text-align: center; }
.manage-footer { display: flex; justify-content: flex-end; margin-top: 12px; padding-top: 10px; border-top: 1px solid #20242e; }
.danger-ghost { height: 32px; padding: 0 10px; border: 1px solid transparent; border-radius: 8px; background: transparent; color: #777e8c; cursor: pointer; font-size: 11px; }
.danger-ghost:hover { color: var(--danger); border-color: rgba(255,107,107,.22); background: rgba(255,107,107,.05); }

.emoji-picker-wrap { display: grid; gap: 7px; }
.emoji-suggestions {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
  padding: 7px;
  border: 1px solid #252a35;
  border-radius: 10px;
  background: #0c0e12;
  max-height: 108px;
  overflow: auto;
}
.emoji-choice {
  min-width: 0;
  aspect-ratio: 1;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
  font-size: 17px;
}
.emoji-choice:hover, .emoji-choice.active { background: var(--accent-soft); border-color: #4a43a0; }

.icon-upload-preview {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  color: var(--muted-2);
  font-size: 11px;
}
.icon-upload-preview img { width: 32px; height: 32px; object-fit: contain; border-radius: 7px; background: var(--accent-soft); }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.primary-btn, .secondary-btn {
  height: 38px; padding: 0 14px; border-radius: 9px; cursor: pointer; font-size: 12px; font-weight: 650;
}
.primary-btn { border: 1px solid #756bff; background: #6e63ee; color: white; }
.primary-btn:hover { background: #786ef5; }
.secondary-btn { border: 1px solid #303542; background: #181b22; color: #b4bac7; }
.secondary-btn:hover { color: var(--text); border-color: #414755; }

@media (max-width: 760px) {
  body { zoom: 1; }
  .shell { width: min(100% - 20px, 1240px); padding-top: 12px; }
  .hero { padding: 17px 18px 18px; border-radius: 15px; align-items: flex-start; }
  .workspace-add { margin-top: 2px; }
  .section-grid { grid-template-columns: 1fr; }
  .emoji-suggestions { grid-template-columns: repeat(10, 1fr); }
}

@media (max-width: 520px) {
  .hero { display: block; }
  .workspace-add { margin-top: 12px; }
  .manage-toolbar { flex-direction: column; }
}

/* V5 — soft workspace/link color system + time widget */
.hero-copy { min-width: 0; }
.hero-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex: 0 0 auto; }
.time-widget { text-align: right; display: grid; gap: 1px; }
.time-widget strong { font-size: 15px; line-height: 1.1; font-weight: 650; color: #d9dce5; font-variant-numeric: tabular-nums; }
.time-widget span { color: #777f90; font-size: 10px; white-space: nowrap; }

.section-card { border-color: color-mix(in srgb, var(--section-color) 24%, var(--border)); }
.section-card::before { content: ''; display: block; width: 34px; height: 2px; border-radius: 999px; background: var(--section-color); opacity: .58; margin-bottom: 8px; }
.section-title { color: color-mix(in srgb, var(--section-color) 74%, #f5f5f7); }
.section-description { color: color-mix(in srgb, var(--section-color) 36%, var(--muted)); }
.edit-section { color: color-mix(in srgb, var(--section-color) 50%, #737a89); }
.edit-section:hover { color: var(--section-color); background: color-mix(in srgb, var(--section-color) 9%, transparent); }

.link-row { border-color: color-mix(in srgb, var(--link-color) 13%, var(--border-soft)); }
.link-row:hover { border-color: color-mix(in srgb, var(--link-color) 28%, #353b49); background: color-mix(in srgb, var(--link-color) 4%, var(--panel-hover)); }
.link-icon { background: color-mix(in srgb, var(--link-color) 13%, transparent); color: var(--link-color); }
.link-name { color: color-mix(in srgb, var(--link-color) 72%, #f5f5f7); }
.link-note { color: color-mix(in srgb, var(--link-color) 36%, var(--muted-2)); }
.link-arrow { color: color-mix(in srgb, var(--link-color) 55%, #7f8695); }
.manage-row { border-color: color-mix(in srgb, var(--link-color) 13%, var(--border-soft)); }
.manage-icon { background: color-mix(in srgb, var(--link-color) 13%, transparent); color: var(--link-color); }
.manage-copy strong { color: color-mix(in srgb, var(--link-color) 70%, #f5f5f7); }

.color-field { display: grid; gap: 7px; }
.field-label { color: #b5bac6; font-size: 12px; }
.color-suggestions { display: flex; flex-wrap: wrap; gap: 7px; padding: 8px; border: 1px solid #252a35; border-radius: 10px; background: #0c0e12; }
.color-choice { width: 29px; height: 29px; padding: 3px; border: 1px solid transparent; border-radius: 8px; background: transparent; cursor: pointer; }
.color-choice span { display: block; width: 100%; height: 100%; border-radius: 6px; background: var(--swatch); opacity: .82; box-shadow: inset 0 0 0 1px rgba(255,255,255,.16); }
.color-choice:hover { background: #171a22; }
.color-choice.active { border-color: color-mix(in srgb, var(--swatch) 75%, white); background: color-mix(in srgb, var(--swatch) 10%, transparent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--swatch) 15%, transparent); }

@media (max-width: 760px) {
  .hero-side { align-items: flex-start; }
  .time-widget { text-align: left; }
}

/* V6 — clearer visual hierarchy: workspace vs. links */
.section-title {
  color: #f5f5f7;
  font-weight: 750;
}
.section-description {
  color: color-mix(in srgb, var(--section-color) 42%, var(--muted));
}
.link-name {
  color: color-mix(in srgb, var(--link-color) 88%, #f5f5f7);
  font-weight: 650;
}
.link-note {
  color: color-mix(in srgb, var(--link-color) 42%, var(--muted-2));
}
.link-arrow {
  color: color-mix(in srgb, var(--link-color) 70%, #7f8695);
}
.link-row {
  box-shadow: inset 2px 0 0 color-mix(in srgb, var(--link-color) 48%, transparent);
}
.link-row:hover {
  box-shadow: inset 2px 0 0 color-mix(in srgb, var(--link-color) 70%, transparent);
}
.section-card::before { opacity: .72; height: 3px; }
.time-widget strong { color: color-mix(in srgb, var(--accent) 38%, #d9dce5); }


/* V7 — drag & drop link priority */
.manage-list { position: relative; }
.manage-row {
  grid-template-columns: 24px 22px 34px minmax(0,1fr) auto;
  user-select: none;
  transition: transform .12s ease, border-color .12s ease, background .12s ease, opacity .12s ease;
}
.drag-handle {
  width: 24px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: #5f6675;
  cursor: grab;
  font-size: 16px;
  letter-spacing: -4px;
  padding: 0 5px;
}
.drag-handle:hover { color: #9da4b3; }
.drag-handle:active { cursor: grabbing; }
.manage-row.dragging { opacity: .42; }
.manage-row.drag-over {
  border-color: color-mix(in srgb, var(--link-color) 48%, #303542);
  background: color-mix(in srgb, var(--link-color) 7%, #0d0f14);
  transform: translateY(-1px);
}
.manage-index {
  color: #555c6b;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.portal-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  transform: translate(-50%, 12px);
  padding: 9px 13px;
  border: 1px solid #303542;
  border-radius: 9px;
  background: #171a21;
  color: #cbd0da;
  box-shadow: 0 12px 35px rgba(0,0,0,.35);
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
}
.portal-toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 520px) {
  .manage-row { grid-template-columns: 22px 18px 32px minmax(0,1fr) auto; gap: 7px; }
  .manage-actions { gap: 0; }
}

/* V8 — dedicated priority manager */
.manage-toolbar-left { display: flex; gap: 8px; flex-wrap: wrap; }
.manage-row {
  grid-template-columns: 34px minmax(0,1fr) auto;
  user-select: auto;
  cursor: default;
}
.manage-row:hover { border-color: color-mix(in srgb, var(--link-color) 22%, var(--border-soft)); }

.priority-modal { width: min(650px, 100%); }
.priority-list { display: grid; gap: 6px; }
.priority-row {
  display: grid;
  grid-template-columns: 30px 26px 38px minmax(0,1fr);
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--link-color) 15%, var(--border-soft));
  border-radius: 10px;
  background: #0d0f14;
  transition: opacity .12s ease, border-color .12s ease, background .12s ease;
}
.priority-row.dragging { opacity: .32; }
.priority-handle {
  width: 30px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #687080;
  cursor: grab;
  font-size: 16px;
  letter-spacing: -4px;
  padding: 0 6px;
}
.priority-handle:hover { color: #aeb5c3; background: #181b23; }
.priority-handle:active { cursor: grabbing; }
.priority-index {
  color: #626a79;
  font-size: 11px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.priority-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: color-mix(in srgb, var(--link-color) 13%, transparent);
  color: var(--link-color);
  font-size: 18px;
}
.priority-icon img { width: 100%; height: 100%; object-fit: contain; padding: 5px; }
.priority-copy { min-width: 0; }
.priority-copy strong { display: block; color: color-mix(in srgb, var(--link-color) 84%, #f5f5f7); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.priority-copy small { display: block; margin-top: 2px; color: var(--muted-2); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.priority-gap {
  min-height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed color-mix(in srgb, var(--accent) 65%, #303542);
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  color: color-mix(in srgb, var(--accent) 78%, #b7bdca);
  font-size: 10px;
  letter-spacing: .02em;
}
.priority-gap span { padding: 2px 8px; }
.priority-hint { margin-top: 9px; color: #747c8b; font-size: 10px; line-height: 1.5; }
.priority-hint strong { color: #a0a7b5; }


@media (max-width: 520px) {
  .manage-toolbar-left { width: 100%; }
  .manage-toolbar-left .secondary-btn { flex: 1; }
  .priority-row { grid-template-columns: 28px 20px 34px minmax(0,1fr); gap: 7px; }
}


/* V10 — integrated link organization inside Manage workspace */
.manage-list { position: relative; }
.manage-row {
  grid-template-columns: 24px 22px 34px minmax(0,1fr) auto;
  user-select: none;
  transition: transform .12s ease, border-color .12s ease, background .12s ease, opacity .12s ease;
}
.manage-row.dragging { opacity: .42; }
.drag-handle {
  width: 24px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #5f6675;
  cursor: grab;
  font-size: 15px;
  letter-spacing: -4px;
  padding: 0 5px;
}
.drag-handle:hover { color: #aeb5c3; background: #181b23; }
.drag-handle:active { cursor: grabbing; }
.manage-index {
  color: #555c6b;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.manage-row .manage-actions { position: relative; z-index: 2; }
.manage-list .priority-gap {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed color-mix(in srgb, var(--accent) 65%, #303542);
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  color: color-mix(in srgb, var(--accent) 78%, #b7bdca);
  font-size: 10px;
  letter-spacing: .02em;
}
.manage-list .priority-gap span { padding: 2px 8px; }
@media (max-width: 520px) {
  .manage-row { grid-template-columns: 22px 18px 32px minmax(0,1fr) auto; gap: 7px; }
  .manage-actions { gap: 0; }
}

/* V11 — access-code login */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #08090c;
}
.login-screen[hidden] { display: none; }
#appShell[hidden] { display: none; }
.login-card {
  width: min(420px, 100%);
  padding: 34px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #101217;
  box-shadow: 0 24px 80px rgba(0,0,0,.42);
}
.login-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border-radius: 13px;
  background: rgba(124,108,255,.13);
  color: #b7b0ff;
  font-size: 22px;
}
.login-kicker { margin: 0 0 6px; color: #8178ff; font-size: 11px; letter-spacing: .12em; font-weight: 700; }
.login-card h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.login-subtitle { margin: 7px 0 22px; color: var(--muted); font-size: 13px; }
.login-form { display: grid; gap: 8px; }
.login-form label { display: block; color: #b8bdc9; font-size: 12px; }
.access-wrap { position: relative; }
.access-wrap input { padding-right: 58px; }
.access-toggle {
  position: absolute; right: 7px; top: 7px;
  height: 26px; padding: 0 7px; border: 0; border-radius: 6px;
  background: transparent; color: #7f8796; cursor: pointer; font-size: 11px;
}
.access-toggle:hover { color: #dce0e8; background: #181b22; }
.login-error { margin: 1px 0 0; color: #df9b9b; font-size: 11px; line-height: 1.5; }
.login-submit { width: 100%; margin-top: 6px; }
.login-submit:disabled { opacity: .65; cursor: wait; }
footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.logout-btn {
  border: 0; background: transparent; color: #656d7c; cursor: pointer; font-size: 11px;
}
.logout-btn:hover { color: #aeb4c0; }

/* V11.1 — stable drag-and-drop insertion space */
.manage-list { padding-bottom: 8px; }
.manage-row.dragging { opacity: .42; }
.priority-gap {
  min-height: 42px;
  border: 1px dashed #3b4050;
  border-radius: 10px;
  background: rgba(124,108,255,.035);
  pointer-events: none;
  box-sizing: border-box;
}

/* V12 — stable insertion space: no animation, no layout flicker */
.manage-list .priority-gap {
  min-height: 42px;
  margin: 2px 0;
  border: 1px dashed #3b4050;
  border-radius: 10px;
  background: rgba(255,255,255,.018);
  pointer-events: none;
  animation: none !important;
}
